PostgreSQL DB - List all Databases
To list out all the existing databases in PostgreSQL:
1. Execute the SQL query from the system Catalog.
SELECT datname FROM pg_database;
2. The psql program's \l meta-command and -l command-line option are also useful for listing the existing databases.
- \l or \list - Lists all databases, their owners, and character encodings in the psql interface.
- \l+ or \list+ - Provides more detailed information, including database size and default tablespace.
- -l command-line option are also useful for listing the existing databases. (Ex: $ psql -l )
3. \c or \conninfo - displays the currently connected database.