Search code examples
postgresqlinformation-schema

Minimum PostgreSQL requirement to view all databases?


Long time MariaDB/MySQL DBA, two weeks into being a Postgres DBA and I'm stumped...

I am creating a script that scans a host and ennumerates the databases but I'm having difficulty nailing down the least-privilege Postgres permissions. The script works fine when testing with SUPERUSER, but I'm not sure what permissions beyond USAGE it needs. It seems that any combination I come up with isn't working.


Solution

  • All you need to get a list of databases in a PostgreSQL cluster is a database user that can connect to one of the databases. Then you can run the SQL statement

    SELECT datname
    FROM pg_database
    WHERE datallowconn;