How do I get postgres list databases in PSQL?

336    Asked by Amitraj in Cyber Security , Asked on Sep 27, 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 Amit Sinha

This postgres lists databases:


SELECT datname FROM pg_database
WHERE datistemplate = false;
This lists tables in the current database
SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name ;

Your Answer

Interviews

Parent Categories