I want to know what are the privileges a given schema or user has in Postgres. Like whether it can create a table, view, function, sequences or not.
I found one query but it showed privileges on table only. Please suggest any appropriate query.
1 Answer 1
In PostgreSQL, the right to create tables, views, functions, operators, data types and the like is not properties of the user (or "role" in PostgreSQL).
You manage this with privileges on schemas: if there is a schema where the user has the CREATE
privilege, the user can create any object he or she wishes in that schema. If you want to keep a PostgreSQL user from creating objects, you don't give them CREATE
on any schema. Since the public
schema by default gives CREATE
to everybody, you'd have to
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
which is a good idea anyway for security reasons.
There are only few privileges that are tied to the user, because they pertain to global objects or no objects at all:
CREATEDB
: the right to runCREATE DATABASE
CREATEROLES
: the right to runCREATE ROLE
REPLICATION
: the right to establish a replication connection; that is for example needed forpg_basebackup
-
"* is not attached to the user*" - hmm, as you grant the
create
privilege on a schema to a user (or role), I would say it is (somehow) "tied" to a user (the grantee).user1822– user18222020年07月13日 07:00:29 +00:00Commented Jul 13, 2020 at 7:00 -
@a_horse_with_no_name I was thinking literally: the privileges are ACL settings on objects, not properties of the user. I'll try to pick a better way to say it.Laurenz Albe– Laurenz Albe2020年07月13日 07:12:30 +00:00Commented Jul 13, 2020 at 7:12
-
Yes , you guessed it correctly, I am a oracle user but now learning postgres as well . We are migrating the data from oracle to postgres . So faced some issue with grants after migrating oracle data to postgres . So, do we have any query or psql command for knowing that whether a user has rights to create a sequence or not ? Or in postgres there is no such grants for sequence exist .user236778– user2367782020年07月13日 12:12:44 +00:00Commented Jul 13, 2020 at 12:12
-
1That would be
\dn+
inpsql
. Then you see which of the schemas the user has theCREATE
permission on.Laurenz Albe– Laurenz Albe2020年07月13日 12:31:47 +00:00Commented Jul 13, 2020 at 12:31
psql
.