You must understand that in PostgreSQL users are per database cluster. @Michael already demonstrates how to get a list of those.
So, unless you restrict permissions for a particular databases explicitly with REVOKE
and GRANT
, all users in the cluster have basic access to any database in the cluster.
To determine, whether a specific user actually has a certain privilege ('CONNECT') for a database:
has_database_privilege(user, database, privilege)
More about privilege functions in the manual.
To determine all specific privileges for a specific database:
SELECT datname, datacl
FROM pg_database
WHERE datname = 'mydb';
You get NULL
for datacl
if no specific restrictions apply.
In addition to that you can restrict access per database and per user in the pg_hba.conf
file. That's on a lower level. The user cannot even connect, if pg_hba.conf
won't let him, even if the database itself would allow access.