DEV Community

wanglei
wanglei

Posted on

Viewing Objects

gsql provides several advanced features to facilitate user operations. The common usage is as follows:

Query the command help information.

\h [NAME]
Enter fullscreen mode Exit fullscreen mode

For example, query all syntaxes of the ABORT statement.

openGauss=# \h ABORT
Command:     ABORT
Description: abort the current transaction
Syntax:
ABORT [ WORK | TRANSACTION ] ;

Enter fullscreen mode Exit fullscreen mode

Switch databases.

\c dbname

Enter fullscreen mode Exit fullscreen mode

For example, switch the postgres database to the dp_tpcc database.

openGauss=# \c db_tpcc
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "db_tpcc" as user "omm".
db_tpcc=# 
Enter fullscreen mode Exit fullscreen mode

Query all databases.

\l

Enter fullscreen mode Exit fullscreen mode

The following is an example:

openGauss=# \l
                          List of databases
   Name    | Owner | Encoding  | Collate | Ctype | Access privileges
-----------+-------+-----------+---------+-------+-------------------
 mydb      | omm   | GBK       | C       | C     |
 postgres  | omm   | SQL_ASCII | C       | C     |
 template0 | omm   | SQL_ASCII | C       | C     | =c/omm           +
           |       |           |         |       | omm=CTc/omm
 template1 | omm   | SQL_ASCII | C       | C     | =c/omm           +
           |       |           |         |       | omm=CTc/omm
(4 rows)
Enter fullscreen mode Exit fullscreen mode

Query all tables in the current database.

\dt
Enter fullscreen mode Exit fullscreen mode

The following is an example:

openGauss=# \dt
                              List of relations
 Schema |      Name       | Type  | Owner |             Storage
--------+-----------------+-------+-------+----------------------------------
 public | customer_t1     | table | omm   | {orientation=row,compression=no}
 public | customer_t1_bak | table | omm   | {orientation=row,compression=no}
(2 rows)
Enter fullscreen mode Exit fullscreen mode

View a table structure.

\d tablename

For example, view the structure of the customer_t1 table.

openGauss=# \d customer_t1
        Table "public.customer_t1"
    Column     |     Type     | Modifiers
---------------+--------------+-----------
 c_customer_sk | integer      |
 c_customer_id | character(5) |
 c_first_name  | character(6) |
 c_last_name   | character(8) |
 amount        | integer      |
Enter fullscreen mode Exit fullscreen mode

Top comments (0)