Need to list databases in PostgreSQL? This guide covers three methods: using the command line, SQL queries, and database clients.
Command-Line Method, use psql
for a quick database list:
Connect
psql -U <username>
List databases
\\l
\\l+
Query method, pg_catalog.pg_database
SELECT *
FROM pg_catalog.pg_database
WHERE datistemplate = false;
This shows user databases only.
Use a client like DbVisualizer:
Connect to your server.
Open the “Databases” section.
FAQ
How to list PostgreSQL databases with a single command?
psql -U <username> -l
How to get the list of tables in a database with psql? ¨
Connect to;
\\c <database_name>
and list tables;
\\dt
What is the easiest way to list databases in PostgreSQL?
Use a database client for a graphical interface.
How to use pgAdmin to view the list of databases?
Open pgAdmin, connect to the server, and expand "Databases".
Conclusion
Listing PostgreSQL databases is straightforward with command-line tools, queries, or clients. For more details, read the article How to List Databases in Postgres Using psql and Other Techniques.