达梦数据库主从切换(takeover)
环境:
OS:Centos 7
DB:V8
1.手工执行监控器
[dmdba@host02 DAMENG]$ dmmonitor /dmdbms/data/DAMENG/dmmonitor.ini
login
username:sysdba
password:
[monitor] 2024-03-25 09:54:55: Login dmmonitor success!
choose takeover GRP1
Group(grp1) has active primary instance, not get standby instance list any more!
我这里主从目前是正常的,所以takeover不能使用
2.查看当前主库
[dmdba@host02 DAMENG]$ dmmonitor /dmdbms/data/DAMENG/dmmonitor.ini
login
username:sysdba
password:
[monitor] 2024-03-25 09:54:55: Login dmmonitor success!
show
2024-03-25 09:56:15
#================================================================================#
GROUP OGUID MON_CONFIRM MODE MPP_FLAG
GRP1 453332 TRUE AUTO FALSE
<<DATABASE GLOBAL INFO:>>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.1.101 52141 2024-03-25 09:56:14 GLOBAL VALID OPEN DAMENG OK 1 1 OPEN PRIMARY DSC_OPEN REALTIME VALID
EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.1.101 5236 OK DAMENG OPEN PRIMARY 0 0 REALTIME VALID 5554 48915 5554 48915 NONE
<<DATABASE GLOBAL INFO:>>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.1.104 52141 2024-03-25 09:56:15 GLOBAL VALID OPEN DAMENGBAK OK 1 1 OPEN STANDBY DSC_OPEN REALTIME VALID
EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.1.104 5236 OK DAMENGBAK OPEN STANDBY 0 0 REALTIME VALID 5554 48915 5554 48915 NONE
DATABASE(DAMENGBAK) APPLY INFO FROM (DAMENG), REDOS_PARALLEL_NUM (1), WAIT_APPLY[FALSE]:
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[5554, 5554, 5554], (RLSN, SLSN, KLSN)[48915, 48915, 48915], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (48915)
主库是192.168.1.101
3.关闭监视器服务
systemctl stop DmMonitorServiceMonitor
4.对主库进行down机
我这里直接关闭机器电源
5.查看当前从库的状态
[dmdba@host02 DAMENG]$ disql hxl/dameng123
Server[LOCALHOST:5236]:mode is standby, state is open
login used time : 3.156(ms)
disql V8
SQL> select status$,mode$ from v$instance;
LINEID status$ mode$
---------- ------- -------
1 OPEN STANDBY
used time: 41.738(ms). Execute id is 501.
6.手工启动监视器进程进行切换
手工启动监视服务器的,有配置监视服务器配置文件dmmonitor.ini即可
[dmdba@host02 arch]$ dmmonitor /dmdbms/data/DAMENG/dmmonitor.ini
[monitor] 2024-03-25 10:09:26: DMMONITOR[4.0] V8
[monitor] 2024-03-25 10:09:28: DMMONITOR[4.0] IS READY.
login ##输入该命令
username:sysdba
password:
[monitor] 2024-03-25 10:10:05: Login dmmonitor success!
choose takeover GRP1 ##输入该命令
no database can do takeover!
choose switchover GRP1 ##输入该命令
no instance can do switchover!
show global info
takeover GRP1.DAMENGBAK ##输入该命令
[monitor] 2024-03-25 10:22:33: Get instance(DAMENGBAK)'s PRIMARY instance info failed(instance DAMENGBAK has not received any archive message from PRIMARY instance)
takeover force GRP1.DAMENGBAK ##输入该命令,强制接管 takeover force 组名.实例名
Be careful to do so, this operation may cause data split, please confirm to continue or not(Y/N)?
提示会出现脑裂,这种情况下的需要重新部署主从.
这个时候数据库的状态:
SQL> select status$,mode$ from v$instance;
LINEID status$ mode$
---------- ------- -------
1 OPEN PRIMARY
used time: 0.638(ms). Execute id is 502.
7.启动原来的主库
原来的主库开机后查看数据库状态
[dmdba@host01 ~]$ disql hxl/dameng123
Server[LOCALHOST:5236]:mode is standby, state is open
login used time : 3.937(ms)
disql V8
SQL> select status$,mode$ from v$instance;
LINEID status$ mode$
---------- ------- -------
1 OPEN STANDBY
used time: 14.153(ms). Execute id is 1
这里自动变成了主库,说明上面的操作没有发生脑裂,主从关系正常.