user7795844
user7795844

Reputation:

PSQL does not detect .pgpass file

I have tried

  1. Setting the permission of .pgpass to 0600
  2. Confirmed .pgpass is in my user's home directory (/home/brandon/.pgpass)
  3. use -w in pg_dumpall command
  4. Confirmed the data in .pgpass is correct

The script (https://wiki.postgresql.org/wiki/Automated_Backup_on_Linux) for automated backup works if I type the password again and again which is why i added -w to all the commands. It for some reason does not read the .pgpass file .

There are multiple error messages but they are generally this.

 pg_dumpall: could not connect to database "template1": FATAL:  password    authentication failed for user "postgres"

FATAL: password authentication failed for user "postgres"

pg_pass file :

localhost:5432:my_db:postgres:password

command line :

username@droplet:~/ProjectDir$ bash cronjob/db_backup/pg_backup.sh
Making backup directory in /home/backups/database/postgresql/2017-12-06/


Performing globals backup
--------------------------------------------

Globals backup
cronjob/db_backup/pg_backup.sh: line 80: /home/backups/database/postgresql/2017-12-06/globals.sql.gz.in_progress: Permission denied
pg_dumpall: could not connect to database "template1": fe_sendauth: no      password supplied

[!!ERROR!!] Failed to produce globals backup


Performing schema-only backups
--------------------------------------------

psql: fe_sendauth: no password supplied
The following databases were matched for schema-only backup:




Performing full backups
--------------------------------------------

psql: fe_sendauth: no password supplied

All database backups complete!

Upvotes: 5

Views: 4476

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246083

You should supply the actual calls to pg_dump and pg_dumpall for a more detailed answer.

However, from your output I see that pg_dumpall (?) tries to connect to database template1, but in your .pgpass file the only database is my_db.

You'll have to add entries to .pgpass for all databases to which you are trying to connect.

localhost:5432:mydb1:postgres:password
localhost:5432:mydb2:postgres:password
localhost:5432:mydb3:postgres:password

Alternatively, you are also able to put an * as a placeholder for different database names.

localhost:5432:*:postgres:password

Make sure that all the fields in .pgpass are the right/matching ones. If any of them (host, port, etc.) don't match, the unclear, uninformative and arguably wrong fe_sendauth: no password supplied error message will be the same.

Upvotes: 3

Related Questions