Join my Laravel for REST API's course on Udemy 👀

List databases in PostgreSQL

April 11, 2021  ‐ 1 min read

To list the databases in Postgres we are going to use the interactive terminal. To do so you might need to switch to the Postgres user with sudo su postgres. You can enter the Postgres terminal with the psql command.

$ psql
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1))
Type "help" for help.

postgres=#

Now that we are in the shell we can use one of Postgres meta-commands to list the databases. The one we need in this case is \l, which is short for \list.

postgres=# \l
                                       List of databases
     Name     |  Owner   | Encoding |   Collate   |    Ctype    |       Access privileges
--------------+----------+----------+-------------+-------------+-------------------------------
 myproject    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 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
(4 rows)