PostgreSQL – Show Databases
In PostgreSQL, there are couple of ways to list all the databases present on the server. In this article, we will explore them.
Using the pSQL command:
To list all the database present in the current database server use one of the following commands:
Syntax: \l or \l+
Example:
First log into the PostgreSQL server using the pSQL shell:
Now use the below command to list all databases using a superuser such as postgres:
\l
This will lead to the following:
Alternatively one can use the below command:
\l+
Output:
Using SELECT statement:
The SELECT statement can also be used to list all the database present on the server:
Syntax: SELECT datname FROM pg_database;
Example:
Below is the simple use of the SELECT statement to list all database present on the server:
SELECT datname FROM pg_database;
Output: