gpt4 book ai didi

postgresql - pgbouncer kill 命令阻止后续连接

转载 作者:行者123 更新时间:2023-11-29 12:10:43 24 4
gpt4 key购买 nike

根据 https://pgbouncer.github.io/usage.html运行 KILL db; 应该立即断开给定数据库上的所有客户端和服务器连接。我试图使用

在我的测试环境中停止所有与 postgres 的连接
=# kill postgres;

它确实关闭了所有客户端和服务器连接,但我无法再连接到 postgres。

$ psql -h localhost -p 6543 postgres
psql: ERROR: pgbouncer cannot connect to server

在 postgresql.log 中我有以下消息

[2016-04-27 16:21:38 u=postgres d=postgres h=[local] p=12458 l=1] LOG: could not send data to client: Broken pipe
[2016-04-27 16:21:38 u=postgres d=postgres h=[local] p=12458 l=2] FATAL: connection to client lost

pgBouncer realod 不会改变这种情况,只有重启有帮助。

=# show databases;
name │ host │ port │ database │ force_user │ pool_size │ reserve_pool │ pool_mode │ max_connections │ current_connections
─────────┼──────┼──────┼──────────┼────────────┼───────────┼──────────────┼───────────┼─────────────────┼─────────────────────

postgres │ NULL │ 5454 │ postgres │ NULL │ 5 │ 100 │ NULL │ 0 │ 0


=# show version;
NOTICE: pgbouncer version 1.7.2
  1. 谁能解释一下发生了什么?
  2. 有没有办法在不重启的情况下通过 pgbouncer 修复 postgres 连接?
  3. 如果数据库连接锁定是 kill 命令的预期行为,我如何关闭所有连接而不阻止新连接?

谢谢,米哈伊尔

最佳答案

对 pgBouncer 使用Resume 命令。

这在 pgBouncer 关于 Process Controlling Commands 的部分中没有准确记录,但是 KILL db; 命令实际上需要后续的 RESUME db; 命令来允许连接。

如果您查看 pgBouncer 日志文件,您应该会看到如下条目:

2016-12-16 22:07:10.224 5720 LOG C-0x851e28: dbname/username@127.0.0.1:42421 登录尝试:db=dbname user=username tls=no
2016-12-16 22:07:10.224 5720 LOG C-0x851e28: dbname/username@127.0.0.1:42421 关闭因为:pgbouncer 无法连接到服务器(age=0)
2016-12-16 22:07:10.224 5720 警告 C-0x851e28: dbname/username@127.0.0.1:42421 Pooler 错误:pgbouncer 无法连接到服务器
2016-12-16 22:07:10.224 5720 LOG S-0x85aae0: dbname/username@(bad-af):0 关闭因为: 暂停模式 (age=0)

请注意,pgBouncer 声称它在此日志中处于暂停模式,并且我看到 psql 在此状态下报告的相同错误:

psql:错误:pgbouncer 无法连接到服务器

在对 pgBouncer 执行 RESUME db; 命令后,连接应该会再次工作。

关于postgresql - pgbouncer kill 命令阻止后续连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36916450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com