Re: [NOVICE] Why psql connection assumes default database name as the username - Mailing list pgsql-novice

From Neha Khatri
Subject Re: [NOVICE] Why psql connection assumes default database name as the username
Date
Msg-id CAFO0U+969nKGCOw235V-=Hb6Ss6OyM5brJv8OipM0uQcnGoh5w@mail.gmail.com
Whole thread Raw
In response to Re: [NOVICE] Why psql connection assumes default database name asthe username  (hubert depesz lubaczewski <depesz@depesz.com>)
Responses Re: [NOVICE] Why psql connection assumes default database name as the username
Re: [NOVICE] Why psql connection assumes default database name asthe username
List 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


pgsql-novice by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: [NOVICE] Why psql connection assumes default database name asthe username
Next
From: "David G. Johnston"
Date:
Subject: Re: [NOVICE] Why psql connection assumes default database name as the username