DM8 資料守護實時主備搭建

eric0435發表於2022-03-18

資料守護實時主備搭建

下列機器事先都安裝了DM,安裝路徑為’/dm8’,執行程式儲存在’/dm8/bin’目錄中,資料存放路徑為’/dm8/data’。

各主備庫的例項名建議採用“組名_守護環境_序號”的方式命名,方便按組區分不同例項,注意總長度不能超過16。本示例中組名為“GRP1”,配置為實時主備,主庫命名為“GRP1_RT_01”,備庫命名為“GRP1_RT_02”。

機器名     IP地址                  初始狀態                         作業系統
dm209     10.10.13.209(對外)     主庫 dm1                         redhat 7.8
          11.11.11.209(mal對內)
dm210    10.10.13.210(對外)
         11.11.11.210(mal對內)     備庫 dm2                         redhat 7.8
dm211    11.11.11.211            確認監視器                       redhat 7.8
例項名       port_num             mal_inst_dw_port    mal_host              mal_port        mal_dw_port
dm1          5236                 5239                11.11.11.209          5237            5238
dm2          5236                 5239                11.11.11.210          5237            5238

資料準備
在主庫機器上初始化資料庫到目錄/dm8/data:

[dmdba@dm209 dm8]$ dminit path=/dm8/data db_name=dm instance_name=dm1 port_num=5236 page_size=8 charset=0
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2022-10-21
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
 log file path: /dm8/data/dm/dm01.log
 log file path: /dm8/data/dm/dm02.log
write to dir [/dm8/data/dm].
create dm database success. 2022-01-13 10:28:01

註冊服務用於啟動資料庫

[root@dm209 root]# ./dm_service_installer.sh -dm_ini /dm8/data/dm/dm.ini -p dm1 -t dmserver
Created symlink from /etc/systemd/system/multi-user.target.wants/DmServicedm1.service to /usr/lib/systemd/system/DmServicedm1.service.
Finished to create the service (DmServicedm1)

正常啟動資料庫並正常關閉

[root@dm209 root]# service DmServicedm1 start
Redirecting to /bin/systemctl start DmServicedm1.service
[root@dm209 root]# ps -ef | grep dmserver
dmdba    18402     1 17 10:33 ?        00:00:04 /dm8/bin/dmserver path=/dm8/data/dm/dm.ini -noconsole
root     18487  4030  0 10:34 pts/1    00:00:00 grep --color=auto dmserver
[root@dm209 ~]# su - dmdba
Last login: Thu Jan 13 10:16:30 CST 2022 on pts/1
[dmdba@dm209 ~]$ disql SYSDBA/SYSDBA@localhost:5236
Server[localhost:5236]:mode is normal, state is open
login used time : 7.108(ms)
disql V8
SQL> exit
[root@dm209 ~]# service DmServicedm1 stop
Redirecting to /bin/systemctl stop DmServicedm1.service

註冊服務用於將資料庫啟動到mount狀態

[root@dm209 root]# ./dm_service_installer.sh -dm_ini /dm8/data/dm/dm.ini -p dm1mount -t dmserver -m mount
Created symlink from /etc/systemd/system/multi-user.target.wants/DmServicedm1mount.service to /usr/lib/systemd/system/DmServicedm1mount.service.
Finished to create the service (DmServicedm1mountT)

備份主庫
使用聯機備份:

[root@dm209 root]# ./dm_service_installer.sh -t dmap -dm_ini /dm8/data/dm/dm.ini
Created symlink from /etc/systemd/system/multi-user.target.wants/DmAPService.service to /usr/lib/systemd/system/DmAPService.service.
Finished to create the service (DmAPService)
[root@dm209 root]# service DmAPService start
Redirecting to /bin/systemctl start DmAPService.service
SQL> BACKUP DATABASE FULL BACKUPSET '/dm8/data/dm_full_01';
executed successfully
used time: 00:00:02.521. Execute id is 501.

建立備庫備庫並恢復

[dmdba@dm210 data]$ dminit path=/dm8/data db_name=dm instance_name=dm2 port_num=5236 page_size=8 charset=0
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2022-10-21
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
 log file path: /dm8/data/dm/dm01.log
 log file path: /dm8/data/dm/dm02.log
write to dir [/dm8/data/dm].
create dm database success. 2022-01-13 16:02:51

將主庫的備份複製備庫:

[root@dm209 data]# scp -r dm_full_01 10.10.13.210:/dm8/data
root@10.10.13.210's password:
dm_full_01.bak                                                                                                                                                                                           100%   15MB  30.7MB/s   00:00
dm_full_01_1.bak                                                                                                                                                                                         100%  164KB   6.2MB/s   00:00
dm_full_01.meta                                                                                                                                                                                          100%   85KB   3.6MB/s   00:00
[root@dm209 data]#

恢復備庫:

[dmdba@dm210 data]$ dmrman CTLSTMT="RESTORE DATABASE '/dm8/data/dm/dm.ini' FROM BACKUPSET '/dm8/data/dm_full_01'"
dmrman V8
RESTORE DATABASE '/dm8/data/dm/dm.ini' FROM BACKUPSET '/dm8/data/dm_full_01'
file dm.key not found, use default license!
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:06][Remaining:00:00:00]
restore successfully.
time used: 00:00:06.629
[dmdba@dm210 ~]$ dmrman CTLSTMT="RECOVER DATABASE '/dm8/data/dm/dm.ini' FROM BACKUPSET '/dm8/data/dm_full_01'"
dmrman V8
RECOVER DATABASE '/dm8/data/dm/dm.ini' FROM BACKUPSET '/dm8/data/dm_full_01'
file dm.key not found, use default license!
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[25922], file_lsn[25922]
[Percent:100.00%][Speed:0.00PKG/s][Cost:00:00:00][Remaining:00:00:00]
recover successfully!
time used: 00:00:02.895
[dmdba@dm210 ~]$ dmrman CTLSTMT="RECOVER DATABASE '/dm8/data/dm/dm.ini' UPDATE DB_MAGIC"
dmrman V8
RECOVER DATABASE '/dm8/data/dm/dm.ini' UPDATE DB_MAGIC
file dm.key not found, use default license!
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[26568], file_lsn[26568]
recover successfully!
time used: 00:00:01.093

配置操作
一.主庫
配置dm.ini檔案,配置以下引數:

DW_INACTIVE_INTERVAL = 60   #接收守護程式訊息超時時間
ALTER_MODE_STATUS = 0       #不允許手工方式修改例項模式/狀態
ENABLE_OFFLINEi_TS = 2      #不允許備庫OFFLINE表空間
MAL_INI = 1                 #開啟MAL系統
ARCH_INI = 1                #開啟歸檔配置
RLOG_SEND_APPLY_MON = 64    #統計最近64次的日誌傳送資訊

配置dmmal.ini檔案
配置MAL系統,各主備庫的dmmal.ini配置必須完全一致,MAL_HOST使用內部網路IP,MAL_PORT與dm.ini中PORT_NUM使用不同的埠值,MAL_DW_PORT是各例項對應的守護程式之間,以及守護程式和監視器之間的通訊埠,配置如下:

MAL_CHECK_INTERVAL = 5          #MAL鏈路檢測時間間隔
MAL_CONN_FAIL_INTERVAL = 5      #判定MAL鏈路斷開的時間
[MAL_INST1]
MAL_INST_NAME = dm1              #例項名,和dm.ini中的INSTANCE_NAME一致
MAL_HOST = 11.11.11.209          #MAL系統監聽TCP連線的IP地址
MAL_PORT = 5237                  #MAL系統監聽TCP連線的埠
MAL_INST_HOST = 10.10.13.209   #例項的對外服務IP地址
MAL_INST_PORT = 5236             #例項的對外服務埠,和dm.ini中的PORT_NUM一致
MAL_DW_PORT = 5238               #例項本地的守護程式監聽TCP連線的埠
MAL_INST_DW_PORT = 5239          #例項監聽守護程式TCP連線的埠
[MAL_INST2]
MAL_INST_NAME = dm2              #例項名,和dm.ini中的INSTANCE_NAME一致
MAL_HOST = 11.11.11.210          #MAL系統監聽TCP連線的IP地址
MAL_PORT = 5237                  #MAL系統監聽TCP連線的埠
MAL_INST_HOST = 10.10.13.210   #例項的對外服務IP地址
MAL_INST_PORT = 5236             #例項的對外服務埠,和dm.ini中的PORT_NUM一致
MAL_DW_PORT = 5238               #例項本地的守護程式監聽TCP連線的埠
MAL_INST_DW_PORT = 5239          #例項監聽守護程式TCP連線的埠
[dmdba@dm209 dm]$ vi dmmal.ini
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = dm1
MAL_HOST = 11.11.11.209
MAL_PORT = 5237
MAL_INST_HOST = 10.10.13.209
MAL_INST_PORT = 5236
MAL_DW_PORT = 5238
MAL_INST_DW_PORT = 5239
[MAL_INST2]
MAL_INST_NAME = dm2
MAL_HOST = 11.11.11.210
MAL_PORT = 5237
MAL_INST_HOST = 10.10.13.210
MAL_INST_PORT = 5236
MAL_DW_PORT = 5238
MAL_INST_DW_PORT = 5239

配置dmarch.ini
修改dmarch.ini,配置本地歸檔和實時歸檔。除了本地歸檔外,其他歸檔配置項中的ARCH_DEST表示例項是Primary模式時,需要同步歸檔資料的目標例項名。當前例項dm1是主庫,需要向dm2(實時備庫)同步資料,因此實時歸檔的ARCH_DEST配置為DM2。

