Authentication with pgpass not working
peer
authentication means postgresql accepts connections over unix socket from specified unix system user without password as specified database user, so trying to use PGPASS is pointless.
More about peer
access here: https://www.postgresql.org/docs/current/auth-peer.html
In your case, your pg_hba.conf
allows only system user postgres
to connect all databases as database user postgres
. I can't see your db_user
in your pg_hba.conf
, so it can't connect. sudo -u postgres pg_dumpall
means you switch to system user postgres
and run pg_dumpall
as that user connecting as database user postgres
. That's why it works.