'Why can I login to my database using my .pgpass credentials, but not use pg_dump?

After updating my computer I am unable to do automatic backups of my PostgreSQL 12 database, which has the version:

psql (PostgreSQL) 12.8 (Ubuntu 12.8-Ubuntu0.20.04.1)

Before updating, I was able to run the following code, both manually and using crontab:

pg_dump -h localhost -p 5432 -U brian -d example_db > '/home/brian/.../example_db.bak'

The error I now get is:

pg_dump: error: connection to database "example_db" failed: FATAL:  password authentication failed for user "brian"
password retrieved from file "/home/brian/.pgpass"
FATAL:  password authentication failed for user "brian"
password retrieved from file "/home/brian/.pgpass"

I have confirmed that my ".pgpass"-file lives up to the manual described here: PostgreSQL 12 Manual: pgpass

I am also able to log in to my database without being prompted for a password:

brian@pc:~$ psql -U brian -d example_db

Would anyone have an idea why I am unable to use pg_dump when I am able to login to my database without being prompted for my password?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source