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

Поиск
Список
Период
Сортировка
От Guillaume Lelarge
Тема Re: psql's default database on connect (our internal ref. SRP-30861)
Дата
Msg-id CAECtzeXep-aPLgT1hr_QmQv6SyO6W31EE=Z=kMZKJ9J+D=Kt1Q@mail.gmail.com
обсуждение исходный текст
Ответ на psql's default database on connect (our internal ref. SRP-30861)  (Matthias Apitz <guru@unixarea.de>)
Ответы Re: psql's default database on connect (our internal ref. SRP-30861)  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: psql's default database on connect (our internal ref. SRP-30861)  (Matthias Apitz <guru@unixarea.de>)
Список pgsql-general
Le ven. 6 août 2021 à 08:53, Matthias Apitz <guru@unixarea.de> a écrit :

Hello,

testpos@srap53dxr1:~> psql --help
  ...
  -d, --dbname=DBNAME      database name to connect to (default: "testpos")

testpos@srap53dxr1:~> whoami
testpos

testpos@srap53dxr1:~> env | grep PG
PGPASSWORD=xxxxxxxx
PGHOST=localhost
PGPORT=5432

testpos@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@srap53dxr1:~> export PGDATABASE=testpos
testpos@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.


-- 
Guillaume.

В списке pgsql-general по дате отправления:

Предыдущее
От: Matthias Apitz
Дата:
Сообщение: psql's default database on connect (our internal ref. SRP-30861)
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: psql's default database on connect (our internal ref. SRP-30861)