snippetsqlCritical
How do I list all databases and tables using psql?
Viewed 0 times
tablesdatabasesallpsqlusinghowandlist
Problem
When I log in with
I have tried
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:
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:
See the manual about psql.
\listor\l: list all databases
\c: connect to a certain database
\dt: list all tables in the current database using yoursearch_path
\dt *.: list all tables in the current database regardless yoursearch_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_nameSee the manual about psql.
Context
StackExchange Database Administrators Q#1285, answer score: 2010
Revisions (0)
No revisions yet.