【问题标题】:Unable to connect to PgBouncer admin console无法连接到 PgBouncer 管理控制台
【发布时间】:2020-08-08 20:49:40
【问题描述】:

我无法连接到我的 PgBouncer 管理控制台。下面是我的pgbouncer.ini 配置。

################## Auto generated ##################
[databases]
* = host=postgresql.default.svc.cluster.local port=5432 user=someuser

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 5432
unix_socket_dir =
user = postgres
auth_file = /etc/pgbouncer/userlist.txt
auth_type = md5
pool_mode = transaction
max_client_conn = 3000
default_pool_size = 50
min_pool_size = 10
reserve_pool_size = 10
reserve_pool_timeout = 5
max_db_connections = 50
max_user_connections = 50
ignore_startup_parameters = extra_float_digits

# Log settings
admin_users = postgres

# Connection sanity checks, timeouts
server_reset_query = DISCARD ALL
server_idle_timeout = 100

# TLS settings

# Dangerous timeouts
################## end file ##################

我有一个userlist.txt 文件,其中包含

"someuser" "password"

我曾尝试使用psql -h localhost -p 5432 -U someuser -d pgbouncer 连接到管理控制台,但出现此错误

psql: ERROR: not allowed

我也尝试过使用psql -h localhost -p 5432 -U postgres -d pgbouncer 进行连接,但psqlthrows

psql: ERROR: no such user: postgres

仅供参考,我正在使用edoburu/pgbouncer:1.9.0 Docker 映像。

【问题讨论】:

    标签: database postgresql connection-pooling pgbouncer


    【解决方案1】:

    由于您似乎是从运行 pgbouncer 的同一台机器上连接的,所以我会尝试通过 Unix 套接字进行连接:

    • 步骤 1:在pgbouncer.ini 中设置unix_socket_dir=/tmpSee docs for details
    • 第 2 步:使用用户 pgbouncer 且无密码的 Unix 套接字连接:
    $ psql --host=/tmp --username=pgbouncer --no-password pgbouncer
    
    psql (12.2 (Ubuntu 12.2-2.pgdg18.04+1), server 1.8.1/bouncer)
    Type "help" for help.
    
    pgbouncer=#
    

    为什么会这样

    根据pgbouncer-docs,这将让您无需密码即可在本地连接:

    此外,如果登录是通过 Unix 套接字 并且客户端具有相同的 Unix 用户 UID,则允许用户名 pgbouncer 无需密码即可登录 作为正在运行的进程。

    (我的重点。)

    【讨论】:

    • 感谢您对“相同的 Unix 用户 UID”的强调,我不得不使用 sudo su postgres 更改用户,因为我的 pgbouncer 服务以 postgres 用户身份运行。
    猜你喜欢
    • 2020-05-19
    • 2016-06-28
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 2018-06-16
    相关资源
    最近更新 更多