PgBouncer - " admin_users"中的用户是否可以使用" auth_query"连接而不是userlist.txt?

时间:2018-06-13 21:17:54

标签: database postgresql pgbouncer

我正在尝试对" admin_users"中列出的用户进行身份验证通过使用" auth_query"而不是在userlist.txt中对密码进行硬编码...但我不认为这可以在最新版本的pgbouncer(v1.8.1)中使用。

请有人告诉我,我错了!

以下是问题的示例,我找不到解决方法。事实上,我已经在项目中记录了一个错误和一个增强功能......但是我喜欢有人指出我犯过的一些愚蠢的错误:

https://github.com/pgbouncer/pgbouncer/issues/302(崩溃的bug) https://github.com/pgbouncer/pgbouncer/issues/303(增强请求)

实施例

pgbouncer.ini

[databases]
* = host=localhost port=5432 auth_user=pgbouncer

[pgbouncer]
auth_query = SELECT uname, phash FROM pgbouncer.user_lookup($1);
admin_users = postgres,gclough
userlist.txt

"pgbouncer" "password"

登录同时适用于数据库(端口5432)和pgbouncer(端口6432):

[root@localhost pgbouncer]# /usr/pgsql-9.6/bin/psql -h 127.0.0.1 -U gclough -p 5432 postgres
Password for user gclough: 
psql (9.6.9)
Type "help" for help.

postgres=# \q

[root@localhost pgbouncer]# /usr/pgsql-9.6/bin/psql -h 127.0.0.1 -U gclough -p 6432 postgres
Password for user gclough: 
psql (9.6.9)
Type "help" for help.

postgres=# \q

但如果我尝试登录pgbouncer,则会失败:

[root@localhost pgbouncer]# /usr/pgsql-9.6/bin/psql -h 127.0.0.1 -U gclough -p 6432 pgbouncer
psql: ERROR:  No such user: gclough

除非我将我的用户放入userlist.txt:

"pgbouncer" "password"
"gclough" "trustno1"

然后它起作用:

[root@localhost pgbouncer]# /usr/pgsql-9.6/bin/psql -h 127.0.0.1 -U gclough -p 6432 pgbouncer
Password for user gclough: 
psql (9.6.9, server 1.8.1/bouncer)
Type "help" for help.

pgbouncer=#

1 个答案:

答案 0 :(得分:0)

我的赌注是pgBouncer issue #278

解析auth_query部分时,[database]设置尚不清楚,因此pgBouncer不够聪明,不知道它应该使用该查询。

重新排序配置文件,使[pgbouncer]部分位于[databases]部分之前,看看是否会产生影响。