Display all databases in the current PostgreSQL cluster using psql meta-commands or SQL.
Open psql
and type \l
or \list
. PostgreSQL immediately shows every database, its owner, encoding, collate/cctype, and access privileges.
\l+
variant help?Add +
for extra columns such as database size and tablespace. Use it when you need storage insight before allocating more space.
Yes. Append a pattern: \l sales*
lists only databases whose names start with sales
. Wildcards follow standard LIKE
semantics.
psql
?Run a SQL query from any client: SELECT datname FROM pg_database WHERE datistemplate = false;
. Skip template databases to avoid noise.
psql
shows every cluster database by default. Use a SQL WHERE clause or pattern filter to hide template0
and template1
.
Combine \l+
with \pset format aligned
for a readable size column, or query pg_database_size(datname)
in SQL.
Create a read-only role that can connect to the cluster but not modify data. Grant it CONNECT
on required databases before listing.
--tuples-only
Automate audits by invoking psql -Atc "\l"
. The -A
flag removes alignment, and -t
strips headers for easy parsing.
Excessive databases can slow pg_dumpall
. Schedule a nightly job that logs SELECT count(*) FROM pg_database WHERE datistemplate = false;
.
Use psql -Atc "\\l" postgres
. The flags produce unaligned, header-free output, ideal for scripts.
Yes—owner appears in the \l
output. In SQL, query datname, pg_catalog.pg_get_userbyid(datdba)
from pg_database
.
Run SELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database WHERE datistemplate = false AND pg_database_size(datname) > 1073741824;
.