Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prilf-0003ZO-QZ for pgsql-admin@arkaria.postgresql.org; Wed, 26 Apr 2023 17:17:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1prild-0003iE-Es for pgsql-admin@arkaria.postgresql.org; Wed, 26 Apr 2023 17:17:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prild-0003i5-3h for pgsql-admin@lists.postgresql.org; Wed, 26 Apr 2023 17:17:21 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1prila-0021s8-Iq for pgsql-admin@lists.postgresql.org; Wed, 26 Apr 2023 17:17:19 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4Q65CD11Xkz9sW7; Wed, 26 Apr 2023 19:17:12 +0200 (CEST) Date: Wed, 26 Apr 2023 19:17:11 +0200 (CEST) From: Erik Wienhold To: richard coleman , pgsql-admin@lists.postgresql.org Message-ID: <2058602074.1048315.1682529431551@office.mailbox.org> In-Reply-To: References: Subject: Re: how to list privileges on the database object itself via SQL? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Rspamd-Queue-Id: 4Q65CD11Xkz9sW7 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 26/04/2023 18:34 CEST richard coleman wrote: > > This might sound like a silly question, but how would I list the privileges > the various roles have on the database objects themselves? > > There appear to be a million ways to list the privileges on various database > objects; tables, views, foreign tables, etc. but for the life of me there > doesn't appear to an analogous way to get permissions on the database objects > themselves. > > At the moment all that I've found is: > > select has_database_privilege('role','db_name', 'CREATE') as can_create; > select has_database_privilege('role','db_name', 'CONNECT') as can_connect; > select has_database_privilege('role','db_name', 'TEMP') as can_temp; > > Am I missing something? If you're interested in specific roles or privileges, then aclexplode is your friend. SELECT datname, grantor::regrole, grantee::regrole, privilege_type, is_grantable FROM pg_database, aclexplode(datacl) WHERE grantee = 'role'::regrole AND privilege_type IN ('CREATE', 'CONNECT', 'TEMPORARY'); -- Erik