为什么 psql 在尝试使用 pgbouncer 连接时要求输入密码

Why psql ask to enter password when trying to connect using pgbouncer

我已将 pgbouncer-1.7.2 安装在与 PostgreSQL-9.6 数据库相同的 Linux 服务器上。 当我尝试使用 pgbouncer 连接到我的本地数据库时,数据库要求输入密码。例如:

psql -p 6432 -U postgres -d mydb10 -h localhost 
**Password for user postgres:** 

输入密码后就可以登录了。 同样的直接请求运行没有密码:

psql -p 5432 -U postgres -d mydb10 -h localhost 
psql (9.6.5) 
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384,    bits: 256, compression: off) 
Type "help" for help. 

mydb10=# \q 

Pgbouncer 设置(不是全部):

[databases]
* = host=127.0.0.1 port=5432 auth_user=postgres pool_size=20
[pgbouncer]

listen_addr = *
listen_port = 6432

auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
;; auth_query = SELECT usename, passwd FROM pg_shadow WHERE usename=

PostgreSQL 设置(不是全部):

port = 5432

pg_hba.conf 中的所有 METHOD 都设置为 'trust'。 如果我设置 auth_type = trust,通过 pgbouncer 的连接不需要密码。 有趣的是,pgbouncer 安装在单独的服务器上时,同样的配置没有这个问题。

如果您知道如何解决这个问题,请告诉我。

似乎 auth_type = trust 是一种方法,如果你想在没有密码检查的情况下连接(因为你在 pg_hba.conf 中配置了 trust

关于

What is interesting is that the same configuration when pgbouncer installed on separate server, has no such problem.

可能 /etc/pgbouncer/userlist.txt 在不同的服务器上有所不同?

PS 还要注意,从 1.7 版本开始,pgbouncer 支持 auth_type = hba,您可能会觉得合适。

PPS 您通过不同的 pgbouncer 实例访问的问题可能是因为 .pgpass 文件不同,这些文件被 psql

使用