Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgU4E-00Fz1l-G1 for pgsql-novice@arkaria.postgresql.org; Wed, 13 Sep 2023 17:54:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qgU4D-001HC2-6B for pgsql-novice@arkaria.postgresql.org; Wed, 13 Sep 2023 17:54:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgU4C-001HBi-D1 for pgsql-novice@lists.postgresql.org; Wed, 13 Sep 2023 17:54:20 +0000 Received: from mx0.riseup.net ([198.252.153.6]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgU48-004N6R-Hu for pgsql-novice@lists.postgresql.org; Wed, 13 Sep 2023 17:54:18 +0000 Received: from fews01-sea.riseup.net (fews01-sea-pn.riseup.net [10.0.1.109]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx0.riseup.net (Postfix) with ESMTPS id 4Rm7PL36t4z9tB5 for ; Wed, 13 Sep 2023 17:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1694627654; bh=UAaWSuBSXyFMvrDB2ynpv2hSKgD5qRlqTlahygK7VOo=; h=Date:From:To:Subject:In-Reply-To:References:From; b=FwM+OrAS4S2UU0wECHnWludT8DcLfYAWdBX+L2njPaZCGLZgf+9xcoNwX4V8eYVEl 9QB6/46IVSh3+Oq7/zsLCfr4Xu98OyO13ON8fEEO/DsmSV9dqC/H4MPdMDXrHYQuh/ IEkZULqjLA+R4KtndNSoVnB3DuL0Da43dsdk1M7k= X-Riseup-User-ID: 6097E2A76FFD321C5A40D851E09F5F4AA714FE38AB5C3EFB8CD09194D2BA8084 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews01-sea.riseup.net (Postfix) with ESMTPSA id 4Rm7PL277KzJnDN for ; Wed, 13 Sep 2023 17:54:14 +0000 (UTC) MIME-Version: 1.0 Date: Wed, 13 Sep 2023 17:54:13 +0000 From: ivanov17@riseup.net To: Pgsql Novice Subject: Re: Grant CREATE privilege on all schemas In-Reply-To: <72494a1f44ffee61199cabd104a278d4ff30c4e1.camel@cybertec.at> References: <42a7db124fa2f9685f01c0a80161549c@riseup.net> <72494a1f44ffee61199cabd104a278d4ff30c4e1.camel@cybertec.at> Message-ID: Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-09-12 17:59, Laurenz Albe wrote: > The owner of the tables must be the user that creates them, that is your > migration role. > > If the database and the schemas are owned by a different user, that does > not matter, as long as the migration user has CREATE on all schemas. > > You could use ALTER DEFAULT PRIVILEGES to make sure that every schema > created by the database owner has that required permission by default. > > While that should work fine, I deem it more complicated than necessary. > I would opt for the migration user being the same as the database owner. > > Yours, > Laurenz Albe Thank you. I use different Ansible roles to configure CI and web servers, so it's easier for me to create different database roles for different purposes. But you're right: this results in the need to assign many additional privileges because objects in schemas are not owned by schema owners. It works, but doesn't look very good. I think I have found the final solution, and it even looks elegant. GRANT web1 TO migration; GRANT web2 TO migration; ALTER ROLE migration IN DATABASE web1 SET role TO web1; ALTER ROLE migration IN DATABASE web2 SET role TO web2; Now when I connect to the database as the migration role, all operations are performed by the database owner role, so all created objects in the schema owned by the database owner. And no confusion with privileges. -- With appreciation, Ivanov