Re: Restrict user to create only one db with a specific name

Поиск
Список
Период
Сортировка
От Tiffany Thang
Тема Re: Restrict user to create only one db with a specific name
Дата
Msg-id CAB_W-NN+KvmLMesNT=MYHJMThsmTVg9rrzf6BwE3yyt8Y5XDLA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Restrict user to create only one db with a specific name  (Paul Förster <paul.foerster@gmail.com>)
Ответы Re: Restrict user to create only one db with a specific name
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Ron
Дата:
Сообщение: Re: duplicate key value violates unique constraint
Следующее
От: Paul Förster
Дата:
Сообщение: Re: Restrict user to create only one db with a specific name