先说问题,关于gsql中的事务:测试gsql中的默认事务自动提交功能的任务,我发现无法修改关闭自动提交功能,无论是尝试修改,或对出会话再登录修改,参数值仍然为on
omm=# \set AUTOCOMMIT off
omm=# \set AUTOCOMMIT off
omm=# show AUTOCOMMIT;
autocommit
------------
on
(1 row)
omm=# \set AUTOCOMMIT off;
unrecognized Boolean value; assuming "on"
omm=# show autocommit;
autocommit
------------
on
(1 row)
不知道有没有人和我遇到一样的情况,还是说这个不是内存生效参数,需要重启实例生效?或者只是该环境的bug?
两种数据库登录方式,一种为本地认证,一种是针对数据库及端口的sql连接登录
omm@modb:~$ gsql -r
omm@modb:~$ gsql -d omm -p 5432 -r
然后测试不加-r参数也可以正常登录,查询资料确认为命令补全功能,建议使用。
—根据openGauss语法规则,gsql支持使用Tab键进行命令的自动补齐,当编译时指定了选项–with-readline,且客户端连接时指定“-r”参数,此功能被打开。
版本查询:
##select version();
(openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr on aarch64-unknown-linux-gnu,
compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)
##show server_version;
server_version
----------------
9.2.4
感觉还是show命令更直观好用,select version输出更像是内核信息。
\copyright命令为版权查询信息:
omm=# GaussDB Kernel Database Management System
Copyright (c) Huawei Technologies Co., Ltd. 2018. All rights reserved.
能看到当前库软件是哪家公司授权的,维保联系不至于联系错供应商…
–\l命令,元命令\l的作用是显示openGauss数据库集簇中,目前有哪些数据库。
\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+---------+-------+-------------------
omm | omm | UTF8 | C | C |
postgres | omm | UTF8 | C | C |
template0 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | UTF8 | C | C | =c/omm +
| | | | | omm=CTc/omm
(4 rows)
--\conninfo命令,元命令\conninfo的作用是在gsql中,显示会话的连接信息。
\conninfo
You are connected to database "omm" as user "omm" via socket in "/tmp" at port "5432".
当前用户信息;
--\c[onnect] [DBNAME]命令,元命令\ c[onnect] [DBNAME]的作用是在gsql中,切换连接的数据库postgres。
\c postgres
omm=# \c postgres
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "postgres" as user "omm".
切换数据库,显示有SSL连接推荐安全模式,并提示连接对象名称及当前连接用户;
–\du命令和\dg命令,元命令\dg命令与元命令\du命令的作用类似,都是显示openGauss数据库集簇中,目前有哪些用户和角色。
omm=# \du
List of roles
Role name | Attributes
| Member of
-----------+-------------------------------------------------------------------------------------------------------
-----------+-----------
gaussdb | Sysadmin
| {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyad
min, UseFT | {}
omm=# \dg
List of roles
Role name | Attributes
| Member of
-----------+-------------------------------------------------------------------------------------------------------
-----------+-----------
gaussdb | Sysadmin
| {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyad
min, UseFT | {}
从输出上看,结果确实一模一样,是当前用户下能查看到的所有角色和权限;
–\db命令,元命令\db的作用是显示openGauss数据库集簇中,目前有哪些表空间。
\db
omm=# List of tablespaces
Name | Owner | Location
------------+-------+----------
pg_default | omm |
pg_global | omm |
查看表空间对象,但是location位置列信息未显示,新建指定文件系统路径的不知道是不是能显示?
–\dn命令,元命令\dn的作用是显示当前数据库有哪些数据库模式。
\dn
omm=# \dn
List of schemas
Name | Owner
-----------------+-------
blockchain | omm
cstore | omm
db4ai | omm
dbe_perf | omm
dbe_pldebugger | omm
sqladvisor | omm
dbe_pldeveloper | omm
pkg_service | omm
public | omm
snapshot | ommomm=# (10 rows)
这个解释查看的是模式,但看输出应该是该用户西安的schemas对象的信息;应该是单纯的文字翻译。
#############################################
--创建表
CREATE TABLE customer_t
( c_customer_sk integer,
c_customer_id char(5),
c_first_name char(6),
c_last_name char(8)
) ;
–插入数据
INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES (3769, 5, 'Grace','White');
###############################################
omm=# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES
omm-# (6885, 1, 'Joes', 'Hunter'),
omm-# (4321, 2, 'Lily','Carter'),
omm-# omm-# (9527, 3, 'James', 'Cook'),
(9500, 4, 'Lucy', 'Baker');
INSERT 0 4
omm=# select * from customer_t;
c_customer_sk | c_customer_id | c_first_name | c_last_name
---------------+---------------+--------------+-------------
3769 | 5 | Grace | White
6885 | 1 | Joes | Hunter
4321 | 2 | Lily | Carter
9527 | 3 | James | Cook
9500 | 4 | Lucy | Baker
(5 rows)
omm=# ROLLBACK;
NOTICE: there is no transaction in progress
#######################################################################
创建及插入表数据正常,但因为自动提交修改不生效,所以无法测试回滚;
omm=# ROLLBACK;
NOTICE: there is no transaction in progress
--\dt命令,命令\dt的作用是显示数据库中所有的表。
\dt
List of relations
Schema | Name | Type | Owner | Storage
--------+------------+-------+-------+----------------------------------
public | customer_t | table | omm | {orientation=row,compression=no}
(1 row)
查看表关系,所属schema,类型,属主,存储方式,是否开压缩;
omm=# \di
No relations found.
omm=# create index idx_customer_id on customer_t(c_customer_id);
CREATE INDEX
omm=#
omm=#
omm=# \di
public | idx_customer_id | index | omm | customer_t |
(1 row)
--\d TableName命令,元命令\d TableName的作用是查看某个表的信息。
\d customer_t
omm=# \d customer_t
Table "public.customer_t"
Column | Type | Modifiers
---------------+--------------+-----------
c_customer_sk | integer |
c_customer_id | character(5) |
c_first_name | character(6) |
c_last_name | character(8) |
类似于oracle desc 表查看列字段;
--\di IndexName命令,查看索引信息,元命令\di IndexName的作用是查看某个索引的信息。
create index idx_customer_id on customer_t(c_customer_id);
\di
omm=# \di
No relations found.
omm=# create index idx_customer_id on customer_t(c_customer_id);
CREATE INDEX
omm=# \di
omm=# List of relations
Schema | Name | Type | Owner | Table | Storage
--------+-----------------+-------+-------+------------+---------
public | idx_customer_id | index | omm | customer_t |
查看索引相关信息;
–可以用\pset命令以不同的方法显示表:
\pset border 2
SELECT * FROM customer_t;
omm=# \pset border 2
Border style is 2.
omm=# SELECT * FROM customer_t;
+---------------+---------------+--------------+-------------+
| c_customer_sk | c_customer_id | c_first_name | c_last_name |
+---------------+---------------+--------------+-------------+
| 3769 | 5 | Grace | White |
+---------------+---------------+--------------+-------------+
输出增量了边框显示;
默认显示:
omm=# SELECT * FROM customer_t;
c_customer_sk | c_customer_id | c_first_name | c_last_name
---------------+---------------+--------------+-------------
3769 | 5 | Grace | White
–打开扩展表格式模式。
\x
omm=# \x
Expanded display is on.
omm=# SELECT * FROM customer_t;
-[ RECORD 1 ]-+---------
c_customer_sk | 3769
c_customer_id | 5
c_first_name | Grace
c_last_name | White
显示又做了变更。




