前期准备
删除DAMENG01.log日志,模拟故障
启动实例失败:
[dmdba@localhost bin]$ ./DmServiceDM start
Starting DmServiceDM: [ FAILED ]
查看日志:
2024-08-09 19:29:59.060 [INFO] database P0000012196 T0000000000000012252 dthrd_info_add nth:93, dthrd_info:0x7fb156753970, thrd_name:dm_osio_thd
2024-08-09 19:29:59.216 [INFO] database P0000012196 T0000000000000012196 Database mode = 0, oguid = 0
2024-08-09 19:29:59.216 [FATAL] database P0000012196 T0000000000000012196 /dmdata/DAMENG/DAMENG01.log not exist,can not startup
查看原实例初始化信息
[dmdba@localhost bin]$ cat /dmdata/DAMENG/dminit20240809111753.log
start init database: V8, 2024-08-09 11:17:53
init params:
db path: /dmdata/DAMENG
db name: DAMENG
auto overwrite: 0
page size: 32768
extent size: 32
char_fix_storage: 0
sql_log_forbid: 0
secur_flag: 2
time zone: +08:00
string case sensitive: 1
charset: 1
page check mode: 3
page check algorithm id: 0
priv flag: 0
env label: 0
rlog enc flag: 0
use new hash: 1
blank pad mode: 1
sec priv mode: 0
huge with delta: 1
rlog gen for huge: 1
pseg_mgr_flag: 0log file path: /dmdata/DAMENG/DAMENG01.log
log file path: /dmdata/DAMENG/DAMENG02.logcreate ini file /dmdata/DAMENG/dm.ini success.
create rlog file /dmdata/DAMENG/DAMENG01.log success.
create rlog file /dmdata/DAMENG/DAMENG02.log success.
SYSTEM file : /dmdata/DAMENG/SYSTEM.DBF
MAIN file : /dmdata/DAMENG/MAIN.DBF
ROLL file : /dmdata/DAMENG/ROLL.DBF
create dm database success. 2024-08-09 11:17:56
[dmdba@localhost bin]$
有备份文件
如果有备份文件,可以重新初始化一个新的数据库(初始化参数要和原库一样,比如页大小、大小写敏感、字符集等,这些可以在 DM 数据库安装路径,../data/DAMENG 目录下以
dminit+日期时间.log
命名的文件中查询),然后将备份文件和归档日志文件拷贝到新的环境,然后再进行备份 + 归档的还原操作。
[dmdba@localhost dmtmp]$ tree /dmdata/dmbak/
/dmdata/dmbak/
└── BACKUP_FILE_01
├── BACKUP_FILE_01.bak
└── BACKUP_FILE_01.meta1 directory, 2 files
初始化一个新实例:
[dmdba@localhost bin]$ ./dminit path=/dmdata/dmtmp page_size=32 extent_size=32 log_size=2048 CASE_SENSITIVE=1 CHARSET=1 BLANK_PAD_MODE=1 initdb V8 db version: 0x7000c License will expire on 2024-12-25 Normal of FAST Normal of DEFAULT Normal of RECYCLE Normal of KEEP Normal of ROLL log file path: /dmdata/dmtmp/DAMENG/DAMENG01.log log file path: /dmdata/dmtmp/DAMENG/DAMENG02.log write to dir [/dmdata/dmtmp/DAMENG]. create dm database success. 2024-08-09 11:29:04
利用备份还原恢复
# 还原 [dmdba@localhost bin]$ ./dmrman CTLSTMT="RESTORE DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' FROM BACKUPSET '/dmdata/dmbak/BACKUP_FILE_01'" dmrman V8 RESTORE DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' FROM BACKUPSET '/dmdata/dmbak/BACKUP_FILE_01' [Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00] restore successfully. time used: 00:00:02.496 # 恢复 [dmdba@localhost bin]$ ./dmrman CTLSTMT="RECOVER DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' FROM BACKUPSET '/dmdata/dmbak/BACKUP_FILE_01'" dmrman V8 RECOVER DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' FROM BACKUPSET '/dmdata/dmbak/BACKUP_FILE_01' recover successfully! time used: 438.265(ms) # 更新 DB_MAGIC [dmdba@localhost bin]$ ./dmrman CTLSTMT="RECOVER DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' UPDATE DB_MAGIC" dmrman V8 RECOVER DATABASE '/dmdata/dmtmp/DAMENG/dm.ini' UPDATE DB_MAGIC recover successfully! time used: 00:00:01.086
注册新实例并启动
没有备份文件
可以通过修改永久魔术值的方式来恢复,但是这种情况下有可能丢失数据。方法如下:
- 重新初始化一个新的数据库,(初始化参数要和原库一样,比如页大小、大小写敏感、字符集等,这些可以在 DM 数据库安装路径,../data/DAMENG 目录下以
dminit+日期时间.log
命名的文件中查询)。 - 将步骤 (1) 中重新初始化的数据库中
DAMENG01.log、DAMENG02.log
文件拷贝到当前丢失 REDO 日志的库目录下。 - 使用 dmmdf 工具获取 SYSTEM.DBF 的 db_magic,并记录下来。
[dmdba@localhost bin]$ ./dmmdf TYPE=1 FILE=/dmdata/DAMENG/SYSTEM.DBF
dmmdf V8
**********************************************************
1 db_magic=1666081164
2 next_trxid=6008
3 pemnt_magic=942891714
4 enable_page_check=3
**********************************************************
Please input which parameter you want to change(1-4), q to quit:
初始化一个新实例:
[dmdba@localhost bin]$ ./dminit path=/dmdata page_size=32 extent_size=32 log_size=2048 CASE_SENSITIVE=1 CHARSET=1 BLANK_PAD_MODE=1 initdb V8 db version: 0x7000c License will expire on 2024-12-25 Normal of FAST Normal of DEFAULT Normal of RECYCLE Normal of KEEP Normal of ROLL log file path: /dmdata/DAMENG/DAMENG01.log log file path: /dmdata/DAMENG/DAMENG02.log write to dir [/dmdata/DAMENG]. create dm database success. 2024-08-12 15:57:38
复制DAMENG01.log到原实例路径下:
[dmdba@localhost DAMENG]$ scp DAMENG01.log dmdba@192.168.192.147:/dmdata/DAMENG
Authorized users only. All activities may be monitored and reported.
dmdba@192.168.192.147's password:
DAMENG01.log 100% 2048MB 105.1MB/s 00:19
[dmdba@localhost DAMENG]$
[dmdba@localhost DAMENG]$ ll /dmdata/DAMENG/
总用量 4749412
drwxr-xr-x 2 dmdba dinstall 6 8月 9 11:17 bak
drwxr-xr-x 2 dmdba dinstall 78 8月 9 11:18 ctl_bak
-rw-r--r-- 1 dmdba dinstall 2147483648 8月 9 11:31 DAMENG01.log
-rw-r--r-- 1 dmdba dinstall 2147483648 8月 9 11:25 DAMENG02.log
-rw-r--r-- 1 dmdba dinstall 5632 8月 9 11:18 dm.ctl
-rw-r--r-- 1 dmdba dinstall 79454 8月 9 11:17 dm.ini
-rw-r--r-- 1 dmdba dinstall 887 8月 9 11:17 dminit20240809111753.log
-rw-r--r-- 1 dmdba dinstall 633 8月 9 11:17 dm_service.prikey
drwxr-xr-x 2 dmdba dinstall 6 8月 9 11:17 HMAIN
-rw-r--r-- 1 dmdba dinstall 134217728 8月 9 11:25 MAIN.DBF
-rw-r--r-- 1 dmdba dinstall 134217728 8月 9 11:25 ROLL.DBF
-rw-r--r-- 1 dmdba dinstall 714 8月 9 11:17 sqllog.ini
-rw-r--r-- 1 dmdba dinstall 222298112 8月 9 11:25 SYSTEM.DBF
-rw-r--r-- 1 dmdba dinstall 77594624 8月 9 11:18 TEMP.DBF
drwxr-xr-x 2 dmdba dinstall 6 8月 9 11:18 trace
DAMENG01.log 文件的 db_magic,原实例的值。
[dmdba@localhost bin]$ ./dmmdf TYPE=2 FILE=/dmdata/DAMENG/DAMENG01.log
dmmdf V8
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 4054151686
4 sta = 0
5 n_magic = 7
6 db_magic = 1006267896
7 len = 2147483648
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 4096
12 pemnt_magic = 942891714
13 fil_id = 0
15 next_seq = 2457
16 g_next_seq = 2457
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000c
20 min_exec_version = V8.1.1.1
21 min_dct_version = 4
22 p_db_magic = 0
23 n_apply_ep = 0
24 apply_info_lsn = 0
pkg_seq_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
apply_lsn_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
25 recv_p_db_magic = 0
26 recv_n_apply_ep = 0
recv_pkg_seq_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
recv_apply_lsn_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
27 l_term_id = 0
28 term_id = 0
29 c_seqno = 0
30 c_lsn = 0
31 rpkg_crc_stand = 1
**********************************************************
You can only reset sta(4) or db_magic (6) or clsn (9) or clsn_fil(10) or clsn_off(11) or pemnt_magic(12) or fil_id(13) or next_seq(15) or g_next_seq(16) or p_db_magic(22) or n_apply_ep(23).
Please input the num which one you want to change, q to quit: 6
Input the new value: 1666081164
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 2836495986
4 sta = 0
5 n_magic = 7
6 db_magic = 1666081164
7 len = 2147483648
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 4096
12 pemnt_magic = 942891714
13 fil_id = 0
15 next_seq = 2457
16 g_next_seq = 2457
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000c
20 min_exec_version = V8.1.1.1
21 min_dct_version = 4
22 p_db_magic = 0
23 n_apply_ep = 0
24 apply_info_lsn = 0
pkg_seq_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
apply_lsn_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
25 recv_p_db_magic = 0
26 recv_n_apply_ep = 0
recv_pkg_seq_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
recv_apply_lsn_arr: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
27 l_term_id = 0
28 term_id = 0
29 c_seqno = 0
30 c_lsn = 0
31 rpkg_crc_stand = 1
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
修改PSEG_RECV参数
如下是修改后的参数PSEG_RECV值为0,跳过回滚活动事务和PURGE已经提交事务。
启动实例
达梦社区地址:https://eco.dameng.com