When using psql with PostgreSQL, we can use the \list+
command to return information about all databases on the server.
We can also use the short form (\l+
) to achieve the same result.
Example
Here’s what I get when I run the command on my test server:
\l+
Result:
List of databases +-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------+ | Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description | +-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------+ | barney | barney | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8433 kB | pg_default | | | music | barney | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8225 kB | pg_default | | | pagila | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 16 MB | pg_default | | | pethotel | barney | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8169 kB | pg_default | | | postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8097 kB | pg_default | default administrative connection database | | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 7905 kB | pg_default | unmodifiable empty database | | | | | | | postgres=CTc/postgres | | | | | template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 7905 kB | pg_default | default template for new databases | | | | | | | postgres=CTc/postgres | | | | +-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------+
The command can also be run without the plus sign (+
), but this will exclude size information (and default tablespaces, and descriptions).
You can also append a database name in order to return information about a single database.
Example:
\l+ music
Result:
List of databases +-------+--------+----------+-------------+-------------+-------------------+---------+------------+-------------+ | Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description | +-------+--------+----------+-------------+-------------+-------------------+---------+------------+-------------+ | music | barney | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 8225 kB | pg_default | | +-------+--------+----------+-------------+-------------+-------------------+---------+------------+-------------+