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

From: Neha Khatri <nehakhatri5(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(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 03:28:13
Message-ID: CAFO0U+9y_c+ByM8DbRgX5Jw2PXxGCsMfWFHNsiHaFxDcpmSJvg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, Mar 28, 2017 at 12:17 PM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Mon, Mar 27, 2017 at 5:58 PM, Neha Khatri
>
>> 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 database 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.
>
> 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.
>

Right, the database does not appear in pg_roles. So having a database name
same as a user in pg_roles, does not have anything to do with guiding the
access privilege for the database.

It seems that for convenience, the OS username and the DB name
correspondence could be in place.
Many other PostgreSQL utilities like createdb, clusterdb, vacuumdb,
reindexdb, pg_dump assume the dbname same as username, in case it is
neither explicitly specified as an option nor it is set in the environment
variable PGDATABASE.

Regards,
Neha

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message anand086 2017-03-28 06:10:31 How does backend server know which data file and page to read?
Previous Message David G. Johnston 2017-03-28 01:17:01 Re: Why psql connection assumes default database name as the username