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

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Neha Khatri <nehakhatri5(at)gmail(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 13:12:32
Message-ID: 20170323131232.GC16353@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, Mar 23, 2017 at 03:57:58PM +1100, Neha Khatri wrote:
> 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?

it's not that database name is assume to be operating system user name.

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

$ psql -d xxx
will try to connect to db xxx with user nega

$ psql -U depesz -d xxx
will try to connect to db xxx with user depesz

> 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.

depesz

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Neha Khatri 2017-03-23 21:49:11 Re: Why psql connection assumes default database name as the username
Previous Message Neha Khatri 2017-03-23 04:57:58 Why psql connection assumes default database name as the username