暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第2天 | openGauss客户端工具gsql的使用

原创 xiaocx 2022-11-25
284

学习目标

学习openGauss数据库客户端工具gsql的使用。

课程学习内容

gsql是openGauss提供在命令行下运行的数据库连接工具,可以通过此工具连接服务器并对其进行操作和维护,除了具备操作数据库的基本功能,gsql还提供了若干高级特性,便于用户使用。

  • 1.使用gsql命令连接数据库
  • 2.在gsql中查看数据库的版本、pg基础版本和版权信息
  • 3.常见元命令的使用
  • 4.gsql中的事务:测试gsql中的默认事务自动提交功能
  • 5.gsql中的事务:测试gsql中的事务手动提交功能
  • 6.gsql相关的帮助

作业练习

1.gsql命令连到数据库omm

root@modb:~# su - omm
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=#


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.常见元命令使用

  • \l命令,元命令\l的作用是显示openGauss数据库集簇中,目前有哪些数据库。
  •  \conninfo命令,元命令\conninfo的作用是在gsql中,显示会话的连接信息。
  •  \c[onnect] [DBNAME]命令,元命令\ c[onnect] [DBNAME]的作用是在gsql中,切换连接的数据库postgres。 
  • \du命令和\dg命令,元命令\dg命令与元命令\du命令的作用类似,都是显示openGauss数据库集簇中,目前有哪些用户和角色。 
  • \db命令,元命令\db的作用是显示openGauss数据库集簇中,目前有哪些表空间。 
  • \dn命令,元命令\dn的作用是显示当前数据库有哪些数据库模式。 
  • \dt命令,命令\dt的作用是显示数据库中所有的表。 
  • \d TableName命令,元命令\d TableName的作用是查看某个表的信息。 
  • \di IndexName命令,查看索引信息,元命令\di IndexName的作用是查看某个索引的信息。 
  • \pset命令可以以不同的方法显示表
  • \x打开扩展表格式模式。
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
 gaussdb   | Sysadmin                                                                                                         | {}
 omm       | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}

openGauss-#                                                               List of roles
 Role name |                                                    Attributes                                                    | Member of 
-----------+------------------------------------------------------------------------------------------------------------------+-----------

openGauss-# \dg
                                                              List of roles
 Role name |                                                    Attributes                                                    | Member of 
 omm       | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}

openGauss-# -----------+------------------------------------------------------------------------------------------------------------------+-----------
 gaussdb   | Sysadmin                                                                                                         | {}

openGauss-# \db
      List of tablespaces
    Name    | Owner | Location 
------------+-------+----------
 pg_default | omm   | 
 pg_global  | omm   | 
(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)
openGauss=# CREATE TABLE customer_t
(  c_customer_sk             integer,   
 c_customer_id             char(5),    
 c_first_name              char(6),    
 c_last_name               char(8) 
) ;
CREATE TABLE

openGauss=# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES (3769, 5, 'Grace','White');
openGauss=# INSERT 0 1
openGauss=# \dt
                           List of relations
 Schema |    Name    | Type  | Owner |             Storage              
--------+------------+-------+-------+----------------------------------
 public | customer_t | table | omm   | {orientation=row,compression=no}
(1 row)

openGauss=# \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) | 

openGauss=# create index idx_customer_id on customer_t(c_customer_id);
CREATE INDEX
openGauss=# \di
                        List of relations
 Schema |      Name       | Type  | Owner |   Table    | Storage 
--------+-----------------+-------+-------+------------+---------
 public | idx_customer_id | index | omm   | customer_t | 
(1 row)

openGauss=# \pset border 2
Border style is 2.
openGauss=# SELECT * FROM customer_t;
+---------------+---------------+--------------+-------------+
| c_customer_sk | c_customer_id | c_first_name | c_last_name |
+---------------+---------------+--------------+-------------+
openGauss=# |          3769 | 5             | Grace        | White       |
+---------------+---------------+--------------+-------------+
(1 row)
openGauss=# \x
Expanded display is on.


4.使用两种方法,连到postgres数据库中

#方法一:omm@modb:~$ gsql -d postgres  -p 5432  -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.openGauss=# \q
omm@modb:~$

#方法二:
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-# \c postgres Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "postgres" as user "omm". openGauss-#


5.测试gsql中的默认事务自动提交功能

事务自动提交功能关闭测试:

omm@modb:~$ gsql -d postgres  -p 5432  -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.

openGauss=# \set AUTOCOMMIT off
openGauss=# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES    
(6885, 1, 'Joes', 'Hunter'),    
(4321, 2, 'Lily','Carter'),    
(9527, 3, 'James', 'Cook'),
(9500, 4, 'Lucy', 'Baker');
INSERT 0 4
openGauss=# 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    
openGauss=#           9500 | 4             | Lucy         | Baker   
(5 rows)

