For many years I have used to use the environment variable $PGUSER when I work with client tools such as psql/pg_dump/pg_restore.
Recently I build up a new PG13 server, the env var $PGUSER does NOT take effect, when I try to use the client tools on a terminal of the server.
I get message like this:
leon@mamba:~$ echo $PGUSER
postgres
leon@mamba:~$ psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed:
FATAL: role "leon" does not exist
If I use the tools on a terminal of another physical computer, the env var takes effect normally.
Of course, the var has been set on both machines.
My pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
host all all 192.168.x.x/16 md5
# IPv6 local connections:
host all all ::1/128 trust
export PGUSER=postgres, I successfully used client tools without specifying CLI arguments. Would you please to explain why I got this? What's the difference between the env var assigned by CLI and by /etc/environment file? I can even get it withexport PGUSER=$PGUSER!