PostgreSQL – How to List All Databases and Tables Using psql

command linepostgresqlpsqltools

I am trying to learn PostgreSQL administration and have started learning how to use the psql command line tool.

When I log in with psql --username=postgres, how do I list all databases and tables?

I have tried \d, d and dS+ but nothing is listed. I have created two databases and a few tables with pgAdmin III, so I know they should be listed.

Best Answer

Please note the following commands:

  • \list or \l: list all databases
  • \dt: list all tables in the current database using your search_path
  • \dt *.: list all tables in the current database regardless your search_path

You will never see tables in other databases, these tables aren't visible. You have to connect to the correct database to see its tables (and other objects).

To switch databases:

\connect database_name or \c database_name

See the manual about psql.