2

system: Ubuntu 20.
related post: PostgreSQL: Using the .pgpass file
https://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables/117470#117470
overall means I permanent set the following enviroment variable in /etc/profile

export PGPASSFILE='/home/jian/.pgpass'
export PSQLRC='/home/jian/.psqlrc'
export PGUSER=admin
export PGDATABASE=test
export PGPORT=5433

I also did sudo chmod 600 /home/jian/.pgpass

 sudo cat /home/jian/.pgpass

return

localhost:5433:test:admin:password
localhost:5432:test:admin:password

when I type psql, it still promopt me to password. I thought all things are properly set. later I deleted the second password line, still ask me password.

5
  • Did you confirm, that the environment variables are really set for your current user (e.g. echo $PGUSER)? What happens if you type: psql -U admin -d test -port 5433 -h localhost. Btw: why set PGPASSFILE or PSQLRC for all users to the same value?
    – user1822
    Jul 6, 2022 at 6:04
  • @a_horse_with_no_name So I need set the enviroment variable and set the ubuntu current user. both should be same? can I make it first check the enviroment variable value?
    – jian
    Jul 6, 2022 at 6:17
  • Why the sudo in sudo cat /home/jian/.pgpass. It seems suspicious. Why do you need to become root to read your own pgpass?
    – jjanes
    Jul 7, 2022 at 0:14
  • @jjanes because I follow this tutorial tableplus.com/blog/2019/09/how-to-use-pgpass-in-postgresql.html to chmod 600 the file.
    – jian
    Jul 7, 2022 at 4:21
  • @jjanes file permission something like: -rw------- 1 admin admin 28 Jul 6 10:34 /home/jian/.pgpass
    – jian
    Jul 7, 2022 at 4:22

1 Answer 1

3

You must be the owner of the password file. Supposing that your user name is jian, you'd have to change the ownership:

sudo chown jian /home/jian/.pgpass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.