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)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Explore this insightful write-up embraced by the inclusive DEV Community. Tech enthusiasts of all skill levels can contribute insights and expand our shared knowledge.

Spreading a simple "thank you" uplifts creators—let them know your thoughts in the discussion below!

At DEV, collaborative learning fuels growth and forges stronger connections. If this piece resonated with you, a brief note of thanks goes a long way.

Okay