[ARCHIVE_REALTIME]                                #實時歸檔
ARCH_TYPE = REALTIME                              #實時歸檔型別
ARCH_DEST = dm2                                   #實時歸檔目標例項名
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL                                 #本地歸檔型別
ARCH_DEST = /dm8/data/dm/arch                     #本地歸檔檔案存放路徑
ARCH_FILE_SIZE = 128                              #單位Mb,本地單個歸檔檔案最大值
ARCH_SPACE_LIMIT = 0                              #單位Mb,0表示無限制,範圍1024~4294967294M
[dmdba@dm209 dm]$ vi dmarch.ini
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = dm2
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dm8/data/dm/arch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0

配置dmwatcher.ini
修改dmwatcher.ini配置守護程式,配置為全域性守護型別,使用自動切換模式。

[GRP1]
DW_TYPE = GLOBAL                                         #全域性守護型別
DW_MODE = AUTO                                           #自動切換模式  生產建議設定成手動
DW_ERROR_TIME = 10                                       #遠端守護程式故障認定時間
INST_RECOVER_TIME = 60                                   #主庫守護程式啟動恢復的間隔時間
INST_ERROR_TIME = 10                                     #本地例項故障認定時間
INST_OGUID = 111111                                      #守護系統唯一OGUID值
INST_INI = /dm8/data/dm/dm.ini                       #dm.ini配置檔案路徑
INST_AUTO_RESTART = 1                                    #開啟例項的自動啟動功能(建議設定成0)
INST_STARTUP_CMD = /dm8/bin/dmserver                     #命令列方式啟動
RLOG_SEND_THRESHOLD = 0                                  #指定主庫傳送日誌到備庫的時間閥值,預設關閉
RLOG_APPLY_THRESHOLD = 0                                 #指定備庫重演日誌的時間閥值,預設關閉
[dmdba@dm209 dm]$ vi dmwatcher.ini
[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 111111
INST_INI = /dm8/data/dm/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /dm8/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

以mount模式啟動主庫

[root@dm209 root]# service DmServicedm1 stop
Redirecting to /bin/systemctl stop DmServicedm1.service
[root@dm209 root]# service DmServicedm1mountT start
Redirecting to /bin/systemctl start DmServicedm1mountT.service

設定主庫 OGUID

SQL> sp_set_oguid(111111);
DMSQL executed successfully
used time: 115.044(ms). Execute id is 0.

修改主資料庫模式

SQL> alter database primary;
executed successfully
used time: 80.002(ms). Execute id is 0.

將主庫的dm.ini,dmmal.ini,dmarch.ini,dmwatcher.ini檔案複製到備庫

[root@dm209 dm]# scp dm*.ini 10.10.13.210:/dm8/data/dm
root@10.10.13.210's password:
dmarch.ini                                                                                                                                                                                               100%  346    18.3KB/s   00:00
dm.ini                                                                                                                                                                                                   100%   52KB  29.9MB/s   00:00
dmmal.ini                                                                                                                                                                                                100%  547    16.9KB/s   00:00
dmwatcher.ini                                                                                                                                                                                            100%  568   332.1KB/s   00:00
[root@dm209 dm]#

二備庫
備機修改相關配置
修改dm.ini

INSTANCE_NAME = DM2

dmmal.ini與主庫一致不用修改

修改dmarch.ini

ARCH_DEST = DM1

dmwatcher.ini 和主庫一致

註冊服務用於啟動資料庫到mount狀態

[root@dm210 root]# ./dm_service_installer.sh -dm_ini /dm8/data/dm/dm.ini -p dm2mount -t dmserver -m mount
Created symlink from /etc/systemd/system/multi-user.target.wants/DmServicedm2mount.service to /usr/lib/systemd/system/DmServicedm2mount.service.
Finished to create the service (DmServicedm2mount)

註冊服務用於啟動資料庫

[root@dm210 root]# ./dm_service_installer.sh -dm_ini /dm8/data/dm/dm.ini -p dm2  -t dmserver
Created symlink from /etc/systemd/system/multi-user.target.wants/DmServicedm2.service to /usr/lib/systemd/system/DmServicedm2.service.
Finished to create the service (DmServicedm2)

以mount方式啟動備庫

[root@dm210 root]# service DmServicedm2mount start
Redirecting to /bin/systemctl start DmServicedm2mount.service

設定備庫 OGUID

SQL> sp_set_oguid(111111);
DMSQL executed successfully
used time: 115.044(ms). Execute id is 0.

修改備資料庫模式
如果當前資料庫不是normal模式,需要先修改dm.ini中ALTER_MODE_STATUS值為1,允許修改資料庫模式,修改Standby模式成功後再改回為0。如果是normal模式,請忽略下面的第1步和第3步。

SQL> alter database standby;
alter database standby;
[-720]:Error in line: 1
Dmwatcher is active, or current configuration(ALTER_MODE_STATUS) not allowed to alter database.
used time: 0.636(ms). Execute id is 0.
SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 1);
DMSQL executed successfully
used time: 7.791(ms). Execute id is 1.
SQL> alter database standby;
executed successfully
used time: 94.298(ms). Execute id is 0.
SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 0);
DMSQL executed successfully
used time: 8.414(ms). Execute id is 2.

註冊並啟動守護程式
主庫

