In PostgreSQL is it possible to generate a list of all databases and all schema with a single psql command?
To be concrete, let me provide an example.
I have two databases in a PotgreSQL database cluster: accounts
and people
. In the accounts
database there are these schema (beyond the default): hr
and finance
. In the people
database there are these schema (beyond the default): hr
, admin
, backup
.
Is there a single psql command I can run that generates results something like this:
database | schema
-----------------
accounts | hr
accounts | finance
people | hr
people | admin
people | backup
Or is the only way to generate this information to connect multiple times and run separate queries?
Best Answer
No. The list of schemas of a database is private to that database and cannot be obtained without being connected to it. The list of databases is available with
\l
orselect * from pg_database
.