Sobes.tech
Junior — Middle

How can you get a list of databases in PostgreSQL via command line?

sobes.tech AI

Answer from AI

To get a list of databases in PostgreSQL via the command line, you can use the psql utility — an interactive client for working with PostgreSQL.

Command to connect to the server and display the list of databases:

psql -U username -h host -p port -l

Explanations:

  • -U — PostgreSQL username
  • -h — server address (e.g., localhost)
  • -p — port (default 5432)
  • -l (or --list) — display list of databases

If you are already connected to psql, you can simply execute:

\l

or

\list

This will display a table with all databases on the server.

How can you get a list of databases in PostgreSQL via… - sobes.tech