[root@dm209 root]# ./dm_service_installer.sh -watcher_ini /dm8/data/dm/dmwatcher.ini -p dw1 -t dmwatcher
Created symlink from /etc/systemd/system/multi-user.target.wants/DmWatcherServicedw1.service to /usr/lib/systemd/system/DmWatcherServicedw1.service.
Finished to create the service (DmWatcherServicedw1)
[root@dm209 root]# service DmWatcherServicedw1 start
Redirecting to /bin/systemctl start DmWatcherServicedw1.service

備庫

[root@dm210 root]# ./dm_service_installer.sh -watcher_ini /dm8/data/dm/dmwatcher.ini -p dw2 -t dmwatcher
Created symlink from /etc/systemd/system/multi-user.target.wants/DmWatcherServicedw2.service to /usr/lib/systemd/system/DmWatcherServicedw2.service.
Finished to create the service (DmWatcherServicedw2)
[root@dm210 root]# service DmWatcherServicedw2 start
Redirecting to /bin/systemctl start DmWatcherServicedw2.service

檢視file_lsn與cur_lsn主備庫是否一致
主庫

[dmdba@dm209 arch]$ disql SYSDBA/SYSDBA
Server[LOCALHOST:5236]:mode is primary, state is mount
login used time : 4.992(ms)
disql V8
SQL> select file_LSN, cur_LSN from v$rlog;
LINEID     FILE_LSN             CUR_LSN
---------- -------------------- --------------------
1          28059                28059
used time: 4.592(ms). Execute id is 700.

備庫

[dmdba@dm210 ~]$ disql SYsDBA/SYSDBA
Server[LOCALHOST:5236]:mode is standby, state is open
login used time : 5.676(ms)
disql V8
SQL> select file_LSN, cur_LSN from v$rlog;
LINEID     FILE_LSN             CUR_LSN
---------- -------------------- --------------------
1          28059                28059
used time: 3.306(ms). Execute id is 200.

配置監視器(基本要求,安裝dm8的軟體)
由於主庫和實時備庫的守護程式配置為自動切換模式,因此這裡選擇配置確認監視器。和普通監視器相比,確認監視器除了相同的命令支援外,在主庫發生故障時,能夠自動通知實時備庫接管為新的主庫,具有自動故障處理的功能。

修改dmmonitor.ini配置確認監視器,其中MON_DW_IP中的IP和PORT和dmmal.ini中的MAL_HOST和MAL_DW_PORT配置項保持一致。

MON_DW_CONFIRM = 1                          #確認監視器模式
MON_LOG_PATH = /dm8/data/log                #監視器日誌檔案存放路徑
MON_LOG_INTERVAL = 60                       #每隔60s定時記錄系統資訊到日誌檔案
MON_LOG_FILE_SIZE = 32                      #每個日誌檔案最大32M
MON_LOG_SPACE_LIMIT = 0                     #不限定日誌檔案總佔用空間
[GRP1]
MON_INST_OGUID = 111111                     #組GRP1的唯一OGUID值
                                            #以下配置為監視器到組GRP1的守護程式的連線資訊,以“IP:PORT”的形式配置
                                            #IP對應dmmal.ini中的MAL_HOST,PORT對應dmmal.ini中的MAL_DW_PORT
MON_DW_IP = 11.11.11.209:5238
MON_DW_IP = 11.11.11.210:5238
[dmdba@dm211 data]$ vi dmmonitor.ini
MON_DW_CONFIRM = 1
MON_LOG_PATH = /dm8/data/log
MON_LOG_INTERVAL = 60
MON_LOG_FILE_SIZE = 32
MON_LOG_SPACE_LIMIT = 0
[GRP1]
MON_INST_OGUID = 111111
MON_DW_IP = 11.11.11.209:5238
MON_DW_IP = 11.11.11.210:5238

啟動監視器:

[dmdba@dm211 data]$ dmmonitor /dm8/data/dmmonitor.ini
[monitor]         2022-01-14 10:43:58: DMMONITOR[4.0] V8
[monitor]         2022-01-14 10:43:58: DMMONITOR[4.0] IS READY.
[monitor]         2022-01-14 10:43:58: Received message from(DM1)
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 10:43:57  OPEN           OK        DM1              OPEN        PRIMARY   VALID    3        28059           28059
[monitor]         2022-01-14 10:43:58: Received message from(DM2)
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 10:43:57  OPEN           OK        DM2              OPEN        STANDBY   VALID    3        28059           28059
show
2022-01-14 10:44:26
#================================================================================#
GROUP            OGUID       MON_CONFIRM     MODE            MPP_FLAG
GRP1             111111      TRUE            AUTO            FALSE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.209        5238         2022-01-14 10:44:24  GLOBAL    VALID     OPEN           DM1              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
10.10.13.209      5236       OK        DM1              OPEN        PRIMARY   0          0            REALTIME  VALID    4264            28059           4264            28059           NONE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.210        5238         2022-01-14 10:44:25  GLOBAL    VALID     OPEN           DM2              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
10.10.13.210      5236       OK        DM2              OPEN        STANDBY   0          0            REALTIME  VALID    4210            28059           4210            28059           NONE
DATABASE(DM2) APPLY INFO FROM (DM1), REDOS_PARALLEL_NUM (1):
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4264, 4264, 4264], (RLSN, SLSN, KLSN)[28059, 28059, 28059], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (28059)
#================================================================================#

