How to Show Databases in PostgreSQL

Different database management systems adopt different approaches to show the list of available databases. For instance, to show the list of databases, the “SHOW DATABASES” statement is used in MySQL, the “\l” statement is used in PostgreSQL, and so on.

This write-up will teach you how to show databases in PostgreSQL via SQL Shell and pgAdmin. So, let’s get started.

How to Show Databases in Postgres Using SQL Shell?

Use the “\l” command from the SQL Shell to get the list of available databases. To achieve this purpose, use the following syntax:

\l;

Step 1: Launch SQL Shell

In order to run the “\l” command, firstly, you need to log into SQL Shell. To do so, launch the SQL Shell(psql) from the Windows start menu:

img

Clicking on the “open” will show the following interface:

img

Fill in all the necessary details and hit the “ENTER” button. Consequently, the following window will appear:

img

Here, “postgres” shows that you are connected to the default database.

Step 2: Show Databases Using \l Command

Once you are connected to the default database, execute the below-given statement to show the list of available databases:

\l;
img

The output authenticates the working of the “\l” command as it shows the list of available databases. Use the “\l+” command to get the list of available databases with more details such as size, tablespace, description, etc.

Step 3: Show Databases Using SELECT Query

In PostgreSQL, the pg_databses catalog holds all the details regarding databases. So, you can run the SELECT query in PostgreSQL to show the list of available databases in pg_databases:

SELECT datname FROM pg_database;
img

This way, you can use the SELECT query to fetch the list of available databases in Postgres.

How to Show Databases in Postgres Using pgAdmin?

Follow the below-listed stepwise instructions to get the list of available databases in Postgres via pgAdmin.

Step 1: Launch pgAdmin

Open the pgAmin 4 from the Windows start menu:

img

Clicking on the “open” will lead you to the following interface:

img

Provide the password and hit the “OK” button to log into the pgAdmin.

Step 2: Show Databases Using Database Tree

Expand the “Servers” tree located in the top left corner of the pgAdmin:

img

Click on “Databases” to see the list of databases:

img

Now select the properties tab to see detailed information about each database:

img

The above snippet shows detailed information about each database.

Conclusion

In PostgreSQL, the “\l” statement and “pg_databases” catalog are used to show the list of databases. The “\l+” command is used to get the list of available databases with more details such as size, tablespace, description, etc. Use the “\l” or “\l+” commands and the “pg_databases” catalog from the SQL Shell to get the list of available databases. While to show the list of databases using pgAdmin, click on the “Servers”, expand the “Databases” Tree, and then click on the “properties” tab. This write-up explained various methods to show databases in Postgres.