openGauss=# ROLLBACK;
ROLLBACK
openGauss=# SELECT * FROM customer_t;
 c_customer_sk | c_customer_id | c_first_name | c_last_name 
---------------+---------------+--------------+-------------
          3769 | 5             | Grace        | White   
(1 row)

openGauss=# 

事务自动提交功能开启测试:

omm@modb:~$ gsql -d postgres  -p 5432  -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.

openGauss=# \set AUTOCOMMIT on
openGauss=# openGauss-# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES    
(6885, 1, 'Joes', 'Hunter'),    
openGauss-# (4321, 2, 'Lily','Carter'),    
openGauss-# (9527, 3, 'James', 'Cook'),
openGauss-# (9500, 4, 'Lucy', 'Baker');
INSERT 0 4
openGauss=# 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)

openGauss=# ROLLBACK;
NOTICE:  there is no transaction in progress
ROLLBACK
openGauss=# 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)


6.测试gsql中的事务手动提交功能

openGauss=# \set AUTOCOMMIT off
openGauss=# 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   
openGauss=# (5 rows)


openGauss=# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES    
openGauss-# openGauss-# (6885, 1, 'Joes', 'Hunter'),    
(4321, 2, 'Lily','Carter'),    
openGauss-# (9527, 3, 'James', 'Cook'),
openGauss-# (9500, 4, 'Lucy', 'Baker');
INSERT 0 4
openGauss=# 
openGauss=# 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   
          6885 | 1             | Joes         | Hunter  
          4321 | 2             | Lily         | Carter  
          9527 | 3             | James        | Cook    
          9500 | 4             | Lucy         | Baker   
(9 rows)

openGauss=# commit;
COMMIT
openGauss=# \q
omm@modb:~$ gsql -d postgres  -p 5432  -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.

openGauss=# 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   
          6885 | 1             | Joes         | Hunter  
          4321 | 2             | Lily         | Carter  
          9527 | 3             | James        | Cook    
          9500 | 4             | Lucy         | Baker   
(9 rows)

openGauss=# 


7.了解gsql相关帮助

  • gsql --help
  • \h
  • \?
详细情况如下:
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)
  -e, --echo-queries       echo commands sent to server
  -E, --echo-hidden        display queries that internal commands generate
  -k, --with-key=KEY       the key for decrypting the encrypted file
  -L, --log-file=FILENAME  send session log to file  -1 ("one"), --single-transaction
                           execute command file as a single transaction
  -?, --help               show this help, then exit

Input and output options:
  -a, --echo-all           echo all input from script

  -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)
  -q, --quiet              run quietly (no messages, only query output)
  -C, --enable-client-encryption              enable client encryption feature
  -s, --single-step        single-step mode (confirm each query)
  -S, --single-line        single-line mode (end of line terminates SQL command)

                           set record separator to zero byte
  -2, --pipeline           use pipeline to pass the password, forbidden to use in terminal
                           must use with -c or -f

Connection options:
Output format options:
  -A, --no-align           unaligned table output mode
  -F, --field-separator=STRING
                           set field separator (default: "|")
  -H, --html               HTML table output mode
  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \pset command)
  -R, --record-separator=STRING
                           set record separator (default: newline)
  -r                       if this parameter is set,use libedit 
  -t, --tuples-only        print rows only
  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)
  -x, --expanded           turn on expanded table output
  -z, --field-separator-zero
                           set field separator to zero byte
  -0, --record-separator-zero


  -W, --password=PASSWORD  the password of specified database user

For more information, type "\?" (for internal commands) or "\help" (for SQL
commands) from within gsql, or consult the gsql section in the openGauss documentation.
  -h, --host=HOSTNAME      database server host or socket directory (default: "local socket")
                           allow multi host IP address with comma separator in centralized cluster
  -p, --port=PORT          database server port (default: "5432")
  -U, --username=USERNAME  database user name (default: "omm")omm@modb:~$ gsql -d postgres  -p 5432  -r^C
omm@modb:~$ omm@modb:~$ 

omm@modb:~$ 
omm@modb:~$ gsql -d postgres  -p 5432  -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.

