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

From hubert depesz lubaczewski
Subject Re: [NOVICE] Why psql connection assumes default database name asthe username
Date
Msg-id 20170324085758.GA6674@depesz.com
Whole thread Raw
In response to Re: [NOVICE] Why psql connection assumes default database name as the username  (Neha Khatri <nehakhatri5@gmail.com>)
Responses Re: Why psql connection assumes default database name as the username
List pgsql-novice
On Fri, Mar 24, 2017 at 08:39:30AM +0000, Neha Khatri wrote:
> Yes, so psql should say "Not sure which database to connect to. Please
> specify a valid database name using -d option".
> For backwards compatibility, psql can still attempt to connect to db with
> name same as the username, but the error message could be more like
> providing the information, what can be done next.

Sorry, but I don't agree.
I use databases named like users all the time, and love the fact that
I don't have to provide dbname when it's obvious.

Error message is, in my opinion, clear enough - you're trying to connect
to database that doesn't exist. Why you are trying to - impossible to
tell. Maybe you made a typo. Maybe you forgot to add option. Maybe you
forgot to export env variable.

What is being chosen as user/database name is documented in psql docs.
Additionally - if you want to require that user provides database name,
why don't require also host and port? After all, you need all
four parameters to connect: host, port, username and database name.

If all you ever want is to connect to db named "x", then why not using
psql -d x, or even setting PGDATABASE to x?

depesz



pgsql-novice by date:

Previous
From: Neha Khatri
Date:
Subject: Re: [NOVICE] Why psql connection assumes default database name as the username
Next
From: Andrew Zakharov
Date:
Subject: [NOVICE] Undo all changes made by production release