【问题标题】:pgbouncer can't connect to local postgresql database (timeout)pgbouncer 无法连接到本地 postgresql 数据库(超时)
【发布时间】:2022-02-16 16:15:51
【问题描述】:

我试图让 pgbouncer 在我的独立 postgresql 服务器上工作,但是当我尝试使用 pgbouncer 端口连接到数据库时,我得到一个超时错误。

Postgresql:9.1.8

pgBouncer:1.4.2

操作系统:Ubuntu 12.04.2 LTS (GNU/Linux 3.8.4-x86_64-linode31 x86_64)

这是我的配置文件:

[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres
mydb = host=127.0.0.1 port=5432 dbname=mydb

[pgbouncer]
logfile = /home/username/pg_log/pgbouncer.log
pidfile = /tmp/pgbouncer.pid
listen_addr = xxx.xxx.xxx.xxx
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
stats_users = stats, root
user = postgres
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 1000
default_pool_size = 20
log_connections = 1
log_disconnections = 1
log_pooler_errors = 1

我正在尝试像这样测试连接:

psql -p 6432 -U postgres mydb

这是我的日志文件:

28396 LOG listening on xxx.xxx.xxx.xxx:6432
28396 LOG listening on unix:/var/run/postgresql/.s.PGSQL.6432
28396 LOG process up: pgbouncer 1.4.2, libevent 2.0.16-stable (epoll), adns: evdns2
28864 LOG C-0x23f7890: mydb/postgres@unix:6432 login attempt: db=mydb user=postgres
28864 LOG C-0x23f7890: mydb/postgres@unix:6432 closing because: client unexpected eof (age=0)
28864 LOG C-0x23f7890: mydb/postgres@unix:6432 login attempt: db=mydb user=postgres
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 new connection to server
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 closing because: connect failed (age=0)
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 new connection to server
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 closing because: connect failed (age=0)
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 new connection to server
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 closing because: connect failed (age=0)
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 new connection to server
28864 LOG S-0x2415240: mydb/postgres@127.0.0.1:5432 closing because: connect failed (age=0)
28864 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
28864 LOG C-0x23f7890: mydb/postgres@unix:6432 closing because: client_login_timeout (server down) (age=60)
28864 WARNING C-0x23f7890: mydb/postgres@unix:6432 Pooler Error: client_login_timeout (server down)
28864 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us
28864 LOG Stats: 0 req/s, in 0 b/s, out 0 b/s,query 0 us

还有什么我需要更改才能使 pgbouncer 工作的吗?

【问题讨论】:

  • 防火墙单向阻塞数据包?
  • 嗯,看起来很奇怪。我在本地和外部测试连接:tcp 0 0 xxx.xxx.xxx.xxx:6432 0.0.0.0:* LISTEN 27040/pgbouncer

标签: postgresql pgbouncer


【解决方案1】:

改变

listen_addresses = 'private_ip'

listen_addresses = '*'

postgresql.conf 文件中。

【讨论】:

    【解决方案2】:

    看起来您正在尝试使用 Unix 套接字进行连接。根据您的 Postgres 安装,套接字可能是在 /tmp 而不是 /var/run/postgres 中创建的。我遇到了同样的问题,它一直是discussed here

    尝试将 pgbouncer.ini 配置更改为:

    unix_socket_dir = /tmp
    

    您也可以尝试通过添加 -h 来连接到 localhost,如下所示:

     psql -p 6432 -h localhost -U postgres mydb
    

    希望这会有所帮助!

    【讨论】:

    • 错误出现在我的 postgresql.conf 文件中。我的 listen_adresses 设置为不接受本地传入。将其更改为 listen_addresses = '*' 现在可以使用了!
    【解决方案3】:

    对我来说,问题似乎出在我在配置文件的[databases] 部分定义数据库时;我无法使用host=127.0.0.1host=localhost,但我必须使用实际IP,host=192.168.0.1。这可能是由于 postgresql pg_hba.conf 文件配置错误造成的,但我找不到使其与本地 IP 一起使用的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-03
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 2017-11-27
      • 1970-01-01
      • 2020-01-05
      相关资源
      最近更新 更多