PostgreSQL Tutorial

Data Types

Querying & Filtering Data

Managing Tables

Modifying Data

Conditionals

Control Flow

Transactions & Constraints

Working with JOINS & Schemas

Roles & Permissions

Working with Sets

Subquery & CTEs

User-defined Functions

Important In-Built Functions

PostgreSQL PL/pgSQL

Variables & Constants

Stored Procedures

Working with Triggers

Working with Views & Indexes

Errors & Exception Handling

PostgreSQL - Show Databases

In PostgreSQL, the concept of "databases" is a bit different than in some other database systems. Each PostgreSQL "cluster" can contain multiple databases, and you often connect to a specific database when you initiate your session.

To get a list of all databases in your PostgreSQL cluster, you can use the \l or \list command from the PostgreSQL command line tool, psql.

If you're already inside a psql session:

\l

OR

\list

However, if you want to retrieve a list of databases using a SQL query (which can be used in any environment where you can execute SQL, not just psql), you can query the pg_database system catalog:

SELECT datname FROM pg_database;

This will return a list of all databases in your PostgreSQL cluster.

Note: To run the above commands or query, you need to have appropriate privileges. If you're connected as the PostgreSQL superuser, you should have no problems. If you're connected as a different user, you might not see all databases or might not be able to query pg_database, depending on the permissions granted to your user.

  1. List databases in PostgreSQL: To list all databases in PostgreSQL, you can use the following SQL query:

    SELECT datname FROM pg_database;
    
  2. Show all databases in PostgreSQL: In PostgreSQL, you can display a list of all databases using the command:

    \l
    
  3. PostgreSQL command to display databases: Use the following SQL query to display all databases:

    SELECT datname FROM pg_database;
    
  4. How to view available databases in PostgreSQL: To view available databases, you can use the following psql command:

    \l
    
  5. List of databases in psql PostgreSQL: Inside the psql terminal, you can list databases using:

    \l
    
  6. Query to show databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  7. PostgreSQL command to check existing databases:

    SELECT datname FROM pg_database;
    
  8. psql command to list databases in PostgreSQL: In the psql terminal, use:

    \l
    
  9. Display all databases in PostgreSQL terminal: To display all databases in the terminal, you can use the psql command:

    \l
    
  10. SQL query to get a list of databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  11. List all PostgreSQL databases with psql: In the psql terminal, use:

    \l
    
  12. Check existing databases in PostgreSQL server:

    SELECT datname FROM pg_database;
    
  13. Command to see databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  14. Get database names in PostgreSQL:

    SELECT datname FROM pg_database;
    
  15. Query to show current databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  16. Viewing database names in PostgreSQL:

    SELECT datname FROM pg_database;
    
  17. psql command to show database names: In the psql terminal, use:

    \l
    
  18. Checking available databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  19. SQL command to list databases in PostgreSQL:

    SELECT datname FROM pg_database;
    
  20. How to retrieve database names in PostgreSQL:

    SELECT datname FROM pg_database;