在 Anaconda 中从 Python 连接到 Postgresql 时,我应该将 .pgpass 文件保存在哪个目录中?

Cha*_*Roe 3 python postgresql spyder anaconda

我已经保存了一个 .pgpass(正确配置)文件

`/Users/username/`

`/anaconda`

`/anaconda/bin/`
Run Code Online (Sandbox Code Playgroud)

但是 postgresql 连接仍然请求我的用户名和密码。我正在使用 Anaconda 和 Spyder IDE。我应该在哪里保存 .pgpass 文件?

Lau*_*lbe 5

就像文档说的:

  • 该程序必须使用 C 客户端库libpq来连接到 PostgreSQL(例如,JDBC 驱动程序不使用libpq)。

  • .pgpass文件必须位于拥有libpq用于连接到 PostgreSQL的进程的用户的主目录中。

  • 您可以通过将变量PGPASSFILE放在进程的环境中或(从 v10 开始)使用连接参数来覆盖默认位置passfile

  • .pgpass文件必须具有 0600 或更少的权限。


Tom*_*zky 3

检查权限。该.pgpass文件必须没有组或其他权限:

chmod u-x,go-rwx ~/.pgpass
Run Code Online (Sandbox Code Playgroud)

命令行 psql 客户端实际上会警告您:
WARNING: password file "/home/tometzky/.pgpass" has group or world access; permissions should be u=rw (0600) or less

  • 我的 .pgpass 文件的权限为 0600。连接无法识别该文件存在。 (2认同)