标签: py-postgresql

psql 可以连接到 unix 域套接字,但具有相同参数的 py-postgresql 得到“权限被拒绝”

问题描述:

我的系统用户是milosz,它映射到project_great中的PostgreSQL 用户pg_ident.conf。我正在使用对等身份验证通过 unix 域套接字连接到 PostgreSQL 数据库。此连接方法在使用 时有效,但在使用 Python 脚本中的相同参数psql时则失败。py-postgresql

在这里,我使用以下命令成功连接到数据库psql

$ psql -U project_great \
>      -d project_great \
>      -h /var/run/postgresql
psql (9.3.4)
Type "help" for help.

project_great=> 
Run Code Online (Sandbox Code Playgroud)

这是database_test.py

#!/usr/bin/env python3

import postgresql

params = {
    'user':     'project_great',
    'database': 'project_great',
    'unix':     '/var/run/postgresql',
}

connection = postgresql.open(**params)
Run Code Online (Sandbox Code Playgroud)

在这里,我尝试通过运行连接到数据库./database_test.py

$ ./database_test.py 
Traceback (most recent call last):
  File "./database_test.py", line 11, in <module>
    sys.exit(main(sys.argv))
  File "./database_test.py", …
Run Code Online (Sandbox Code Playgroud)

postgresql unix-socket python-3.x py-postgresql

8
推荐指数
1
解决办法
2万
查看次数