The Wayback Machine - https://web.archive.org/web/20240624023100/https://www.geeksforgeeks.org/postgresql-show-databases/
Open In App

PostgreSQL – Show Databases

Last Updated : 28 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:


Previous Article
Next Article

Similar Reads

PostgreSQL - Show Tables
PostgreSQL does not support the SHOW TABLES statement directly like MySQL does but provides users with an alternative. In this article, we will explore them in detail. Using Psql Shell: One way to list all the tables in a database is to use the below command after logging into the database: Syntax: \dt Example: In this example, we will query for th
1 min read
Show All Rows with an Above-Average Value in PostgreSQL
PostgreSQL is a robust relational database management system that offers powerful features for data analysis. One common task in data analysis is identifying rows with values above the average of a specific column. In this article, we will explore how to Show All Rows with an Above-Average Value in PostgreSQL by understanding the multiple approache
3 min read
PostgreSQL - Connect To PostgreSQL Database Server in Python
The psycopg database adapter is used to connect with PostgreSQL database server through python. Installing psycopg: First, use the following command line from the terminal: pip install psycopg If you have downloaded the source package into your computer, you can use the setup.py as follows: python setup.py build sudo python setup.py installCreate a
4 min read
PostgreSQL - Export PostgreSQL Table to CSV file
In this article we will discuss the process of exporting a PostgreSQL Table to a CSV file. Here we will see how to export on the server and also on the client machine. For Server-Side Export: Use the below syntax to copy a PostgreSQL table from the server itself: Syntax: COPY Table_Name TO 'Path/filename.csv' CSV HEADER; Note: If you have permissio
2 min read
PostgreSQL - Installing PostgreSQL Without Admin Rights on Windows
If you are a part of a corporation, it is highly unlikely that you have the admin privileges to install any external software. But the curious souls that all software developers are, in this article, we will see the detailed process of installation of PostgreSQL without having administrator rights on our Windows machine. Installation: Follow the be
3 min read
PostgreSQL - Creating Updatable Views Using WITH CHECK OPTION Clause
PostgreSQL is the most advanced general purpose open source database in the world. pgAdmin is the most popular management tool or development platform for PostgreSQL. It is also an open source development platform. It can be used in any Operating Systems and can be run either as a desktop application or as a web in your browser. In this article, we
4 min read
What is PostgreSQL - Introduction
This is an introductory article for the PostgreSQL database management system. In this we will look into the features of PostgreSQL and why it stands out among other relational database management systems. Brief History of PostgreSQL: PostgreSQL also known as Postgres, was developed by Michael Stonebraker of the University of California, Berkley. I
2 min read
Install PostgreSQL on Windows
This is a step-by-step guide to install PostgreSQL on a windows machine. Since PostgreSQL version 8.0, a window installer is available to make the installation process fairly easier. We will be installing PostgreSQL version 11.3 on Windows 10 in this article. There are three crucial steps for the installation of PostgreSQL as follows: Download Post
2 min read
Install PostgreSQL on Mac
This is a step-by-step guide to install PostgreSQL on a Mac OS machine. We will be installing PostgreSQL version 11.3 on Mac using the installer provided by EnterpriseDB in this article. There are three crucial steps for the installation of PostgreSQL as follows: Download PostgreSQL EnterpriseDB installer for MacInstall PostgreSQLVerify the install
2 min read
PostgreSQL - Loading a Database
In this article we will look into the process of loading a PostgreSQL database into the PostgreSQL database server. Before moving forward we just need to make sure of two things: PostgreSQL database server is installed on your system. A sample database. For the purpose of this article, we will be using a sample database which is DVD rental database
3 min read