pgbouncer kill命令阻止后续连接

时间:2016-04-28 13:39:42

标签: postgresql database-connection pgbouncer

根据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-connection而不重启?
  3. 如果数据库连接锁定是kill命令的预期行为,我如何在不阻塞新连接的情况下关闭所有连接?
  4. 谢谢,米哈伊尔

1 个答案:

答案 0 :(得分:2)

恢复命令用于pgBouncer。

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 login attempt: db=dbname user=username tls=no 2016-12-16 22:07:10.224 5720 LOG C-0x851e28: dbname/username@127.0.0.1:42421 closing because: pgbouncer cannot connect to server (age=0) 2016-12-16 22:07:10.224 5720 WARNING C-0x851e28: dbname/username@127.0.0.1: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

对pgBouncer发出RESUME db;命令后,连接应该再次起作用。

相关问题