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

标签 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 连接而无需重新启动?
  3. 如果数据库连接锁定是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/

相关文章:

php - 避免重复的 mysql 连接

postgresql - Pgbouncer 超时

postgresql - 聚合函数以保留特定值,具体取决于其他列

sql - 如何创建从 postgreSQL 中的表返回一组行的过程

wordpress - 在 Azure 中哪里可以找到我的数据库主机名?

c++ - 错误 C2061 : syntax error : identifier 'buffer' when compiling algparam. h

postgresql - pgbouncer 1.7 主从

postgresql - Pgbouncer - 管理动态数据库设置

json - 汇总 JSON 值

php - 从一个数据库读取数据并使用 PHP 插入另一个数据库时出现编码错误