0

我在 Web 服务器上有一个 haproxy 架构,它路由到从属服务器,在那里我有 pgbouncer over postgre。HAPoxy 配置:

global
    log 127.0.0.1 local1 debug
    user haproxy
    group haproxy

defaults
    log global
    retries 3
    timeout connect 1s
    timeout server 20m
    timeout client 20m

listen pgsql-cluster
    bind 127.0.0.1:5433
    mode tcp
    balance leastconn
    #option pgsql-check user postgres - 
    default-server inter 1s downinter 1s rise 2 fall 1
    server pgsql-1 10.5.8.14:6432 check
    server pgsql-2 10.5.8.21:6432 check

Pgbouncer 配置是默认的。第一个问题,pgsql-check 不工作。pgboucer.log:

2016-11-23 12:47:37.805 17068 WARNING C-0x23bb760: (nodb)/(nouser)@10.5.8.13:48898 Pooler Error: No such database: postgres
2016-11-23 12:47:37.805 17068 LOG C-0x23bb760: (nodb)/(nouser)@10.5.8.13:48898 login failed: db=postgres user=postgres

但最大的问题是,经过一段时间后,我的网站 (Yii2) 出现了很多错误。日志:

2016-11-22 16:37:42 [10.5.33.135][-][-][error][application] SQLSTATE[08006] [7] server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request. in file /var/www/copy-search/vendor/yiisoft/yii2/db/Connection.php on line 547

我有一种感觉,那个 haproxy 只是中断了会话。

4

1 回答 1

1

要回答第一个问题,请确保在您的 PG Bouncer 配置中定义了一个名为 postgres 的用户。我目前有 HA 代理设置以在两个 PG Bouncer 进程之间分配负载,并在我的配置中定义了一个 postgres 用户和一个 postgres 数据库,并且运行状况检查工作。至于第二个问题,我目前遇到了同样的错误。

更新:

我增加了 HA 代理的超时时间,这解决了我的问题。

listen pgsql-cluster
   bind 127.0.0.1:5433
   mode tcp
   balance leastconn
   timeout client 30h
   timeout server 30h
   #option pgsql-check user postgres - 
   default-server inter 1s downinter 1s rise 2 fall 1
   server pgsql-1 10.5.8.14:6432 check
   server pgsql-2 10.5.8.21:6432 check
于 2017-11-14T15:23:07.330 回答