public inbox for [email protected]  
help / color / mirror / Atom feed
From: Muhammad Usman Khan <[email protected]>
To: somnath som <[email protected]>
Cc: Pgsql-admin <[email protected]>
Subject: Re: User Privileges Issue
Date: Fri, 30 Aug 2024 16:44:57 +0500
Message-ID: <CAPnRvGv4fzFYwpoObd5k=4RZYEJuys7DKaHiwXGXS8UMJuKmtg@mail.gmail.com> (raw)
In-Reply-To: <CABGa5dGsbneuEz6sVtSMSaWK3Mt1hRYiBWLVeb1DYikXSS313A@mail.gmail.com>
References: <CABGa5dGsbneuEz6sVtSMSaWK3Mt1hRYiBWLVeb1DYikXSS313A@mail.gmail.com>

Hi,
You can use the following queries to check privileges. I have tested with
my created user 'user01'

*Check Role Attributes  *
postgres=# SELECT rolname, rolsuper, rolinherit, rolcreaterole,
rolcreatedb, rolcanlogin, rolreplication
postgres-# FROM pg_roles
postgres-# WHERE rolname = 'user01';
 rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb |
rolcanlogin | rolreplication
---------+----------+------------+---------------+-------------+-------------+----------------
 user01  | f        | t          | f             | f           | t
  | f
(1 row)

*Check Database Privileges:*
postgres=# SELECT datname,
postgres-#        has_database_privilege('user01', datname, 'CONNECT') AS
connect,
postgres-#        has_database_privilege('user01', datname, 'CREATE') AS
create,
postgres-#        has_database_privilege('user01', datname, 'TEMP') AS temp
postgres-# FROM pg_database;
  datname  | connect | create | temp
-----------+---------+--------+------
 postgres  | t       | f      | t
 agens     | t       | f      | t
 template1 | t       | f      | f
 template0 | t       | f      | f
(4 rows)

*Check Schema Privileges:*
postgres=# SELECT nspname,
postgres-#        has_schema_privilege('user01', nspname, 'CREATE') AS
create,
postgres-#        has_schema_privilege('user01', nspname, 'USAGE') AS usage
postgres-# FROM pg_namespace;
      nspname       | create | usage
--------------------+--------+-------
 pg_toast           | f      | f
 pg_temp_1          | f      | f
 pg_toast_temp_1    | f      | f
 pg_catalog         | f      | t
 public             | t      | t
 information_schema | f      | t
(6 rows)


On Fri, 30 Aug 2024 at 16:38, somnath som <[email protected]> wrote:

> We have one user like “Test_User”, Can I check what all previliges are
> there for “Test_User”.
>
> When running \du+ command then only can see for superuser, others user are
> not showing.
>
> Please provide me command to check what all previliges are there for a
> user.
>


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: User Privileges Issue
  In-Reply-To: <CAPnRvGv4fzFYwpoObd5k=4RZYEJuys7DKaHiwXGXS8UMJuKmtg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox