|PolarDB-O主备高可用部署及切换排雷指引( 七 )
''master'': {
''endpoint'': ''192.168.238.130:5432'',
''data_path'': ''/opt/polardb/data'',
''user'': ''polardb'',
''phase'': ''RUNNING'',
''start_at'': ''2020-11-03 11:37:07''
},
''standby'': [
{
''endpoint'': ''192.168.238.131:5432'',
''data_path'': ''/opt/polardb/data'',
''user'': ''polardb'',
''phase'': ''RUNNING'',
''start_at'': ''2020-11-03 11:37:40'',
''sync_status'': ''SYNC''
}
],
''vip'': [
{
''vip'': ''192.168.238.133'',
''interface'': ''ens33'',
''mask'': ''255.255.255.0'',
''endpoint'': ''192.168.238.130:5432''
}
]
状态为running表示正常 。
5)主库查询同步状态
select * from pg_stat_replication;
Expanded display is on.
polardb=# select * from pg_stat_replication;
-[ RECORD 1 ]----+---------------------------------
pid | 22449
usesysid | 16384
usename | replicator
application_name | standby_3232296579_5432
client_addr | 192.168.238.131
client_hostname |
client_port | 60866
backend_start | 03-NOV-20 13:58:17.811323 +08:00
backend_xmin |
state | streaming
sent_lsn | 0/41BD1648
write_lsn | 0/41BD1648
flush_lsn | 0/41BD1648
replay_lsn | 0/41BD1648
write_lag | 00:00:00.002793
flush_lag | 00:00:00.002801
replay_lag | 00:00:00.003894
sync_priority | 1
sync_state | sync
新插入数据验证下:
polardb=# insert into t1 values (3);
INSERT 0 1
polardb=# select * from t1;
id
----
1 2 3 (3 rows)
7、主备切换
1)手动方式切换
curl -H ''Content-Type:application/json'' -X POST --data ''{''from'':''192.168.238.130:5432'',''to'':''192.168.238.131:5432''}'' http://127.0.0.1:5000/v1/switchover
{''code'':200}
返回结果200为正常 , 500为错误 。
执行如下命令 , 验证主库是否手动切换成功 。
curl -H ''Content-Type:application/json'' http://127.0.0.1:5000/v1/status?type=visual
{
''phase'': ''RunningPhase'',
''master'': {
''endpoint'': ''192.168.238.131:5432'',
''data_path'': ''/opt/polardb/data'',
''user'': ''polardb'',
''phase'': ''RUNNING'',
''start_at'': ''2020-11-03 11:45:15'',
''sync_status'': ''SYNC''
},
''standby'': [
{
''endpoint'': ''192.168.238.130:5432'',
''data_path'': ''/opt/polardb/data'',
''user'': ''polardb'',
''phase'': ''RUNNING'',
''start_at'': ''2020-11-03 11:45:19'',
''sync_status'': ''SYNC''
}
],
''vip'': [
{
''vip'': ''192.168.238.133'',
''interface'': ''ens33'',
''mask'': ''255.255.255.0'',
''endpoint'': ''192.168.238.131:5432''
}
]
}
可以看到master和standby的ip地址互换 , vip也自动漂移到备节点上了 ,
验证一下:
select * from pg_stat_replication;
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start |