You are on page 1of 2

To List Databases:

You can use any one of below commands to list all databases in PostgreSQL.

postgres=# \list

postgres=# \l

List all Tables in Database:

To list tables of any database first you connect to that database and then view tables in that database.

First command will connect you with database (example: mydb) to which you want to see tables and

second command will list tables.

postgres=# \connect mydb

mydb=# \dt

ostgreSQL is one of the best database engines for an average web project and many who moves
to psql from mysql (for example) often ask the following questions: what is the analog of show
tables in postgres? or how can I get the list of databases in postgres like show databases in
mysql? The answers are short:

mysql: SHOW TABLES


postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

mysql: SHOW DATABASES


postgresql: \l
postgresql: SELECT datname FROM pg_database;

mysql: SHOW COLUMNS


postgresql: \d table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name
='table';

mysql: DESCRIBE TABLE


postgresql: \d+ table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name
='table';

You might also like