简体   繁体   English

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

[英]Which directory should I save a .pgpass file in when connecting to Postgresql from Python in Anaconda?

I've saved a .pgpass (properly configured) file in 我已将.pgpass(正确配置)文件保存在

`/Users/username/`

`/anaconda`

`/anaconda/bin/`

but the postgresql connection still requests my username and password. 但是postgresql连接仍然要求我的用户名和密码。 I'm using Anaconda and Spyder IDE. 我正在使用Anaconda和Spyder IDE。 Where should I save the .pgpass file? .pgpass文件应保存在哪里?

Check permissions. 检查权限。 The .pgpass file has to have no group nor other permissions: .pgpass文件不必具有组或其他权限:

chmod u-x,go-rwx ~/.pgpass

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

Like the documentation says: 就像文档中说的那样:

  • The program must be using the C client library libpq to connect to PostgreSQL (the JDBC driver, for example, doesn't use libpq ). 该程序必须使用C客户端库libpq连接到PostgreSQL(例如JDBC驱动程序不使用libpq )。

  • The .pgpass file must be in the home directory of the user that owns the process which uses libpq to connect to PostgreSQL. .pgpass文件必须位于拥有使用libpq连接到PostgreSQL的进程的用户的主目录中。

  • You can override the default location by either putting the variable PGPASSFILE in the process' environment or (from v10 on) with the connection parameter passfile . 您可以通过将变量PGPASSFILE放在进程的环境中或(从v10开始)带有连接参数passfile方式覆盖默认位置。

  • The .pgpass file must have permissions 0600 or less. .pgpass文件必须具有0600或更少的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python 在连接到 PostgreSQL 时不能使用 .pgpass - python can not use .pgpass while connecting to PostgreSQL 导入熊猫时,Anaconda python在目录中执行python文件 - Anaconda python executes a python file in directory when I import pandas 我应将.dat文件保存在哪个目录中? - In which directory should I save my .dat file? 安装最新版Python应该在哪个目录下? - Which directory should I be in when I install the newest version of Python? 如何使用 libpq 的 pgpass 连接到 postgresql,而不指定纯文本密码? - How to connect to postgresql, without specifying plain-text password, with libpq's pgpass? 我应该从 Anaconda 安装哪个 xgboost 包? - Which xgboost package should I install from Anaconda? python中没有这样的文件或目录(卸载/安装Anaconda) - No such file or directory in python (Uninstall/Install Anaconda) 尽管在.pgpass中找到了密码,但Postgresql还是从命令行提示输入密码 - Postgresql prompts for password from command-line despite finding it in .pgpass 我应该保存哪种格式的python脚本输出? - Which format should I save my python script output? Python如果anaconda是我的python组织者,我应该使用pip / pip3来安装/更新软件包吗? - Python If I should use pip/pip3 to install/update packages when anaconda is my python organizer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM