DEV Community

Cover image for Efficient Ways to List PostgreSQL Databases
DbVisualizer
DbVisualizer

Posted on

Efficient Ways to List PostgreSQL Databases

Learn how to list databases in PostgreSQL using command-line tools, SQL queries, and database clients. Each method is tailored to different preferences and requirements.

Use the command-Line method to connect and list databases with psql:

  1. Connect

    psql -U <username>
    
  2. List databases

    \l
    
```
\l+
```
Enter fullscreen mode Exit fullscreen mode

Retrieve databases using a query

SELECT * 
FROM pg_catalog.pg_database 
WHERE datistemplate = false;
Enter fullscreen mode Exit fullscreen mode

Use a client like DbVisualizer;

  1. Connect to your server.
  2. View the databases in the “Databases” section.

FAQ

How to list PostgreSQL databases with a single command?

psql -U <username> -l
Enter fullscreen mode Exit fullscreen mode

How to get the list of tables in a database with psql?

Connect to a database;

\c <database_name>
Enter fullscreen mode Exit fullscreen mode

List tables;

\dt
Enter fullscreen mode Exit fullscreen mode

What is the easiest way to list databases in PostgreSQL?

Using a database client for an intuitive interface.

How to use pgAdmin to view the list of databases?

Open pgAdmin, connect, and expand "Databases".

Conclusion

Listing PostgreSQL databases can be done via command-line tools, queries, or database clients. Choose the method that fits your workflow. For detailed instructions, read the article How to List Databases in Postgres Using psql and Other Techniques.

Top comments (0)