I would like to check the perm in PostgreSQL db as well as I do it via this command
'SELECT HAS_PERMS_BY_NAME(NULL, 'DATABASE', 'CREATE DATABASE')
' for the SQL server.
What is the best way to do the same in PostgreSQL? I didn`t find the similar function in PostgreSQL...
CodePudding user response:
The privilege to create a new database is stored in pg_roles
To check if a specific user can create a new database:
select rolcreatedb
from pg_catalog.pg_roles
where rolname = current_user; --<< or replace with a specific user name
If you want to see all roles that are allowed to create a new database
select rolname
from pg_catalog.pg_roles
where rolcreatedb;