或者[root@ora19c root]# ./dm_service_installer.sh -i /dm8/data/dmmonitor.ini -p DM -t dmmonitor

ln -s '/usr/lib/systemd/system/DmMonitorServiceDM.service' '/etc/systemd/system/multi-user.target.wants/DmMonitorServiceDM.service'
Finished to create the service (DmMonitorServiceDM)

使用服務方式啟動不能執行相關命令來顯示監控資訊所以一般不使用

主備同步測試
主庫:

[dmdba@dm209 arch]$ disql SYSDBA/SYSDBA@localhost:5236
Server[localhost:5236]:mode is primary, state is open
login used time : 6.172(ms)
disql V8
SQL> create table t1(id int);
executed successfully
used time: 60.028(ms). Execute id is 800.
SQL> insert into t1 values(1);
affect rows 1
used time: 1.253(ms). Execute id is 801.
SQL> commit;
executed successfully
used time: 2.770(ms). Execute id is 802.
SQL> select * from t1;
LINEID     ID
---------- -----------
1          1
used time: 1.224(ms). Execute id is 803.

備庫:

[dmdba@dm210 ~]$ disql SYSDBA/SYSDBA@localhost:5236
Server[localhost:5236]:mode is standby, state is open
login used time : 5.946(ms)
disql V8
SQL> select * from t1;
LINEID     ID
---------- -----------
1          1
used time: 7.131(ms). Execute id is 300.

主庫:

SQL> update t1 set id=2;
affect rows 1
used time: 1.081(ms). Execute id is 804.
SQL> commit;
executed successfully
used time: 2.552(ms). Execute id is 805.
SQL> select * from t1;
LINEID     ID
---------- -----------
1          2
used time: 0.435(ms). Execute id is 806.

備庫:

SQL> select * from t1;
LINEID     ID
---------- -----------
1          2
used time: 2.014(ms). Execute id is 301.

主備切換測試
操作直接在監控器裡執行。
Switchover 切換