openGauss=# \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 DIRECTORY                   COMMIT                            CREATE WEAK PASSWORD DICTIONARY   DROP WORKLOAD GROUP
  ALTER EXTENSION                   COMMIT PREPARED                   CREATE WORKLOAD GROUP             END
  ALTER FOREIGN TABLE               COPY                              CURSOR                            EXECUTE
  ALTER DATABASE                    CLUSTER                           CREATE USER                       DROP VIEW
  ALTER DEFAULT PRIVILEGES          COMMENT                           CREATE VIEW                       DROP WEAK PASSWORD DICTIONARY
  ALTER FOREIGN TABLE FOR HDFS      CREATE APP WORKLOAD GROUP         DEALLOCATE                        EXECUTE DIRECT
  ALTER FUNCTION                    CREATE APP WORKLOAD GROUP MAPPING DECLARE                           EXPLAIN
  ALTER GLOBAL CONFIGURATION        CREATE AUDIT POLICY               DELETE                            FETCH
  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 OPERATOR                    CREATE FOREIGN TABLE              DROP DATABASE                     PREPARE TRANSACTION
  ALTER NODE GROUP                  CREATE EXTENSION                  DROP DATA SOURCE                  PREPARE
  ALTER PACKAGE                     CREATE FUNCTION                   DROP DIRECTORY                    PUBLISH SNAPSHOT
--More--
Most commands optionally preceded by integer argument k.  Defaults in brackets.
Star (*) indicates argument becomes new default.
-------------------------------------------------------------------------------
<space>                 Display next k lines of text [current screen size]
z                       Display next k lines of text [current screen size]*
<return>                Display next k lines of text [1]*
d or ctrl-D             Scroll k lines [current scroll size, initially 11]*
q or Q or <interrupt>   Exit from more
s                       Skip forward k lines of text [1]
f                       Skip forward k screenfuls of text [1]
b or ctrl-B             Skip backwards k screenfuls of text [1]
'                       Go to place where previous search started
=                       Display current line number
/<regular expression>   Search for kth occurrence of regular expression [1]
n                       Search for kth occurrence of last r.e [1]
!<cmd> or :!<cmd>       Execute <cmd> in a subshell
v                       Start up /usr/bin/vi at current line
ctrl-L                  Redraw screen
:n                      Go to kth next file [1]
:p                      Go to kth previous file [1]
:f                      Display current file name and line number
.                       Repeat previous command
-------------------------------------------------------------------------------
  ALTER PUBLICATION                 CREATE GROUP                      DROP EXTENSION                    PURGE
  ALTER RESOURCE LABEL              CREATE INDEX                      DROP FOREIGN TABLE                PURGE SNAPSHOT
  ALTER RESOURCE POOL               CREATE LANGUAGE                   DROP FUNCTION                     REASSIGN OWNED
  ALTER ROLE                        CREATE MASKING POLICY             DROP GLOBAL CONFIGURATION         REFRESH MATERIALIZED VIEW
  ALTER ROW LEVEL SECURITY POLICY   CREATE MATERIALIZED VIEW          DROP GROUP                        REINDEX
  ALTER SCHEMA                      CREATE MODEL                      DROP INDEX                        RESET
  ALTER SEQUENCE                    CREATE NODE                       DROP MASKING POLICY               REVOKE
  ALTER SERVER                      CREATE NODE GROUP                 DROP MATERIALIZED VIEW            ROLLBACK
  ALTER SESSION                     CREATE OPERATOR                   DROP MODEL                        ROLLBACK PREPARED
  ALTER SUBSCRIPTION                CREATE PACKAGE                    DROP NODE                         SAMPLE SNAPSHOT
  ALTER SYNONYM                     CREATE PACKAGE BODY               DROP NODE GROUP                   SAVEPOINT
  ALTER SYSTEM KILL SESSION         CREATE PROCEDURE                  DROP OPERATOR                     SELECT
  ALTER SYSTEM SET                  CREATE PUBLICATION                DROP OWNED                        SELECT INTO
  ALTER TABLE                       CREATE RESOURCE LABEL             DROP PACKAGE                      SET
  ALTER TABLE PARTITION             CREATE RESOURCE POOL              DROP PACKAGE BODY                 SET CONSTRAINTS
  ALTER TABLE SUBPARTITION          CREATE ROLE                       DROP PROCEDURE                    SET ROLE
  ALTER TABLESPACE                  CREATE ROW LEVEL SECURITY POLICY  DROP PUBLICATION                  SET SESSION AUTHORIZATION
  ALTER TEXT SEARCH CONFIGURATION   CREATE SCHEMA                     DROP RESOURCE LABEL               SET TRANSACTION
  ALTER TEXT SEARCH DICTIONARY      CREATE SEQUENCE                   DROP RESOURCE POOL                SHOW
  ALTER TRIGGER                     CREATE SERVER                     DROP ROLE                         START TRANSACTION
  ALTER VIEW                        CREATE SUBSCRIPTION               DROP SEQUENCE                     UPDATE
  ALTER TYPE                        CREATE SNAPSHOT AS                DROP ROW LEVEL SECURITY POLICY    TIMECAPSULE TABLE
  ALTER USER                        CREATE SNAPSHOT FROM              DROP SCHEMA                       TRUNCATE
  ALTER WORKLOAD GROUP              CREATE SYNONYM                    DROP SERVER                       VACUUM
  ANALYSE                           CREATE TABLE                      DROP SUBSCRIPTION                 VALUES
  ANALYZE                           CREATE TABLE AS                   DROP SYNONYM                      
  ANONYMOUS BLOCK                   CREATE TABLE PARTITION            DROP TABLE                        
  ARCHIVE SNAPSHOT                  CREATE TABLE SUBPARTITION         DROP TABLESPACE                   
