fbpx

PostgreSQL List Databases

To list all databases in Postgres, you can use the \l command. This will display a list of all databases on the current Postgres server, along with some additional information for each database, such as its owner and encoding.

Alternatively, you can use the \list or \l+ command to show a more detailed view of the databases, including their sizes and tablespaces.

Keep in mind that in order to use these commands, you must be connected to the Postgres server using a client such as psql. You can then enter the \l command at the psql prompt to list the databases.

Here is an example of how this might look:​

				
					$ psql
psql (12.1)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)


				
			

In this example, we are connected to the PostgreSQL server and have used the \l command to list the databases. As you can see, the output includes the name of each database, along with its owner, encoding, and access privileges.

Share:

Facebook
Twitter
Pinterest
LinkedIn

Social Media

Most Popular

Get The Latest Updates

Subscribe To Our Weekly Newsletter

No spam, notifications only about new products, updates.

Categories