How to list database postgres & tables using psql?

329    Asked by FukudaAshikaga in SQL Server , Asked on Oct 3, 2022

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.

Answered by Gabrielle Dowd

To list database postgres & tables using psql-


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.



Your Answer

Interviews

Parent Categories