show
2022-01-14 11:15:30
#================================================================================#
GROUP            OGUID       MON_CONFIRM     MODE            MPP_FLAG
GRP1             111111      TRUE            AUTO            FALSE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.209        5238         2022-01-14 11:15:29  GLOBAL    VALID     OPEN           DM1              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
10.10.13.209      5236       OK        DM1              OPEN        PRIMARY   0          0            REALTIME  VALID    4288            28136           4288            28136           NONE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.210        5238         2022-01-14 11:15:29  GLOBAL    VALID     OPEN           DM2              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
10.10.13.210      5236       OK        DM2              OPEN        STANDBY   0          0            REALTIME  VALID    4210            28136           4210            28136           NONE
DATABASE(DM2) APPLY INFO FROM (DM1), REDOS_PARALLEL_NUM (1):
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4288, 4288, 4288], (RLSN, SLSN, KLSN)[28136, 28136, 28136], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (28136)
#================================================================================#
choose switchover grp1
Can choose one of the following instances to do switchover:
1: DM2
switchover grp1.dm2
[monitor]         2022-01-14 11:16:27: Not login dmmonitor or server public key changed, please try to login again!
login
username:SYSDBA
password:
[monitor]         2022-01-14 11:17:03: Login dmmonitor success!
switchover grp1.dm2
[monitor]         2022-01-14 11:17:23: Start to switchover instance DM2
[monitor]         2022-01-14 11:17:23: Notify dmwatcher(DM1) switch to SWITCHOVER status
[monitor]         2022-01-14 11:17:23: Dmwatcher process DM1 status switching [OPEN-->SWITCHOVER]
[monitor]         2022-01-14 11:17:23: Switch dmwatcher DM1 to SWITCHOVER status success
[monitor]         2022-01-14 11:17:23: Notify dmwatcher(DM2) switch to SWITCHOVER status
[monitor]         2022-01-14 11:17:23: Dmwatcher process DM2 status switching [OPEN-->SWITCHOVER]
[monitor]         2022-01-14 11:17:25: Switch dmwatcher DM2 to SWITCHOVER status success
[monitor]         2022-01-14 11:17:25: Instance DM1 start to execute sql SP_SET_GLOBAL_DW_STATUS(0, 6)
[monitor]         2022-01-14 11:17:25: Instance DM1 execute sql SP_SET_GLOBAL_DW_STATUS(0, 6) success
[monitor]         2022-01-14 11:17:25: Instance DM2 start to execute sql SP_SET_GLOBAL_DW_STATUS(0, 6)
[monitor]         2022-01-14 11:17:25: Instance DM2 execute sql SP_SET_GLOBAL_DW_STATUS(0, 6) success
[monitor]         2022-01-14 11:17:25: Instance DM1 start to execute sql ALTER DATABASE MOUNT
[monitor]         2022-01-14 11:17:25: Instance DM1 execute sql ALTER DATABASE MOUNT success
[monitor]         2022-01-14 11:17:25: Instance DM2 start to execute sql SP_APPLY_KEEP_PKG()
[monitor]         2022-01-14 11:17:25: Instance DM2 execute sql SP_APPLY_KEEP_PKG() success
[monitor]         2022-01-14 11:17:25: Instance DM2 start to execute sql ALTER DATABASE MOUNT
[monitor]         2022-01-14 11:17:25: Instance DM2 execute sql ALTER DATABASE MOUNT success
[monitor]         2022-01-14 11:17:25: Instance DM1 start to execute sql ALTER DATABASE STANDBY
[monitor]         2022-01-14 11:17:25: Instance DM1 execute sql ALTER DATABASE STANDBY success
[monitor]         2022-01-14 11:17:25: Instance DM2 start to execute sql ALTER DATABASE PRIMARY
[monitor]         2022-01-14 11:17:26: Instance DM2 execute sql ALTER DATABASE PRIMARY success
[monitor]         2022-01-14 11:17:26: Notify instance DM2 to change all arch status to be invalid
[monitor]         2022-01-14 11:17:26: Succeed to change all instances arch status to be invalid
[monitor]         2022-01-14 11:17:26: Instance DM1 start to execute sql ALTER DATABASE OPEN FORCE
[monitor]         2022-01-14 11:17:26: Instance DM1 execute sql ALTER DATABASE OPEN FORCE success
[monitor]         2022-01-14 11:17:26: Instance DM2 start to execute sql ALTER DATABASE OPEN FORCE
[monitor]         2022-01-14 11:17:26: Instance DM2 execute sql ALTER DATABASE OPEN FORCE success
[monitor]         2022-01-14 11:17:26: Instance DM1 start to execute sql SP_SET_GLOBAL_DW_STATUS(6, 0)
[monitor]         2022-01-14 11:17:26: Instance DM1 execute sql SP_SET_GLOBAL_DW_STATUS(6, 0) success
[monitor]         2022-01-14 11:17:26: Instance DM2 start to execute sql SP_SET_GLOBAL_DW_STATUS(6, 0)
[monitor]         2022-01-14 11:17:26: Instance DM2 execute sql SP_SET_GLOBAL_DW_STATUS(6, 0) success
[monitor]         2022-01-14 11:17:26: Notify dmwatcher(DM1) switch to OPEN status
[monitor]         2022-01-14 11:17:26: Dmwatcher process DM1 status switching [SWITCHOVER-->OPEN]
[monitor]         2022-01-14 11:17:27: Switch dmwatcher DM1 to OPEN status success
[monitor]         2022-01-14 11:17:27: Notify dmwatcher(DM2) switch to OPEN status
[monitor]         2022-01-14 11:17:28: Dmwatcher process DM2 status switching [SWITCHOVER-->OPEN]
[monitor]         2022-01-14 11:17:28: Switch dmwatcher DM2 to OPEN status success
[monitor]         2022-01-14 11:17:28: Notify group(GRP1)'s dmwatcher to do clear
[monitor]         2022-01-14 11:17:29: Clean request of dmwatcher processer DM1 success
[monitor]         2022-01-14 11:17:29: Clean request of dmwatcher processer DM2 success
[monitor]         2022-01-14 11:17:29: Switchover instance DM2 success
2022-01-14 11:17:29
#================================================================================#
GROUP            OGUID       MON_CONFIRM     MODE            MPP_FLAG
GRP1             111111      TRUE            AUTO            FALSE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.210        5238         2022-01-14 11:17:28  GLOBAL    VALID     OPEN           DM2              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
10.10.13.210      5236       OK        DM2              OPEN        PRIMARY   0          0            REALTIME  VALID    4289            29494           4289            29494           NONE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.209        5238         2022-01-14 11:17:28  GLOBAL    VALID     OPEN           DM1              OK        1     1     OPEN        STANDBY   DSC_OPEN       REALTIME  INVALID
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
10.10.13.209      5236       OK        DM1              OPEN        STANDBY   0          0            REALTIME  INVALID  4288            28136           4288            28136           NONE
DATABASE(DM1) APPLY INFO FROM (DM2), REDOS_PARALLEL_NUM (1):
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4288, 4288, 4288], (RLSN, SLSN, KLSN)[28136, 28136, 28136], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (28136)
#================================================================================#
[monitor]         2022-01-14 11:17:30: Dmwatcher process DM2 status switching [OPEN-->RECOVERY]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 11:17:30  RECOVERY       OK        DM2              OPEN        PRIMARY   VALID    4        29494           29494
[monitor]         2022-01-14 11:17:33: Dmwatcher process DM2 status switching [RECOVERY-->OPEN]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 11:17:32  OPEN           OK        DM2              OPEN        PRIMARY   VALID    4        29494           29494

Takeover 接管

choose takeover grp1
Group(grp1) has active primary instance, not get standby instance list any more!

將主庫網路直接中斷:

[root@dm210 data]# systemctl stop network
#此時可以接管了:
[monitor]         2022-01-14 14:36:50: Received message timeout from(DM2)
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:36:39  ERROR          OK        DM2              OPEN        PRIMARY   VALID    4        29501           29501
[monitor]         2022-01-14 14:36:51: Check primary instance error in group(GRP1), start to auto takeover
[monitor]         2022-01-14 14:36:51: Notify group(GRP1)'s active dmwatcher to set MID
[monitor]         2022-01-14 14:36:51: Notify group(GRP1)'s active dmwatcher to set MID success
[monitor]         2022-01-14 14:36:51: Start to takeover use instance DM1
[monitor]         2022-01-14 14:36:51: Notify dmwatcher(DM1) switch to TAKEOVER status
[monitor]         2022-01-14 14:36:51: Dmwatcher process DM1 status switching [OPEN-->TAKEOVER]
[monitor]         2022-01-14 14:36:52: Switch dmwatcher DM1 to TAKEOVER status success
[monitor]         2022-01-14 14:36:52: Instance DM1 start to execute sql SP_SET_GLOBAL_DW_STATUS(0, 7)
[monitor]         2022-01-14 14:36:52: Instance DM1 execute sql SP_SET_GLOBAL_DW_STATUS(0, 7) success
[monitor]         2022-01-14 14:36:52: Instance DM1 start to execute sql SP_APPLY_KEEP_PKG()
[monitor]         2022-01-14 14:36:52: Instance DM1 execute sql SP_APPLY_KEEP_PKG() success
[monitor]         2022-01-14 14:36:52: Instance DM1 start to execute sql ALTER DATABASE MOUNT
[monitor]         2022-01-14 14:36:52: Instance DM1 execute sql ALTER DATABASE MOUNT success
[monitor]         2022-01-14 14:36:52: Instance DM1 start to execute sql ALTER DATABASE PRIMARY
[monitor]         2022-01-14 14:36:53: Instance DM1 execute sql ALTER DATABASE PRIMARY success
[monitor]         2022-01-14 14:36:53: Notify instance DM1 to change all arch status to be invalid
[monitor]         2022-01-14 14:36:53: Succeed to change all instances arch status to be invalid
[monitor]         2022-01-14 14:36:53: Instance DM1 start to execute sql ALTER DATABASE OPEN FORCE
[monitor]         2022-01-14 14:36:53: Instance DM1 execute sql ALTER DATABASE OPEN FORCE success
[monitor]         2022-01-14 14:36:53: Instance DM1 start to execute sql SP_SET_GLOBAL_DW_STATUS(7, 0)
[monitor]         2022-01-14 14:36:53: Instance DM1 execute sql SP_SET_GLOBAL_DW_STATUS(7, 0) success
[monitor]         2022-01-14 14:36:53: Notify dmwatcher(DM1) switch to OPEN status
[monitor]         2022-01-14 14:36:54: Dmwatcher process DM1 status switching [TAKEOVER-->OPEN]
[monitor]         2022-01-14 14:36:54: Switch dmwatcher DM1 to OPEN status success
[monitor]         2022-01-14 14:36:54: Notify group(GRP1)'s dmwatcher to do clear
[monitor]         2022-01-14 14:36:54: Clean request of dmwatcher processer DM1 success
[monitor]         2022-01-14 14:36:54: Success to takeover use instance DM1
[monitor]         2022-01-14 14:36:54: Group(GRP1) use instance DM1 auto takeover success

恢復DW環境
恢復原主庫的網路後,監視器自動將原主庫切換成了備庫:

[monitor]         2022-01-14 14:42:19: Dmwatcher process DM2 status switching [NONE-->MON CONFIRM]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:19  MON CONFIRM    OK        DM2              SUSPEND     PRIMARY   VALID    4        29501           29501
[monitor]         2022-01-14 14:42:21: Dmwatcher process DM2 status switching [MON CONFIRM-->STARTUP]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:20  STARTUP        OK        DM2              SUSPEND     PRIMARY   VALID    4        29501           29501
[monitor]         2022-01-14 14:42:23: Instance DM2[PRIMARY, SUSPEND, ISTAT_SAME:TRUE] error
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:22  STARTUP        ERROR     DM2              SUSPEND     PRIMARY   VALID    4        29501           29501
[monitor]         2022-01-14 14:42:35: Instance DM2[STANDBY, MOUNT, ISTAT_SAME:TRUE] recover to OK
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:35  STARTUP        OK        DM2              MOUNT       STANDBY   INVALID  4        29501           29501
[monitor]         2022-01-14 14:42:36: Dmwatcher process DM2 status switching [STARTUP-->OPEN]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:36  OPEN           OK        DM2              OPEN        STANDBY   INVALID  4        29501           29501
[monitor]         2022-01-14 14:42:40: Dmwatcher process DM1 status switching [OPEN-->RECOVERY]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:39  RECOVERY       OK        DM1              OPEN        PRIMARY   VALID    5        30859           30859
[monitor]         2022-01-14 14:42:43: Dmwatcher process DM1 status switching [RECOVERY-->OPEN]
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 14:42:42  OPEN           OK        DM1              OPEN        PRIMARY   VALID    5        30859           30859
show
2022-01-14 14:43:05
#================================================================================#
GROUP            OGUID       MON_CONFIRM     MODE            MPP_FLAG
GRP1             111111      TRUE            AUTO            FALSE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.209        5238         2022-01-14 14:43:03  GLOBAL    VALID     OPEN           DM1              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
10.10.13.209      5236       OK        DM1              OPEN        PRIMARY   0          0            REALTIME  VALID    4359            30859           4359            30859           NONE
< >
DW_IP               MAL_DW_PORT  WTIME                WTYPE     WCTLSTAT  WSTATUS        INAME            INST_OK   N_EP  N_OK  ISTATUS     IMODE     DSC_STATUS     RTYPE     RSTAT
11.11.11.210        5238         2022-01-14 14:43:03  GLOBAL    VALID     OPEN           DM2              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
10.10.13.210      5236       OK        DM2              OPEN        STANDBY   0          0            REALTIME  VALID    4356            30859           4356            30859           NONE
DATABASE(DM2) APPLY INFO FROM (DM1), REDOS_PARALLEL_NUM (1):
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4359, 4359, 4359], (RLSN, SLSN, KLSN)[30859, 30859, 30859], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (30859)
#================================================================================#

DW 環境啟動與關閉測試
因為Global 守護型別的守護程式,會自動將資料庫例項切換到 Open 狀態,並將守護程式狀態也切換為 Open。因此在關閉DW系統時,必須按照一定的順序來關閉守護程式和例項。

可以在監視器中執行 Stop Instance 命令關閉資料守護系統,命令執行成功後,資料庫例項正常關閉。但守護程式並沒有真正退出,而是將狀態切換為Shutdown 狀態。

如果使用手動方式關閉資料守護系統,請嚴格按照以下順序:

1) 如果啟動了確認監視器,先關閉確認監視器(防止自動接管)
2) 關閉主庫守護程式(防止重啟例項)
3) 關閉備庫守護程式(防止重啟例項)

在關閉守護程式時會自動關閉對應的DM例項。 所以我們這裡只需要關閉對應的守護程式即可。

關閉DW 環境
我們這裡使用手工方式關閉DW.
1.關閉監視器程式
直接ctrl + c 結束命令即可。

2.關閉主庫守護程式

[root@dm209 root]# systemctl stop DmWatcherServicedw1
[root@dm209 root]# ps -ef|grep dm.ini
root      4515 18565  0 15:16 pts/1    00:00:00 grep --color=auto dm.ini

3.關閉備庫守護程式

[root@dm210 log]# service DmWatcherServicedw2 stop
Redirecting to /bin/systemctl stop DmWatcherServicedw2.service
[root@dm210 log]# ps -ef | grep dm.ini
root      3725 20825  0 15:16 pts/2    00:00:00 grep --color=auto dm.ini

啟動DW環境
啟動備庫守護程式

[root@dm210 log]# service DmWatcherServicedw2 start
Redirecting to /bin/systemctl start DmWatcherServicedw2.service
[root@dm210 log]# ps -ef | grep dm.ini
dmdba     3795     1  1 15:18 ?        00:00:00 /dm8/bin/dmserver /dm8/data/dm/dm.ini mount
root      3887 20825  0 15:18 pts/2    00:00:00 grep --color=auto dm.ini

啟動守護程式時會自動啟動DM 例項。

啟動主庫守護程式

[root@dm209 root]# service DmWatcherServicedw1 start
Redirecting to /bin/systemctl start DmWatcherServicedw1.service
[root@dm209 root]# ps -ef|grep dm.ini
dmdba     4598     1  0 15:20 ?        00:00:00 /dm8/bin/dmserver /dm8/data/dm/dm.ini mount
root      4713 18565  0 15:21 pts/1    00:00:00 grep --color=auto dm.ini

啟動監視器

[dmdba@dm211 data]$ dmmonitor /dm8/data/dmmonitor.ini
[monitor]         2022-01-14 15:43:58: DMMONITOR[4.0] V8
[monitor]         2022-01-14 15:43:58: DMMONITOR[4.0] IS READY.
[monitor]         2022-01-14 15:43:58: Received message from(DM1)
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 15:43:57  OPEN           OK        DM1              OPEN        PRIMARY   VALID    3        30859           30859
[monitor]         2022-01-14 15:43:58: Received message from(DM2)
                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN
                  2022-01-14 15:43:57  OPEN           OK        DM2              OPEN        STANDBY   VALID    3        30859           30859


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2872374/,如需轉載,請註明出處,否則將追究法律責任。

相關文章