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 1pZBQI-0007TG-VE for pgsql-general@arkaria.postgresql.org; Mon, 06 Mar 2023 14:02:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZBQH-0002n8-N4 for pgsql-general@arkaria.postgresql.org; Mon, 06 Mar 2023 14:02:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZBQH-0002mz-By for pgsql-general@lists.postgresql.org; Mon, 06 Mar 2023 14:02:41 +0000 Received: from mout-u-107.mailbox.org ([2001:67c:2050:101:465::107]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZBQA-0000kw-VY for pgsql-general@lists.postgresql.org; Mon, 06 Mar 2023 14:02:40 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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-107.mailbox.org (Postfix) with ESMTPS id 4PVgJ60ng1z9sSK; Mon, 6 Mar 2023 15:02:30 +0100 (CET) Date: Mon, 6 Mar 2023 15:02:29 +0100 (CET) From: Erik Wienhold To: Dominique Devienne , pgsql-general@lists.postgresql.org Message-ID: <1316927941.360065.1678111349572@office.mailbox.org> In-Reply-To: References: Subject: Re: CREATE/DROP ROLE transactional? GRANT/REVOKE? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Rspamd-Queue-Id: 4PVgJ60ng1z9sSK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 06/03/2023 14:19 CET Dominique Devienne wrote: > > Perhaps I missed it in the doc (e.g. [1]), but are DDLs around ROLEs and > GRANTs transactional? Have you tried? DDL is transactional unless stated otherwise (cf. CREATE DATABASE, CREATE INDEX CONCURRENTLY, CREATE TABLESPACE). Run the following psql script: drop role if exists alice, bob; \du begin; create role alice; \du rollback; \du begin; create role alice; create role bob; commit; \du begin; grant alice to bob; \du rollback; \du begin; drop role alice; \du rollback; \du Output: DROP ROLE List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} BEGIN CREATE ROLE List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- alice | Cannot login | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} ROLLBACK List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} BEGIN CREATE ROLE CREATE ROLE COMMIT List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- alice | Cannot login | {} bob | Cannot login | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} BEGIN GRANT ROLE List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- alice | Cannot login | {} bob | Cannot login | {alice} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} ROLLBACK List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- alice | Cannot login | {} bob | Cannot login | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} BEGIN DROP ROLE List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- bob | Cannot login | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} ROLLBACK List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- alice | Cannot login | {} bob | Cannot login | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} > Since I'm creating many ROLEs and making many GRANTs, based info I read from > PostgreSQL itself (in pg_catalog and elsewhere), should everything be in a > single transaction? If it should be atomic and the commands are allowed in transactions, then yes, use transactions. -- Erik