0

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.

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I am trying to do it for the current user without filtering by rolname column as it is implemented in MS SQL HAS_PERMS_BY_NAME. Do you know how to do it better than below? I can do it something like that: select rolcreatedb from pg_catalog.pg_roles where rolname in (select current_user)
Then use where rolname = current_user in the first query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.