一、实验场景
当redo log被意外删除,且如果没有备份时,数据库已经无法正常处理事务。
二、还原方法
此时可以重新初始化一个数据库,初始化参数要和原库一样,比如页大小、大小写敏感、字符集等,并通过修改永久魔术值的方式来恢复,但是这种情况下有可能丢失数据。
1)重新初始化一个库,相关参数可以在达梦数据目录下的dminit+日期时间.log的一个文件中查询。
[dmdba@rac01 bin]$ ./dminit PATH=/dm/5237/TESTDB CASE_SENSITIVE=1 PAGE_SIZE=32 EXTENT_SIZE=32 CHARSET=1 PORT_NUM=5237 DB_NAME=TESTDB
2)将重新初始化的TESTDB01.log、TESTDB02.log拷贝到当前丢失redo日志的库目录下。
3)使用dmmdf工具获取SYSTEM.DBF的db_magic,并记录下来
dmmdf工具说明:
[dmdba@rac02 bin]$ ./dmmdf help
格式: ./dmmdf KEYWORD=value
例程: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.DBF
关键字 说明
--------------------------------------------------------------------------------
TYPE 类型
1表示dbf
2表示rlog
3表示original bak
4表示bakset meta
5表示bakset bkp
6表示bakset
7表示数据库降级:
SCOPE=1,表示仅支持0x0007000A降级到0x00070009,FILE指定为dm.ctl路径
SCOPE=2,表示仅支持0x0007000B降级到0x0007000A,FILE指定为dm.ini路径
8表示联机日志降级(仅支持0x7006降级到0x7005)
9表示特定版本的数据库升级(仅支持执行码版本号在[V8.1.1.88(V7.1.7.88), V8.1.1.100(V7.1.7.100)]范围内的数据库升级)
FILE 文件路径
DCR_INI dmdcr.ini路径
DFS_INI dmdfs.ini路径
SCOPE TYPE=7时使用,指定具体的降级范围
HELP 打印帮助信息
--------------------------------------------------
示例: ./dmmdf TYPE=1 FILE=/opt/data/DAMENG/SYSTEM.dbf
./dmmdf TYPE=2 FILE=/opt/data/DAMENG/DAMENG01.log
./dmmdf TYPE=3 FILE=/opt/data/DAMENG/bak/dmdb.bak
./dmmdf TYPE=4 FILE=/opt/data/DAMENG/bak/bset/nbak.meta
./dmmdf TYPE=5 FILE=/opt/data/DAMENG/bak/bset/nbak.bak
./dmmdf TYPE=6 FILE=/opt/data/DAMENG/bak/bset
./dmmdf TYPE=7 SCOPE=1 FILE=/opt/data/DAMENG/dm.ctl
./dmmdf TYPE=7 SCOPE=2 FILE=/opt/data/DAMENG/dm.ini
./dmmdf TYPE=8 FILE=/opt/data/DAMENG/dm.ini
./dmmdf TYPE=9 FILE=/opt/data/DAMENG/dm.ini
记录SYSTEM.DBF数据文件的db_magic的值
4)修改拷贝来的TESTDB01.log、TESTDB02.log文件的db_magic
[dmdba@rac02 bin]$ ./dmmdf TYPE=2 FILE=/dm/5237/TESTDB/TESTDB01.log
dmmdf V8
**********************************************************
1 sig = DMRLOG
2 ver = 7006
3 chksum = 478203869
4 sta = 1
5 n_magic = 7
6 db_magic = 1642492576
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 4096
12 pemnt_magic = 1259669528
13 fil_id = 0
15 next_seq = 2457
16 g_next_seq = 2457
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000b
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)
**********************************************************
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(20) or n_apply_ep(21).
Please input the num which one you want to change, q to quit: 6
Input the new value: 2088374559
**********************************************************
1 sig = DMRLOG
2 ver = 7006
3 chksum = 18656354
4 sta = 1
5 n_magic = 7
6 db_magic = 2088374559
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 4096
12 pemnt_magic = 1259669528
13 fil_id = 0
15 next_seq = 2457
16 g_next_seq = 2457
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000b
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)
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
[dmdba@rac02 bin]$ ./dmmdf TYPE=2 FILE=/dm/5237/TESTDB/TESTDB02.log
dmmdf V8
**********************************************************
1 sig = DMRLOG
2 ver = 7006
3 chksum = 92327902
4 sta = 0
5 n_magic = 7
6 db_magic = 1642492576
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 1259669528
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000b
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)
**********************************************************
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(20) or n_apply_ep(21).
Please input the num which one you want to change, q to quit: 6
Input the new value: 2088374559
**********************************************************
1 sig = DMRLOG
2 ver = 7006
3 chksum = 404532321
4 sta = 0
5 n_magic = 7
6 db_magic = 2088374559
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 1259669528
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
17 arch_lsn = 0
18 arch_seq = 0
19 dbversion = 0x7000b
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)
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
三、启动数据库并验证
[dmdba@rac02 bin]$ /etc/rc.d/init.d/DmServiceTESTDB start
Starting DmServiceTESTDB: [ OK ]
[dmdba@rac02 bin]$ ./disql sysdba/SYSDBA:5237
服务器[LOCALHOST:5237]:处于普通打开状态
登录使用时间 : 29.769(ms)
disql V8
SQL> select instance_name,status$ from v$instance;
行号 INSTANCE_NAME STATUS$
---------- ------------- -------
1 TESTDB OPEN
已用时间: 1.571(毫秒). 执行号:402.
SQL> select * from v$rlogfile;
行号 GROUP_ID FILE_ID PATH CLIENT_PATH CREATE_TIME RLOG_SIZE MIN_EXEC_VER MIN_DCT_VER
---------- ----------- ----------- ---------------------------- ------------ -------------------------- -------------------- ------------ -----------
1 2 0 /dm/5237/TESTDB/TESTDB01.log TESTDB01.log 2021-03-03 17:58:40.000000 268435456 V8.1.1.1 4
2 2 1 /dm/5237/TESTDB/TESTDB02.log TESTDB02.log 2021-03-03 17:58:40.000000 268435456 V8.1.1.1 4
已用时间: 126.913(毫秒). 执行号:400.