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
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.
List databases in PostgreSQL: To list all databases in PostgreSQL, you can use the following SQL query:
SELECT datname FROM pg_database;
Show all databases in PostgreSQL: In PostgreSQL, you can display a list of all databases using the command:
\l
PostgreSQL command to display databases: Use the following SQL query to display all databases:
SELECT datname FROM pg_database;
How to view available databases in PostgreSQL: To view available databases, you can use the following psql command:
\l
List of databases in psql PostgreSQL: Inside the psql terminal, you can list databases using:
\l
Query to show databases in PostgreSQL:
SELECT datname FROM pg_database;
PostgreSQL command to check existing databases:
SELECT datname FROM pg_database;
psql command to list databases in PostgreSQL: In the psql terminal, use:
\l
Display all databases in PostgreSQL terminal: To display all databases in the terminal, you can use the psql command:
\l
SQL query to get a list of databases in PostgreSQL:
SELECT datname FROM pg_database;
List all PostgreSQL databases with psql: In the psql terminal, use:
\l
Check existing databases in PostgreSQL server:
SELECT datname FROM pg_database;
Command to see databases in PostgreSQL:
SELECT datname FROM pg_database;
Get database names in PostgreSQL:
SELECT datname FROM pg_database;
Query to show current databases in PostgreSQL:
SELECT datname FROM pg_database;
Viewing database names in PostgreSQL:
SELECT datname FROM pg_database;
psql command to show database names: In the psql terminal, use:
\l
Checking available databases in PostgreSQL:
SELECT datname FROM pg_database;
SQL command to list databases in PostgreSQL:
SELECT datname FROM pg_database;
How to retrieve database names in PostgreSQL:
SELECT datname FROM pg_database;