Re: psql's default database on connect (our internal ref. SRP-30861)

From: Matthias Apitz <guru(at)unixarea(dot)de>
To: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: psql's default database on connect (our internal ref. SRP-30861)
Date: 2021-08-06 07:25:29
Message-ID: YQzj6YEyfyfJ8t1C@c720-r368166
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

El día viernes, agosto 06, 2021 a las 09:07:56a. m. +0200, Guillaume Lelarge escribió:

> Le ven. 6 août 2021 à 08:53, Matthias Apitz <guru(at)unixarea(dot)de> a écrit :
>
> >
> > Hello,
> >
> > testpos(at)srap53dxr1:~> psql --help
> > ...
> > -d, --dbname=DBNAME database name to connect to (default: "testpos")
> >
> > testpos(at)srap53dxr1:~> whoami
> > testpos
> >
> > testpos(at)srap53dxr1:~> env | grep PG
> > PGPASSWORD=xxxxxxxx
> > PGHOST=localhost
> > PGPORT=5432
> >
> > testpos(at)srap53dxr1:~> LANG=C psql -Usisis
> > psql (13.3)
> > Type "help" for help.
> >
> > sisis=# \l
> > List of databases
> > Name | Owner | Encoding | Collate | Ctype | Access
> > privileges
> >
> > -----------+----------+----------+-------------+-------------+-----------------------
> > postgres | postgres | UTF8 | de_DE.UTF-8 | de_DE.UTF-8 |
> > sisis | sisis | UTF8 | de_DE.UTF-8 | de_DE.UTF-8 |
> > ...
> >
> > Why psql connects to the database 'sisis'? I was expecting that it
> > will try to connect to a database 'testpos' as this is the UNIX login
> > and as '-d....' was not specified. I was expecting in this case an
> > error like this:
> >
> > testpos(at)srap53dxr1:~> export PGDATABASE=testpos
> > testpos(at)srap53dxr1:~> psql -Usisis
> > psql: error: FATAL: database »testpos« does not exist
> >
> > What do I uderstand wrong?
> >
>
> When you try to connect without specifying a database name on the command
> line, psql will check PGDATABASE. If unset, it will use the PostgreSQL user
> name also as the database name. If you don't specify explicitly the
> PostgreSQL username, it will check PGUSER and, if unset, will use the OS
> username.
>
> That matches all your examples above.

No, it does not match all my examples. Read again what it says as
default on --help.

matthias
--
Matthias Apitz, ✉ guru(at)unixarea(dot)de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
Tear it down! Defund the Humboldt Forum!
https://www.jungewelt.de/artikel/406715.humboldt-forum-feudaler-themenpark.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2021-08-06 07:34:42 Re: psql's default database on connect (our internal ref. SRP-30861)
Previous Message David G. Johnston 2021-08-06 07:16:10 Re: psql's default database on connect (our internal ref. SRP-30861)