2

If I set PGPASSFILE to an explicit path like /home/user/.pgpass then it works fine and when logged in as the user that owns that file I can use psql for the entries in .pgpass.conf.

The problem I have is that I need to have multiple accounts use psql. If I change PGPASSFILE to user directory like ~/.pgpass.conf then it doesn't work and doesn't read the file so it gives a password error.

Because I can only specify one file it means only the owner of that file can run the commands I need to run.

I am running on Ubuntu 18.04 and I need root & www-data to have a .pgpass.conf file.

How do I do this?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Guerrilla
  • 13,375
  • 31
  • 109
  • 210

1 Answers1

0

If you have system users corresponding to your db users (root and www-data in your case), each has its own, separate .pgpass file in its respective home directory. Set each accordingly.

And simply do not set PGPASSFILE at all. The manual:

PGPASSFILE behaves the same as the passfile connection parameter.

And:

passfile

Specifies the name of the file used to store passwords (see Section 33.15). Defaults to ~/.pgpass, or %APPDATA%\postgresql\pgpass.conf on Microsoft Windows. (No error is reported if this file does not exist.)

Related:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228