尝试使用 psql 连接时 Pgbouncer 身份验证失败

Jos*_*rby 7 postgresql pgbouncer postgresql-9.3

我正在尝试配置最新的 pgbouncer 以与 postgres 9 一起使用。我可以使用psql正确的密码连接到我的数据库,但是当我使用时,psql -p 6432我无法连接,错误消息为psql: ERROR: auth failed

这似乎可能是由我的 userlist.txt 文件引起的,但我不确定。我检查过,所有必需的文件均由 Postgres 系统用户完全拥有

pgbouncer.ini

[databases]
postgres = host=localhost port=5433 auth_user=postgres dbname=postgres

[pgbouncer]
pidfile = /usr/local/pgbouncer-1.9.0/pgbouncer.pid
logfile = /usr/local/pgbouncer-1.9.0/log/pgbouncer.log

user = postgres

listen_addr = *
listen_port = 6432

auth_type = md5
auth_file = /usr/local/pgbouncer-1.9.0/etc/userlist.txt
Run Code Online (Sandbox Code Playgroud)

用户列表.txt

"postgres" "md5<MD5 SUM>"

用于启动 pgbouncer 的命令

./bin/pgbouncer -d etc/pgbouncer.ini

日志输出显示失败

2019-08-20 13:46:01.080 16446 LOG C-0x1028ce0: postgres/postgres@127.0.0.1:43286 login attempt: db=postgres user=postgres tls=no
2019-08-20 13:46:01.080 16446 LOG C-0x1028ce0: postgres/postgres@127.0.0.1:43286 closing because: client unexpected eof (age=0)
2019-08-20 13:46:06.980 16446 LOG C-0x1028ce0: postgres/postgres@127.0.0.1:43414 login attempt: db=postgres user=postgres tls=no
2019-08-20 13:46:06.980 16446 LOG C-0x1028ce0: postgres/postgres@127.0.0.1:43414 closing because: auth failed (age=0)
2019-08-20 13:46:06.980 16446 WARNING C-0x1028ce0: postgres/postgres@127.0.0.1:43414 pooler error: auth failed
Run Code Online (Sandbox Code Playgroud)

RCr*_*oss 11

要为 PGBouncer(或 PostgreSQL)创建 md5 密码,公式为:

\n\n
"md5" + md5(password + username)\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以通过以下 3 种方式创建一个,其中用户名是“admin”,密码是“password123”...

\n\n

Linux:

\n\n
# echo -n "md5"; echo -n "password123admin" | md5sum | awk \'{print $1}\'\nmd53f84a3c26198d9b94054ca7a3839366d\n
Run Code Online (Sandbox Code Playgroud)\n\n

苹果系统:

\n\n
\xe2\x9e\x9c echo -n "md5"; md5 -qs "password123admin"                                                                                                                                                                                   \nmd53f84a3c26198d9b94054ca7a3839366d\n
Run Code Online (Sandbox Code Playgroud)\n\n

Python 2:

\n\n
>>> import hashlib\n>>> print("md5" + hashlib.md5("password123" + "admin").hexdigest())\nmd53f84a3c26198d9b94054ca7a3839366d\n
Run Code Online (Sandbox Code Playgroud)\n\n

Python 3:

\n\n

如上所述,但使用二进制字符串...

\n\n
print("md5" + hashlib.md5(b"password123" + b"admin").hexdigest())\n
Run Code Online (Sandbox Code Playgroud)\n\n

配置文件

\n\n

pgbouncer.ini 中的条目应该是:

\n\n
auth_type = md5\nauth_file = /etc/pgbouncer/userlist.txt\n
Run Code Online (Sandbox Code Playgroud)\n\n

/etc/pgbouncer/userlist.txt 中的相关条目应该是:

\n\n
"admin" "md53f84a3c26198d9b94054ca7a3839366d"\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后你可以通过连接到 pgbouncer 来测试它

\n\n
psql -h localhost -p 6432 -U admin\n
Run Code Online (Sandbox Code Playgroud)\n\n

...然后在出现提示时输入密码的纯文本版本。

\n


Jos*_*rby 1

设法解决了这个问题,我在用户列表中使用了我的 Postgres 密码的 md5 和。我这样做是因为我在 3 个不同的指南中看到了它,但在查看官方文档后,我发现您需要以纯文本形式输入密码,同时身份验证类型仍为 md5。现在这是有道理的,但为什么不同网站上的 3 个不同指南都给出了错误的信息,我不确定。虽然问题已经解决了,但还是很高兴。