omm=# \h
Available help:
ABORT BEGIN CREATE TABLESPACE DROP TEXT SEARCH CONFIGURATION
ALTER APP WORKLOAD GROUP CALL CREATE TEXT SEARCH CONFIGURATION DROP TEXT SEARCH DICTIONARY
ALTER APP WORKLOAD GROUP MAPPING CHECKPOINT CREATE TEXT SEARCH DICTIONARY DROP TRIGGER
ALTER AUDIT POLICY CLEAN CONNECTION CREATE TRIGGER DROP TYPE
ALTER DATA SOURCE CLOSE CREATE TYPE DROP USER
ALTER DEFAULT PRIVILEGES COMMENT CREATE VIEW DROP WEAK PASSWORD DICTIONARY
ALTER DIRECTORY COMMIT CREATE WEAK PASSWORD DICTIONARY DROP WORKLOAD GROUP
ALTER EXTENSION COMMIT PREPARED CREATE WORKLOAD GROUP END
ALTER FOREIGN TABLE FOR HDFS CREATE APP WORKLOAD GROUP DEALLOCATE EXECUTE DIRECT
ALTER FUNCTION CREATE APP WORKLOAD GROUP MAPPING DECLARE EXPLAIN
ALTER FOREIGN TABLE COPY CURSOR EXECUTE
ALTER GLOBAL CONFIGURATION CREATE AUDIT POLICY DELETE FETCH
ALTER DATABASE CLUSTER CREATE USER DROP VIEW
ALTER GROUP CREATE BARRIER DO GRANT
ALTER INDEX CREATE CLIENT MASTER KEY DROP APP WORKLOAD GROUP INSERT
ALTER LARGE OBJECT CREATE COLUMN ENCRYPTION KEY DROP APP WORKLOAD GROUP MAPPING LOCK
ALTER MASKING POLICY CREATE DATA SOURCE DROP AUDIT POLICY MERGE
ALTER MATERIALIZED VIEW CREATE DATABASE DROP CLIENT MASTER KEY MOVE
ALTER NODE CREATE DIRECTORY DROP COLUMN ENCRYPTION KEY PREDICT BY
ALTER NODE GROUP CREATE EXTENSION DROP DATA SOURCE PREPARE
ALTER OPERATOR CREATE FOREIGN TABLE DROP DATABASE PREPARE TRANSACTION
ALTER PACKAGE CREATE FUNCTION DROP DIRECTORY PUBLISH SNAPSHOT
omm=# \?
General
\copyright show openGauss usage and distribution terms
\g [FILE] or ; execute query (and send results to file or |pipe)
\h(\help) [NAME] help on syntax of SQL commands, * for all commands
\parallel [on [num]|off] toggle status of execute (currently off)
\q quit gsql
Query Buffer
\e [FILE] [LINE] edit the query buffer (or file) with external editor
\ef [FUNCNAME [LINE]] edit function definition with external editor
\p show the contents of the query buffer
\r reset (clear) the query buffer
\w FILE write query buffer to file
Input/Output
\copy ... perform SQL COPY with data stream to the client host
\echo [STRING] write string to standard output
\i FILE execute commands from file
omm@modb:~$ gsql --help
gsql is the openGauss interactive terminal.
Usage:
gsql [OPTION]... [DBNAME [USERNAME]]
General options:
-c, --command=COMMAND run only single command (SQL or internal) and exit
-d, --dbname=DBNAME database name to connect to (default: "omm")
-f, --file=FILENAME execute commands from file, then exit
-l, --list list available databases, then exit
-v, --set=, --variable=NAME=VALUE
set gsql variable NAME to VALUE
-V, --version output version information, then exit
-X, --no-gsqlrc do not read startup file (~/.gsqlrc)
-1 ("one"), --single-transaction
execute command file as a single transaction
-?, --help show this help, then exit
-L, --log-file=FILENAME send session log to file
-m, --maintenance can connect to cluster during 2-pc transaction recovery
-n, --no-libedit disable enhanced command line editing (libedit)
-o, --output=FILENAME send query results to file (or |pipe) -s, --single-step single-step mode (confirm each query)
-S, --single-line single-line mode (end of line terminates SQL command)
1.gsql命令连到数据库omm
2.查看数据库的版本、版权信息
omm=# select version(); 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) omm=# show server_version; server_version ---------------- 9.2.4 (1 row) omm=# \copyright GaussDB Kernel Database Management System Copyright (c) Huawei Technologies Co., Ltd. 2018. All rights reserved.3.常见元命令使用
omm=# \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) omm=# \conninfo You are connected to database "omm" as user "omm" via socket in "/tmp" at port "5432". omm=# \c postgres Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "postgres" as user "omm". openGauss=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+----------- gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} openGauss=# \dg List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+----------- gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} openGauss=# \db List of tablespaces Name | Owner | Location ------------+-------+---------- pg_default | omm | pg_global | omm | openGauss=# (2 rows) openGauss=# \dn List of schemas Name | Owner -----------------+--------- blockchain | omm cstore | omm db4ai | omm dbe_perf | omm dbe_pldebugger | omm dbe_pldeveloper | omm gaussdb | gaussdb pkg_service | omm public | omm snapshot | omm sqladvisor | omm (11 rows)4.使用两种方法,连到postgres数据库中
5.测试gsql中的默认事务自动提交功能
omm=# show AUTOCOMMIT; autocommit ------------ on (1 row) omm=# create table customer_new as select * from customer_t; INSERT 0 1 omm=# \q omm@modb:~$ gsql -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=# \dt List of relations Schema | Name | Type | Owner | Storage --------+--------------+-------+-------+---------------------------------- public | customer_new | table | omm | {orientation=row,compression=no} public | customer_t | table | omm | {orientation=row,compression=no} (2 rows)6.测试gsql中的事务手动提交功能
omm=# \set autocommit off 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-# (9527, 3, 'James', 'Cook'), omm-# (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; omm=# select * from customer_t; c_customer_sk | c_customer_id | c_first_name | c_last_name ---------------+---------------+--------------+------------- 3769 | 5 | Grace | White7.了解gsql相关帮助
omm=# \h Available help: ABORT BEGIN CREATE TABLESPACE DROP TEXT SEARCH CONFIGURATION ALTER APP WORKLOAD GROUP CALL CREATE TEXT SEARCH CONFIGURATION DROP TEXT SEARCH DICTIONARY ALTER APP WORKLOAD GROUP MAPPING CHECKPOINT CREATE TEXT SEARCH DICTIONARY DROP TRIGGER ALTER AUDIT POLICY CLEAN CONNECTION CREATE TRIGGER DROP TYPE ALTER DATA SOURCE CLOSE CREATE TYPE DROP USER ALTER DEFAULT PRIVILEGES COMMENT CREATE VIEW DROP WEAK PASSWORD DICTIONARY ALTER DIRECTORY COMMIT CREATE WEAK PASSWORD DICTIONARY DROP WORKLOAD GROUP ALTER EXTENSION COMMIT PREPARED CREATE WORKLOAD GROUP END ALTER FOREIGN TABLE FOR HDFS CREATE APP WORKLOAD GROUP DEALLOCATE EXECUTE DIRECT ALTER FUNCTION CREATE APP WORKLOAD GROUP MAPPING DECLARE EXPLAIN ALTER FOREIGN TABLE COPY CURSOR EXECUTE ALTER GLOBAL CONFIGURATION CREATE AUDIT POLICY DELETE FETCH ALTER DATABASE CLUSTER CREATE USER DROP VIEW ALTER GROUP CREATE BARRIER DO GRANT ALTER INDEX CREATE CLIENT MASTER KEY DROP APP WORKLOAD GROUP INSERT ALTER LARGE OBJECT CREATE COLUMN ENCRYPTION KEY DROP APP WORKLOAD GROUP MAPPING LOCK ALTER MASKING POLICY CREATE DATA SOURCE DROP AUDIT POLICY MERGE ALTER MATERIALIZED VIEW CREATE DATABASE DROP CLIENT MASTER KEY MOVE ALTER NODE CREATE DIRECTORY DROP COLUMN ENCRYPTION KEY PREDICT BY ALTER NODE GROUP CREATE EXTENSION DROP DATA SOURCE PREPARE ALTER OPERATOR CREATE FOREIGN TABLE DROP DATABASE PREPARE TRANSACTION ALTER PACKAGE CREATE FUNCTION DROP DIRECTORY PUBLISH SNAPSHOT omm=# \? General \copyright show openGauss usage and distribution terms \g [FILE] or ; execute query (and send results to file or |pipe) \h(\help) [NAME] help on syntax of SQL commands, * for all commands \parallel [on [num]|off] toggle status of execute (currently off) \q quit gsql Query Buffer \e [FILE] [LINE] edit the query buffer (or file) with external editor \ef [FUNCNAME [LINE]] edit function definition with external editor \p show the contents of the query buffer \r reset (clear) the query buffer \w FILE write query buffer to file Input/Output \copy ... perform SQL COPY with data stream to the client host \echo [STRING] write string to standard output \i FILE execute commands from file omm@modb:~$ gsql --help gsql is the openGauss interactive terminal. Usage: gsql [OPTION]... [DBNAME [USERNAME]] General options: -c, --command=COMMAND run only single command (SQL or internal) and exit -d, --dbname=DBNAME database name to connect to (default: "omm") -f, --file=FILENAME execute commands from file, then exit -l, --list list available databases, then exit -v, --set=, --variable=NAME=VALUE set gsql variable NAME to VALUE -V, --version output version information, then exit -X, --no-gsqlrc do not read startup file (~/.gsqlrc) -1 ("one"), --single-transaction execute command file as a single transaction -?, --help show this help, then exit -L, --log-file=FILENAME send session log to file -m, --maintenance can connect to cluster during 2-pc transaction recovery -n, --no-libedit disable enhanced command line editing (libedit) -o, --output=FILENAME send query results to file (or |pipe) -s, --single-step single-step mode (confirm each query) -S, --single-line single-line mode (end of line terminates SQL command)