How to get list of databases in PostgreSQL

We can get the list of databases in PostgreSQL by using the met-command \l or by querying on catalog table ‘pg_database’. There is no show databases in PostgreSQL(psql)

Get the list of databases by using the meta-command \l:

postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+---------------------- - lonprod1 | 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

How to get list of databases in PostgreSQL
How to get list of databases in PostgreSQL

Get the list of databases by using the catalog table pg_database:

postgres=# select datname from pg_database; datname ----------- postgres lonprod1 template1 template0 (4 rows)