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

From: Neha Khatri <nehakhatri5(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Why psql connection assumes default database name as the username
Date: 2017-03-23 21:49:11
Message-ID: CAFO0U+969nKGCOw235V-=Hb6Ss6OyM5brJv8OipM0uQcnGoh5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>
> > For psql connection, the default database name is assumed to be operating
> > system user name. Is it a common practice to have a database name same as
> > an OS username. Or would the applications create a database with the OS
> > username as some default procedure?
>
> psql (or specifically libpq) makes two assumptions:
> 1. if username is not given - use operating system user name
> 2. if database name is not given - use username as db name.
>
> So, if you don't have anything set in environment, and you're logged in
> a neha, then:
>
> $ psql
> will try to connect to db neha with user neha
>
> $ psql -U depesz
> will try to connect to db depesz with user depesz
>

I had the question specific to above two cases, when the database name is
not provided. There is no surety of having a database name same as the user
name. Then why assume the database name and try to connect to it. Is it due
to legacy reason or due to some common database naming practice?

> In my specific case the problem is just that the database 'pgadmin' is not
> > there, then why should it be a FATAL error. I understand that any process
> > aborting errors are treated FATAL. But it looks like a simple error here.
>
> Levels or errors are clearly defined:
> 1. ERROR means that something was wrong, but you can still continue to
> work in the db connection
> 2. FATAL means that something wrong happened, and you can't use the
> connection any more as it has closed.
>
> Since failing to open db connection prohibits you from doing any more
> work in the db connection (which is not there) - it's clearly FATAL and
> not ERROR.

In this case the database does not exist, then connecting to a non existent
database does not seem a FATAL issue. May if connection to an existent
database fails, it definitely would be a FATAL issue. Though I understand
that this thought is not in line with the protocol defined for error
severity. Still does not appear to be a FATAL issue.

Regards,
Neha

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David G. Johnston 2017-03-23 22:16:22 Re: Why psql connection assumes default database name as the username
Previous Message hubert depesz lubaczewski 2017-03-23 13:12:32 Re: Why psql connection assumes default database name as the username