pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Förster <paul.foerster@gmail.com>
To: Tiffany Thang <tiffanythang@gmail.com>
Cc: Forums postgresql <pgsql-general@postgresql.org>
Subject: Re: Restrict user to create only one db with a specific name
Date: Sun, 8 Mar 2020 09:37:35 +0100
Message-ID: <46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com> (raw)
In-Reply-To: <CAB_W-NN+KvmLMesNT=MYHJMThsmTVg9rrzf6BwE3yyt8Y5XDLA@mail.gmail.com>
References: <CAB_W-NNf3RUDHOMPOvYhyTTdrbYE5pEQp72f9GZLJSB13f--7Q@mail.gmail.com>
	<395AEEFA-8532-48E1-B1AA-8155DB162349@gmail.com>
	<CAB_W-NN+KvmLMesNT=MYHJMThsmTVg9rrzf6BwE3yyt8Y5XDLA@mail.gmail.com>

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 <tiffanythang@gmail.com> wrote:
> 
> 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’ll just implement what Paul has suggested.
> 
> Thanks.
> 
> Tiff 
> 
> On Sat, Mar 7, 2020 at 2:35 AM Paul Förster <paul.foerster@gmail.com> wrote:
> Hi Tiff,
> 
> from what you say, it sounds that each user should have his or her own database.
> 
> 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.
> 
> So, basically like this:
> 
> postgres=# create role "userA" login;
> CREATE ROLE
> postgres=# create database "userA" owner "userA";
> CREATE DATABASE
> postgres=# create role "userB" login;
> CREATE ROLE
> postgres=# create database "userB" owner "userB";
> CREATE DATABASE
> 
> When, say, "userB" goes away, his or her data will go the way all things do:
> 
> drop database "userB";
> drop role "userB";
> 
> Or did I misunderstand you?
> 
> Cheers,
> Paul
> 
> 
> > On 07. Mar, 2020, at 00:28, Tiffany Thang <tiffanythang@gmail.com> wrote:
> > 
> > Hi,
> > Is there a way in PostgreSQL 12 to restrict user to creating a database with a specific database name?
> > 
> > For example, userA can only create a database with a name called mydb. Any other names would generate an error. 
> > 
> > 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.
> > 
> > Thanks.
> > 
> > Tiff
> 






view thread (7+ messages)  latest in thread

Message-ID: <46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com>
Permalink:  ../46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com/
Also on:    postgresql.org/message-id/46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: paul.foerster@gmail.com, tiffanythang@gmail.com
  Subject: Re: Restrict user to create only one db with a specific name
  In-Reply-To: <46FDE202-6795-42F4-929C-F950FFB9669A@gmail.com>
  References: <CAB_W-NNf3RUDHOMPOvYhyTTdrbYE5pEQp72f9GZLJSB13f--7Q@mail.gmail.com> <395AEEFA-8532-48E1-B1AA-8155DB162349@gmail.com> <CAB_W-NN+KvmLMesNT=MYHJMThsmTVg9rrzf6BwE3yyt8Y5XDLA@mail.gmail.com> <46FDE202-6795-42F4-929C-F950FFB9669A@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox