集群管理

SQL方式

show cluster_status; //显示当前配置信息

unvdb=# show cluster_status; //显示当前配置信息
                 item                  |                        value                         |                                   description                                   
---------------------------------------+------------------------------------------------------+---------------------------------------------------------------------------------
 backend_clustering_mode               | 1                                                    | clustering mode
 listen_addresses                      | *                                                    | host name(s) or IP address(es) to listen on
 port                                  | 9999                                                 | unvdbcluster accepting port number
 socket_dir                            | /tmp                                                 | unvdbcluster socket directory
 pcp_listen_addresses                  | *                                                    | host name(s) or IP address(es) for pcp process to listen on
...

具体含义参考 cluster配置 章节

show cluster_nodes; //查看节点信息

unvdb=# show cluster_processes;
 unvdbcluster_pid |     start_time      | client_connection_count | database | username | backend_connection_time | unvdbcluster_counter |       status        
------------------+---------------------+-------------------------+----------+----------+-------------------------+----------------------+---------------------
 27830            | 2022-09-23 18:32:40 | 0                       |          |          |                         |                      | Wait for connection
 27682            | 2022-09-23 16:12:29 | 0                       |          |          |                         |                      | Wait for connection
 27836            | 2022-09-23 18:35:41 | 0                       |          |          |                         |                      | Wait for connection
 27866            | 2022-09-23 19:14:17 | 0                       |          |          |                         |                      | Wait for connection
 27791            | 2022-09-23 17:31:34 | 0                       |          |          |                         |                      | Wait for connection

show cluster_pools; //连接池信息

unvdb=# show cluster_pools;
  pid  |     start_time      | client_connection_count | id | backend_id | database | username | backend_connection_time | client_connection_time | client_disconnection_time | client_idle_duration | majorversion |minorversion | counter | backendpid | connected |       status
-------+---------------------+-------------------------+----+------------+----------+----------+-------------------------+------------------------+---------------------------+----------------------+--
------------+--------------+---------+------------+-----------+---------------------
 27830 | 2022-09-23 18:32:40 | 0                       | 0  | 0          |          |          |                         |                        |                           | 0                    | 0
            | 0            | 0       | 0          | 0         | Wait for connection

show cluster_version; //查看版本号

unvdb=# show cluster_version;
unvdbcluster_version 
----------------------
 22.4 (UniversalDB)

pcp方式

pcp_node_count 统计后端数据库节点数量

[root@clus-91 ~]# pcp_node_count -U admin -h 192.168.2.98 -p 9898
Password: 
2

pcp_node_info 查看后端数据库节点信息

[root@clus-92 udb-clus]# pcp_node_info -U admin -h 192.168.2.98 -p 9898
Password: 
192.168.2.81 5678 2 0.500000 up up primary primary 0 none none 2022-08-22 17:36:38
192.168.2.82 5678 2 0.500000 up up standby standby 0 none none 2022-08-22 17:36:38

81是主节点,82是从节点

pcp_watchdog_info 看门狗信息

[root@clus-91 ~]# pcp_watchdog_info -U admin -h 192.168.2.98 -p 9898 -v
Password: 
Watchdog Cluster Information 
Total Nodes              : 2  #节点总数
Remote Nodes             : 1  #
Member Remote Nodes      : 1  #成员节点数
Alive Remote Nodes       : 1  #活动节点数
Nodes required for quorum: 1
Quorum state             : QUORUM EXIST
Local node escalation    : YES  
Leader Node Name         : 192.168.2.92:9999 Linux clus-92  #领导者节点
Leader Host Name         : 192.168.2.92
Watchdog Node Information 
Node Name         : 192.168.2.92:9999 Linux clus-92
Host Name         : 192.168.2.92
Delegate IP       : 192.168.2.98
Pgpool port       : 9999
Watchdog port     : 9000
Node priority     : 2
Status            : 4
Status Name       : LEADER
Membership Status : MEMBER
Node Name         : 192.168.2.91:9999 Linux clus-91
Host Name         : 192.168.2.91
Delegate IP       : 192.168.2.98
Pgpool port       : 9999
Watchdog port     : 9000
Node priority     : 2
Status            : 7
Status Name       : STANDBY
Membership Status : MEMBER

pcp_cluster_status 查看配置信息,具体参考 cluster配置 章节

[root@clus-91 ~]# pcp_cluster_status  -U admin -h 192.168.2.91 -p 9898
Password: 
name : backend_clustering_mode
value: 1
desc : clustering mode
name : listen_addresses
value: *
desc : host name(s) or IP address(es) to listen on
name : port
value: 9999
desc : unvdbcluster accepting port number

增加节点

修改配置文件,并重启cluster

backend_hostname0 = '192.168.2.81'
backend_port0 = 5678
backend_weight0 = 1
backend_data_directory0 = '/data/udb'
backend_flag0 = 'ALLOW_TO_FAILOVER'

剔除1号节点

注意:不能用此方式剔除主节点

pcp_detach_node -d -U admin -p 9898 -h 192.168.2.98 -n 1

重新加入0号节点

注:加入前要保证数据完整以及同步已建立

pcp_attach_node -d -U admin -p 9898 -h 192.168.2.98 -n 0
DEBUG: recv: tos="m", len=8
DEBUG: recv: tos="r", len=21
DEBUG: send: tos="C", len=6
DEBUG: recv: tos="c", len=20
pcp_attach_node -- Command Successful
DEBUG: send: tos="X", len=4

pcp_promote_node 提升指定节点为主节点

注:它并不会真正提升节点,只是把cluster内部状态改为主节点。请谨慎操作,否则导致集群不可用。

pcp_recovery_node 以恢复模式加入节点

注:实验阶段,谨慎操作