pgbench without dbname worked differently with psql and pg_dump - Mailing list pgsql-hackers

From Hayato Kuroda (Fujitsu)
Subject pgbench without dbname worked differently with psql and pg_dump
Date
Msg-id OSCPR01MB14966BC18CB84D81D8016317FF5E62@OSCPR01MB14966.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: pgbench without dbname worked differently with psql and pg_dump
List pgsql-hackers
Dear hackers,

Recently the 'd' option of pgbench is unified with other applications like psql and pg_dump,
but I found further difference. pgbebch uses an OS user as the dbanme even when the '-U' is
specified. Please see below experiments.

```
# Assuming the OS user is "hayato", whereas the database admin is "postgres"
$ initdb -U postgres -D data
...
Success. You can now start the database server using:

    pg_ctl -D data -l logfile start

$pg_ctl -D data -l logfile start
waiting for server to start.... done
server started

# psql can connect to the database "postgres"
$ psql -U postgres -c "SELECT current_database();"
 current_database
------------------
 postgres
(1 row)

# pg_dump can connect as well
$ pg_dump -U postgres
--
-- PostgreSQL database dump
--
....

# ... but pgbench cannot
$ pgbench -U postgres
pgbench: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:  database "hayato" does not exist
pgbench: error: could not create connection for setup
```

Also, I found that dbname parameter for both pgbench and pg_dump is described by
the same sentences [1] [2]. This is also confusing.

Is it an expected behavior?


[1]: https://www.postgresql.org/docs/devel/pgbench.html#PGBENCH-OPTION-DBNAME
```
[-d] dbname
[--dbname=]dbname
Specifies the name of the database to test in. If this is not specified, the environment variable PGDATABASE is used.
If that is not set, the user name specified for the connection is used.
```

[2]: https://www.postgresql.org/docs/devel/app-pgdump.html#:~:text=of%20the%20output.-,dbname,-Specifies%20the%20name
```
dbname
Specifies the name of the database to be dumped. If this is not specified, the environment variable PGDATABASE is used.
If that is not set, the user name specified for the connection is used.
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED




pgsql-hackers by date:

Previous
From: Sumanth Vishwaraj
Date:
Subject: Re: [External] : Re: New feature request for adding session information to PostgreSQL transaction log
Next
From: Logan MAUZAIZE
Date:
Subject: Re: Proper way to clean-up connection for reuse (`DISCARD ALL` and default role)