【问题标题】:How to force psql to detect .pgpass file on Windows 10 system?如何强制 psql 在 Windows 10 系统上检测 .pgpass 文件?
【发布时间】:2021-05-26 15:31:18
【问题描述】:

我正在使用 Windows 10 系统,python 3.9.4 in,anaconda env。 我有一个.pgpass 文件:localhost:port:db_name:user_name:password

当我跑步时:

psql -U user_name -d db_name -pXXXX

或

psql -U user_name -d db_name -pXXXX -f /path/to/sql/file.sql

它提示我输入密码。当我输入密码时,我可以连接,但我希望 psql 取而代之的是 pgpass 文件。

我的理论是:pgpass 的格式。在 Windows 系统上是否需要特定的 EOL 字符?

localhost:port:db_name_1:user_name_1:password_1 <CR or LF>
localhost:port:db_name_2:user_name_2:password_2 <CR or LF>

【问题讨论】:

  • 另外,当我尝试“psql -U user_name -d db_name -pXXXX -w”时,我得到以下输出:psql:错误:无法连接到服务器:fe_sendauth:没有提供密码
  • 行尾无关紧要。我猜该文件可能不在正确的位置。 type %AppData%\postgresql\pgpass.conf 给你什么?或者您是否定义了指向非标准位置的环境变量`PGPASSFILE`?
  • 我的 postgres 安装在 conda 环境中。那么我的 pgpass.conf 应该放在哪里呢?
  • 那么我的 pgpass.conf 应该放在哪里呢? C:\Users\USER_NAME\AppData\Local\Continuum\anaconda3\envs\ENV_NAME\???是否有命令返回 psql 正在寻找 pgpass.conf 的位置?

标签: python-3.x windows psql


【解决方案1】:

我能够让它工作。我必须创建“postgresql”文件夹。它不在那里。之后,我添加了“pgpass.conf”文件,我可以在 conda 环境中不提示密码登录。

/Users/user_name/AppData/Roaming/postgresql/pgpass.conf

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2018-05-18
    • 2016-12-10
    • 2017-10-15
    • 2012-07-09
    • 2018-06-17
    • 2015-06-18
    • 2012-03-22
    • 1970-01-01
    • 2016-11-28
    相关资源
    最近更新 更多