根据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
- 谁能解释一下发生了什么?
- 有没有办法通过 pgbouncer 修复 postgres 连接而无需重新启动?
- 如果数据库连接锁定是kill命令的预期行为,我如何关闭所有连接而不阻止新连接?
谢谢,米哈伊尔
最佳答案
使用 pgBouncer 的恢复命令。
pgBouncer 关于 Process Controlling Commands 的部分没有准确记录这一点,但是 KILL db;
命令实际上需要后续的 RESUME db;
命令允许连接。
如果您查看 pgBouncer 日志文件,您应该会看到如下条目:
2016-12-16 22:07:10.224 5720 LOG C-0x851e28: dbname/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f1f7e1f6eae5e9e1c4b5b6b3aab4aab4aab5" rel="noreferrer noopener nofollow">[email protected]</a>:42421 login attempt: db=dbname user=username tls=no
2016-12-16 22:07:10.224 5720 LOG C-0x851e28: dbname/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0f091f08141b171f3a4b484d544a544a544b" rel="noreferrer noopener nofollow">[email protected]</a>:42421 closing because: pgbouncer cannot connect to server (age=0)
2016-12-16 22:07:10.224 5720 WARNING C-0x851e28: dbname/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9aefe9ffe8f4fbf7ffdaaba8adb4aab4aab4ab" rel="noreferrer noopener nofollow">[email protected]</a>:42421 Pooler Error: pgbouncer cannot connect to server
2016-12-16 22:07:10.224 5720 LOG S-0x85aae0: dbname/username@(bad-af):0 closing because: pause mode (age=0)
请注意,pgBouncer 在此日志中声称它处于暂停模式,并且我在处于此状态时看到 psql 报告的相同错误:
psql: ERROR: pgbouncer cannot connect to server
在RESUME db;
之后向 pgBouncer 命令,连接应该可以再次工作。
关于postgresql - pgbouncer kill 命令阻止后续连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36916450/