Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jArRV-0003WM-8O for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2020 08:37:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jArRS-0005ch-C4 for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2020 08:37:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jArRR-0005ca-RY for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2020 08:37:46 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jArRL-00059I-1v for pgsql-general@postgresql.org; Sun, 08 Mar 2020 08:37:44 +0000 Received: by mail-wr1-x444.google.com with SMTP id r7so7303827wro.2 for ; Sun, 08 Mar 2020 00:37:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=AAYzd8GComT8evED997Ojcc4QDZrZLMwTB0trKOVmIM=; b=Lo2m0MNYtNKHA63+/y4N+K534y4vk/nQdL8RGiN/E/if4H0ucEGAQ8C22n/Qwl68Dr ayYOZWoR8xXrZShdBif7yU78NX6sb4Q8oawhFKEqNJD0sgtvnUpADfamrzm2so1s7E2n HQ91DvhdZWRl22465+4eridsyZ7SjgjHDtMgKwEirl6fHCEzbY0EHqBYrOmRRgyUc9qp TJi/MQe7ruhsCV3TjmQW2yR9fFZ3Hp+Wx/wdp4OjvZRrlGh+9BiYyrLJBrHdxWdx968v EvS6AMvpqznuFj9twpo39zD4Qp+5MIIVWI8dDPiAAq01m09gM6YkcyG7pLNDeTx9bgfp 2cOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=AAYzd8GComT8evED997Ojcc4QDZrZLMwTB0trKOVmIM=; b=Y1xfzr54KY2yMP2YAJv56bTm4sLcEqg65DSAdsMIPJAUUMWJqr3podbyqv7PurYPjO sKv0js2LfitBWryVSpRvJR2CxCP7ENL6i0mBb7zV+SsNJSDmsJLYSfs182LbC+Okrjzj RId8WVR9PbD9Yzh3KXD8xERNkaYMVDWLBYGLIkysnUykv5lcEdDJGHjwPPaukdVdCsU+ GMqslqNSMvIorclXlUKpxt61Fo16jGc/bewa2u6yRzjq56JnOIYn6sl4Lcp5yia3SZSI xDGbLxEBUqSyEKcIVTdxyGklnDaE1CVpdfPivqbH73nyKsAEc0fjNr9JFRDzhj8nJpb1 v41Q== X-Gm-Message-State: ANhLgQ1mBp5PBjpLy1HxLy3f3o9Eu65NQEy6ibGmHxbTWlXcCV04j40I 46qxzsq58C9omfF5icfPVNNmw2eY X-Google-Smtp-Source: ADFU+vsdJdJuGxCAbWHVyIyHDPONDa457sc3yR4eO6TGBOUiGrpxUgZVidoUxInjp8Qi4OrbVjHxtQ== X-Received: by 2002:adf:f047:: with SMTP id t7mr14983355wro.371.1583656656431; Sun, 08 Mar 2020 00:37:36 -0800 (PST) Received: from [192.168.1.8] (241-57-239-77.dyn.cable.fcom.ch. [77.239.57.241]) by smtp.gmail.com with ESMTPSA id b12sm29170040wro.66.2020.03.08.00.37.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Mar 2020 00:37:35 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: Restrict user to create only one db with a specific name From: =?utf-8?Q?Paul_F=C3=B6rster?= In-Reply-To: Date: Sun, 8 Mar 2020 09:37:35 +0100 Cc: Forums postgresql Content-Transfer-Encoding: quoted-printable Message-Id: <46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com> References: <395AEEFA-8532-48E1-B1AA-8155DB162349@gmail.com> To: Tiffany Thang X-Mailer: Apple Mail (2.3608.60.0.2.5) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Tiff, note that there is an absurd high maximum of databases possible inside a = PostgreSQL database cluster. I think, the maximum is 4,294,950,911 but = I'm sure you don't get that many users or databases anyway. ;-) Cheers, Paul > On 07. Mar, 2020, at 23:35, Tiffany Thang = wrote: >=20 > Thanks David and Paul. Because each user wants the ability to drop and = recreate their own databases, I want to impose a restriction on the = database names. I=E2=80=99ll just implement what Paul has suggested. >=20 > Thanks. >=20 > Tiff=20 >=20 > On Sat, Mar 7, 2020 at 2:35 AM Paul F=C3=B6rster = wrote: > Hi Tiff, >=20 > from what you say, it sounds that each user should have his or her own = database. >=20 > Considering the other answers here already pointing out the = difficulties, why don't you just create a database for each user with = the same name as the username and grant him or her access to it. >=20 > So, basically like this: >=20 > postgres=3D# create role "userA" login; > CREATE ROLE > postgres=3D# create database "userA" owner "userA"; > CREATE DATABASE > postgres=3D# create role "userB" login; > CREATE ROLE > postgres=3D# create database "userB" owner "userB"; > CREATE DATABASE >=20 > When, say, "userB" goes away, his or her data will go the way all = things do: >=20 > drop database "userB"; > drop role "userB"; >=20 > Or did I misunderstand you? >=20 > Cheers, > Paul >=20 >=20 > > On 07. Mar, 2020, at 00:28, Tiffany Thang = wrote: > >=20 > > Hi, > > Is there a way in PostgreSQL 12 to restrict user to creating a = database with a specific database name? > >=20 > > For example, userA can only create a database with a name called = mydb. Any other names would generate an error.=20 > >=20 > > If that is not possible, will it be possible then to limit userA to = creating only one database? Granting the createdb privilege would allow = the user to create any number of databases which I want to avoid. > >=20 > > Thanks. > >=20 > > Tiff >=20