postgresql: .pgpass not working

前端 未结 5 762
再見小時候
再見小時候 2021-02-03 19:16

I have created a .pgpass file in my home directory which looks like this

localhost:5432:somedb:someuser:somepass

I am using a shell scr

5条回答
  •  抹茶落季
    2021-02-03 20:05

    psql (startup.c) calls PQconnectdbParams (fe-connect.c), and then passwordFromFile is called. Here’s a checklist to make sure the pgpass file will be used:

    1. Make sure the flags --password/-W and password= in the connection string are unset. Otherwise, the pgpass file will not be used.
    2. Make sure the environment variable PGPASSWORD is unset (echo $PGPASSWORD). Otherwise, the pgpass file will not be used.
    3. Make sure the pgpass file is in the right location ($PGPASSFILE or default ~/.pgpass or %APPDATA%\postgresql\pgpass.conf)
    4. Make sure the passfile is not readable, writable, or executable by group or other (e.g. chmod 600 ~/.pgpass); otherwise psql will print a warning.
    5. Make sure the passfile is a file (not a symlink); otherwise psql will print a warning.
    6. Make sure the passfile is readable by the psql user (e.g. cat ~/.pgpass); otherwise psql will ignore it without warning. Make sure that it is owned by the user, and that all its ancestor directories are executable by the user.
    7. Make sure that the pgpass file has the correct format hostname:port:database:username:password (The Password File, passwordFromFile). Each field (other than password) can be *. The characters : and \ must be escaped \: and \\ (even in password). The password ends at : or the end of the line and can include any byte other than \r, \n, or \0. Any lines that aren’t formatted right or don’t match the host and user are ignored without warning as if they were comments.
    8. Make sure the hostname, port, dbname, username of the line in the pgpass file match the server or are *. The server’s “pwhost” that is checked is the host name if non-empty, or the hostaddr ip address. Otherwise, the line will be ignored without warning.

    Unfortunately, there is no logging within these files, so if this doesn’t help, then you may need to compile psql and libpq yourself and run it in a debugger.

提交回复
热议问题