Re: AW: Connect to db denied for superuser inherited by group

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael(dot)Dietrich(at)swisscom(dot)com
Cc: sfrost(at)snowman(dot)net, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: AW: Connect to db denied for superuser inherited by group
Date: 2018-03-20 14:11:41
Message-ID: 10823.1521555101@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

<Michael(dot)Dietrich(at)swisscom(dot)com> writes:
> What I've done
> CREATE ROLE superrole WITH NOLOGIN SUPERUSER ..;
> CREATE USER nosuperuser WITH LOGIN NOSUPERUSER INHERIT ..;
> GRANT superrole TO nosuperuser WITH ADMIN OPTION;
> REVOKE CONNECT ON DATABASE nonpublicdb FROM public ;

> psql -d postgres -U nosupuser

> postgres=# set role superrole;

> postgres=# \c nonpublicdb
> FATAL: permission denied for database " nonpublicdb "
> DETAIL: User does not have CONNECT privilege.

> I expect that the connection to the database is allowed since a role
> with superuser is used.

You're misunderstanding what psql's \c command does. In this form,
it attempts a connection with the new database name, but the same
username as the previous connection, ie nosupuser. It doesn't know
anything about SET ROLE commands you may have issued to the server
while connected.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ron Watkins 2018-03-20 16:50:24 Newbie question
Previous Message Samed YILDIRIM 2018-03-20 11:13:32 Re: Standard tools for multimaster cluster