可以使用 Replication Manager 工具套件和 PostgreSQL 交互式终端检查数据库高可用性集群中各个 VMware Cloud Director 节点的复制状态。

过程

  1. root 身份直接或通过 SSH 登录到集群中任何正在运行的节点的操作系统。
  2. 将用户更改为 postgres
    sudo -i -u postgres
  3. 检查节点的复制状态。
    /opt/vmware/vpostgres/current/bin/repmgr -f /opt/vmware/vpostgres/current/etc/repmgr.conf node status
    主节点的系统输出提供有关节点、PostgreSQL 版本和复制详细信息的信息。例如:
    Node "bos1-vcloud-static-161-5":
            PostgreSQL version: 10.9
            Total data size: 81 MB
            Conninfo: host=172.18.36.193 user=repmgr dbname=repmgr connect_timeout=2
            Role: primary
            WAL archiving: off
            Archive command: (none)
            Replication connections: 2 (of maximal 10)
            Replication slots: 0 physical (of maximal 10; 0 missing)
            Replication lag: n/a
    
    备用节点的系统输出提供有关节点、PostgreSQL 版本、复制详细信息和上游节点的信息。例如:
    Node "bos1-vcloud-static-161-49":
        PostgreSQL version: 10.9
        Total data size: 83 MB
        Conninfo: host=172.18.36.191 user=repmgr dbname=repmgr connect_timeout=2
        Role: standby
        WAL archiving: off
        Archive command: (none)
        Replication connections: 0 (of maximal 10)
        Replication slots: 0 physical (of maximal 10; 0 missing)
        Upstream node: bos1-vcloud-static-161-48 (ID: 683)
        Replication lag: 0 seconds
        Last received LSN: 2/D863B4E0
        Last replayed LSN: 2/D863B4E0
  4. (可选) 有关更多详细信息,请使用 PostgreSQL 交互式终端检查节点的复制状态。
    PostgreSQL 交互式终端可以提供有关备用节点的任何已接收日志记录是否落后于主节点所发送日志的信息。
    1. 连接到 psql 终端。
      /opt/vmware/vpostgres/current/bin/psql
    2. 要展开显示并使查询结果更易于阅读,请运行 set \x 命令。
    3. 根据节点的角色运行复制状态查询。
      选项 操作

      在主节点上运行查询。

      select* from pg_stat_replication;

      在备用节点上运行查询。

      select* from pg_stat_wal_receiver;