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.

DevCycle image

Ship Faster, Stay Flexible.

DevCycle is the first feature flag platform with OpenFeature built-in to every open source SDK, designed to help developers ship faster while avoiding vendor-lock in.

Start shipping

Top comments (0)

Via QT image

Effortless, secure sharing for even your largest files.

No centralized keys. Post-quantum, end-to-end encryption means no one, not even VIA, can access your data.

To celebrate our launch and Cybersecurity Awareness Month, we’re giving you 1 TB of FREE data transfers when you sign up in October.

See more 🎥