openGauss=# \?
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
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
  \i+ FILE KEY           execute commands from encrypted file
  \ir FILE               as \i, but relative to location of current script
  \qecho [STRING]        write string to query output stream (see \o)
--More--  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \w FILE                write query buffer to file

  \ir+ FILE KEY          as \i+, but relative to location of current script
  \o [FILE]              send all query results to file or |pipe

Informational
  (options: S = show system objects, + = additional detail)
  \d[S+]                 list tables, views, and sequences
  \d[S+]  NAME           describe table, view, sequence, or index
  \da[S]  [PATTERN]      list aggregates
  \db[+]  [PATTERN]      list tablespaces
  \dc[S+] [PATTERN]      list conversions
  \dC[+]  [PATTERN]      list casts
  \dd[S]  [PATTERN]      show object descriptions not displayed elsewhere
  \ddp    [PATTERN]      list default privileges
  \dD[S+] [PATTERN]      list domains
  \ded[+] [PATTERN]      list data sources
  \det[+] [PATTERN]      list foreign tables
  \des[+] [PATTERN]      list foreign servers
  \deu[+] [PATTERN]      list user mappings
  \dew[+] [PATTERN]      list foreign-data wrappers
  \di[S+] [PATTERN]      list indexes
--More--  \df[antw][S+] [PATRN]  list [only agg/normal/trigger/window] functions
  \dF[+]  [PATTERN]      list text search configurations
  \dFd[+] [PATTERN]      list text search dictionaries
  \dFp[+] [PATTERN]      list text search parsers
  \dFt[+] [PATTERN]      list text search templates
  \dg[+]  [PATTERN]      list roles
  \dl                    list large objects, same as \lo_list
  \dL[S+] [PATTERN]      list procedural languages
  \dm[S+] [PATTERN]      list materialized views
  \dn[S+] [PATTERN]      list schemas
  \do[S]  [PATTERN]      list operators
--More--  \dO[S+] [PATTERN]      list collations
  \dp     [PATTERN]      list table, view, and sequence access privileges
  \drds [PATRN1 [PATRN2]] list per-database role settings
  \ds[S+] [PATTERN]      list sequences
  \dt[S+] [PATTERN]      list tables
  \dT[S+] [PATTERN]      list data types
  \du[+]  [PATTERN]      list roles
  \dv[S+] [PATTERN]      list views
  \dE[S+] [PATTERN]      list foreign tables
  \dx[+]  [PATTERN]      list extensions
  \l[+]                  list all databases
  \sf[+] FUNCNAME        show a function's definition
  \z      [PATTERN]      same as \dp

Formatting
  \a                     toggle between unaligned and aligned output mode
  \C [STRING]            set table title, or unset if none
  \f [STRING]            show or set field separator for unaligned query output
  \H                     toggle HTML output mode (currently off)
  \pset NAME [VALUE]     set table output option
                         (NAME := {format|border|expanded|fieldsep|fieldsep_zero|footer|null|
                         numericlocale|recordsep|recordsep_zero|tuples_only|title|tableattr|pager|
                         feedback})
  \cd [DIR]              change the current working directory
  \setenv NAME [VALUE]   set or unset environment variable
  \timing [on|off]       toggle timing of commands (currently off)
  \t [on|off]            show only rows (currently off)
  \T [STRING]            set HTML <table> tag attributes, or unset if none
  \x [on|off|auto]       toggle expanded output (currently off)

Connection
  \c[onnect] [DBNAME|- USER|- HOST|- PORT|-]
                         connect to new database (currently "postgres")
  \encoding [ENCODING]   show or set client encoding
  \conninfo              display information about current connection

Operating System
  \prompt [TEXT] NAME    prompt user to set internal variable
--More--  \! [COMMAND]           execute command in shell or start interactive shell

Variables
Large Objects
  \lo_export LOBOID FILE
  \lo_import FILE [COMMENT]
  \lo_list
  \lo_unlink LOBOID      large object operations
  \set [NAME [VALUE]]    set internal variable, or list all if no parameters
  \unset NAME            unset (delete) internal variable

openGauss=#
最后修改时间:2022-12-03 11:48:00
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论