HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlCritical

How do I list all databases and tables using psql?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablesdatabasesallpsqlusinghowandlist

Problem

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.

Solution

Please note the following commands:

  • \list or \l: list all databases



  • \c : connect to a certain database



  • \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.

Context

StackExchange Database Administrators Q#1285, answer score: 2010

Revisions (0)

No revisions yet.