Pgpool日志错误:主0在1个中仅拥有0个备用

时间:2019-02-22 23:37:45

标签: postgresql pgpool

我在管理两个PostgreSQL 11.2数据库节点(0-主数据库和1-备用数据库)的应用服务器上运行pgpool-II v4.0.2。 psql -c'show pool_nodes'命令显示两个节点都在运行:

$ psql -c 'show pool_nodes'
 node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | last_status_change 
---------+-----------+------+--------+-----------+---------+------------+-------------------+-------------------+---------------------
 0 | 10.1.1.20 | 5432 | up | 0.500000 | primary | 0 | true | 0 | 2019-02-22 21:37:55
 1 | 10.1.3.20 | 5432 | up | 0.500000 | standby | 0 | false | 0 | 2019-02-22 21:44:49

但是,我已经开始在测试在线恢复和回退过程后每10秒将这个错误写入日志:

$ sudo -u postgres pgpool -n
---
2019-02-22 22:15:47: pid 22204: LOG: Setting up socket for 0.0.0.0:5432
2019-02-22 22:15:47: pid 22204: LOG: Setting up socket for :::5432
2019-02-22 22:15:47: pid 22204: LOG: find_primary_node_repeatedly: waiting for finding a primary node
2019-02-22 22:15:47: pid 22204: LOG: verify_backend_node_status: primary 0 owns only 0 standbys out of 1
2019-02-22 22:15:47: pid 22204: LOG: find_primary_node: primary node is 0
2019-02-22 22:15:47: pid 22204: LOG: find_primary_node: standby node is 1
2019-02-22 22:15:47: pid 22204: LOG: pgpool-II successfully started. version 4.0.2 (torokiboshi)
2019-02-22 22:15:47: pid 22204: LOG: node status[0]: 1
2019-02-22 22:15:47: pid 22204: LOG: node status[1]: 2
2019-02-22 22:15:47: pid 22238: LOG: verify_backend_node_status: primary 0 owns only 0 standbys out of 1
2019-02-22 22:15:57: pid 22238: LOG: verify_backend_node_status: primary 0 owns only 0 standbys out of 1
...
(repeats each 10 seconds)

我不知道这意味着什么以及如何解决。 PostgreSQL流复制似乎正常工作。那就是当我在主数据库上创建并填充测试表时,在备用数据库上我会看到同样的情况。

有什么主意可以看吗?谢谢。

更新2/23/19:

我将范围缩小了一点。看来,尽管我的后端节点正在流式复制中运行,但以下查询返回NULL(https://github.com/beocommedia/pgpool-II/blob/4.0.2/src/main/pgpool_main.c#L3265-L3268):

2019-02-23 15:32:32: pid 17383: DEBUG: verify_backend_node_status: pg_stat_wal_receiver status for standby 1 is NULL
2019-02-23 15:32:32: pid 17383: LOCATION: pgpool_main.c:3271

如果我通过pgpool查询相同的备用节点,则会返回状态:

$ psql -x -h 10.1.3.20 -c "SELECT status, conninfo FROM pg_stat_wal_receiver";
-[ RECORD 1 ]----------------------------------------------------------------
status   | streaming
conninfo | user=repl passfile=/var/lib/postgresql/.pgpass dbname=replication 
           host=10.1.1.20 port=5432 fallback_application_name=walreceiver
           sslmode=prefer sslcompression=0 krbsrvname=postgres
           target_session_attrs=any

知道我可能在这里缺少什么吗?

1 个答案:

答案 0 :(得分:0)

好。我终于能够解决这个问题。问题出在sr_check_user= 'pgpool'用户没有查询pg_stat_wal_receiver视图的权限。在SELECT中传递pgpool用户名后,它变得显而易见:

$ psql -x -h [standby.db.node.ip] -U pgpool -d postgres -c "SELECT status, conninfo FROM pg_stat_wal_receiver";

可以通过使pgpool用户成为“ pg_monitor”角色来解决此问题:

GRANT pg_monitor to pgpool;

我已要求pgpool维护者更新以下文档:http://www.pgpool.net/docs/latest/en/html/example-cluster.html