Re: Why psql connection assumes default database name as the username

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Neha Khatri <nehakhatri5(at)gmail(dot)com>
Cc: jesusthefrog <jesusthefrog(at)gmail(dot)com>, Hubert Lubaczewski <depesz(at)depesz(dot)com>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Why psql connection assumes default database name as the username
Date: 2017-03-28 01:17:01
Message-ID: CAKFQuwZL-sahuhrL2cGtZfUHMOKj8cdND8KBrMW9xE5LUJ56OQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Mar 27, 2017 at 5:58 PM, Neha Khatri <nehakhatri5(at)gmail(dot)com> wrote:

> Can a similar definition be applied in PostgreSQL for User and Database
> name mapping, i.e if a database name is same as a user name then the
> access privileges for that datbase are guided by the properties defined for
> that user in view pg_roles?
>

​Nowhere in "pg_roles" does the name of a specific database appear - so no.

You defines roles. You define databases. You give roles CONNECT
permissions on databases if you want them to be allowed to connect to said
databases. Of course, superusers can connect to anything. That is, along
as pg_hba.conf allows them to attempt a connection in the first place.

What I said above is wrong, though, if one leaves the default permissions
of the implicit PUBLIC group in place. By default all users are allowed to
CONNECT to any database in the cluster - among other permissions.

So while creating a database of the same name of as a user "just works" it
is working because of a default that can be changed. The fact that the
names match doesn't enter into it.

https://www.postgresql.org/docs/current/static/sql-grant.html
https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

David J.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Neha Khatri 2017-03-28 03:28:13 Re: Why psql connection assumes default database name as the username
Previous Message Neha Khatri 2017-03-28 00:58:45 Re: Why psql connection assumes default database name as the username