查看对象

gsql工具提供了若干高级特性,便于用户使用。常见用法如下:

  • 查看命令帮助信息

    1. \h [NAME]

    例如,查询ABORT的所有语法。

    1. openGauss=# \h ABORT
    2. Command: ABORT
    3. Description: abort the current transaction
    4. Syntax:
    5. ABORT [ WORK | TRANSACTION ] ;
  • 切换数据库

    1. \c dbname

    例如,将postgres数据库切换为数据库db_tpcc。

    1. openGauss=# \c db_tpcc
    2. Non-SSL connection (SSL connection is recommended when requiring high-security)
    3. You are now connected to database "db_tpcc" as user "omm".
    4. db_tpcc=#
  • 查询所有数据库

    1. \l

    示例如下。

    1. openGauss=# \l
    2. List of databases
    3. Name | Owner | Encoding | Collate | Ctype | Access privileges
    4. -----------+-------+-----------+---------+-------+-------------------
    5. mydb | omm | GBK | C | C |
    6. postgres | omm | SQL_ASCII | C | C |
    7. template0 | omm | SQL_ASCII | C | C | =c/omm +
    8. | | | | | omm=CTc/omm
    9. template1 | omm | SQL_ASCII | C | C | =c/omm +
    10. | | | | | omm=CTc/omm
    11. (4 rows)
  • 查询当前数据库中的所有表

    1. \dt

    示例如下。

    1. openGauss=# \dt
    2. List of relations
    3. Schema | Name | Type | Owner | Storage
    4. --------+-----------------+-------+-------+----------------------------------
    5. public | customer_t1 | table | omm | {orientation=row,compression=no}
    6. public | customer_t1_bak | table | omm | {orientation=row,compression=no}
    7. (2 rows)
  • 查看表结构

    1. \d tablename

    例如,查看表customer_t1的表结构。

    1. openGauss=# \d customer_t1
    2. Table "public.customer_t1"
    3. Column | Type | Modifiers
    4. ---------------+--------------+-----------
    5. c_customer_sk | integer |
    6. c_customer_id | character(5) |
    7. c_first_name | character(6) |
    8. c_last_name | character(8) |
    9. amount | integer |