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+
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:
This will lead to the following:
Alternatively one can use the below command:
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;
Below is the simple use of the SELECT statement to list all database present on the server:
SELECT datname FROM pg_database;
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.