PostgreSQL: Show tables in PostgreSQL

后端 未结 24 2591
醉梦人生
醉梦人生 2020-11-28 16:58

What\'s the equivalent to show tables (from MySQL) in PostgreSQL?

24条回答
  •  春和景丽
    2020-11-28 17:22

    You can use PostgreSQL's interactive terminal Psql to show tables in PostgreSQL.

    1. Start Psql

    Usually you can run the following command to enter into psql:

    psql DBNAME USERNAME
    

    For example, psql template1 postgres

    One situation you might have is: suppose you login as root, and you don't remember the database name. You can just enter first into Psql by running:

    sudo -u postgres psql
    

    In some systems, sudo command is not available, you can instead run either command below:

    psql -U postgres
    psql --username=postgres
    

    2. Show tables

    Now in Psql you could run commands such as:

    1. \? list all the commands
    2. \l list databases
    3. \conninfo display information about current connection
    4. \c [DBNAME] connect to new database, e.g., \c template1
    5. \dt list tables of the public schema
    6. \dt .* list tables of certain schema, e.g., \dt public.*
    7. \dt *.* list tables of all schemas
    8. Then you can run SQL statements, e.g., SELECT * FROM my_table;(Note: a statement must be terminated with semicolon ;)
    9. \q quit psql

提交回复
热议问题