1、概述
本文描述了达梦数据库重做日志(即REDO日志)误删后的修复方法。
2、重做日志
重做日志(即 REDO 日志)指在 DM 数据库中添加、删除、修改对象,或者改变数据,
DM 都会按照特定的格式,将这些操作执行的结果写入到当前的重做日志文件中。重做日志文件以 log 为扩展名。每个 DM 数据库实例必须至少有 2 个重做日志文件,默认两个日志文件为 DAMENG01.log、DAMENG02.log,这两个文件循环使用。
重做日志文件因为是数据库正在使用的日志文件,因此被称为联机日志文件。
重做日志文件主要用于数据库的备份与恢复。理想情况下,数据库系统不会用到重做日志文件中的信息。然而现实世界总是充满了各种意外,比如电源故障、系统故障、介质故障,或者数据库实例进程被强制终止等,数据库缓冲区中的数据页会来不及写入数据文件。这样,在重启 DM 实例时,通过重做日志文件中的信息,就可以将数据库的状态恢复到发生意外时的状态。
重做日志文件对于数据库是至关重要的。它们用于存储数据库的事务日志,以便系统在出现系统故障和介质故障时能够进行故障恢复。在 DM 数据库运行过程中,任何修改数据库的操作都会产生重做日志,例如,当一条元组插入到一个表中的时候,插入的结果写入了重做日志,当删除一条元组时,删除该元组的事实也被写了进去,这样,当系统出现故障时,通过分析日志可以知道在故障发生前系统做了哪些动作,并可以重做这些动作使系统恢复到故障之前的状态。
3、操作过程
3.1、构造业务数据
SQL> CREATE TABLESPACE "TBS_TEST" DATAFILE '/dm8/data/DAMENG/TBS01.DBF' SIZE 128 AUTOEXTEND ON NEXT 100 MAXSIZE 1024;
操作已执行
已用时间: 56.900(毫秒). 执行号:700.
SQL> CREATE USER "SHEN" IDENTIFIED BY "Dameng123" DEFAULT TABLESPACE "TBS_TEST";
操作已执行
已用时间: 5.503(毫秒). 执行号:701.
SQL> GRANT RESOURCE TO SHEN;
操作已执行
已用时间: 1.947(毫秒). 执行号:702.
SQL> conn shen/Dameng123;
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间 : 1.887(ms)
SQL> create table TEST (id int,name varchar(20));
操作已执行
已用时间: 13.115(毫秒). 执行号:800.
SQL> begin
for i in 1..1000 loop
insert into TEST(id, name)
values(i, DBMS_RANDOM.RANDOM_STRING('U',5)||':'|| lpad(i,4, '0'));
end loop;
end;
/2 3 4 5 6 7
DMSQL 过程已成功完成
已用时间: 27.629(毫秒). 执行号:801.
SQL> select count(*) from TEST;
行号 COUNT(*)
------- --------------------
1 1000
已用时间: 1.214(毫秒). 执行号:802.
SQL>
3.2、模拟误删redo日志文件
[dmdba@DM8 DAMENG]$ rm -rf DAMENG02.log
3.3、重启数据库服务
[dmdba@DM8 ~]$ DmServiceDMSERVER stop
Stopping DmServiceDMSERVER: [ OK ]
[dmdba@DM8 ~]$ DmServiceDMSERVER start
Starting DmServiceDMSERVER: [ FAILED ]
file dm.key not found, use default license!
version info: develop
DM Database Server 64 V8 03134283890-20220525-161267-10045 startup...
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
Database mode = 0, oguid = 0
/dm8/data/DAMENG/DAMENG02.log not exist, can not startup
重启数据库服务报错DAMENG02.log日志文件不存在,无法启动。
3.4、查看初始化参数信息
[dmdba@DM8 ~]$ cat /dm8/data/DAMENG/dminit20220625212830.log
start init database: V8, 2022-06-25 21:28:30
init params:
db path: /dm8/data/DAMENG
db name: DAMENG
auto overwrite: 0
page size: 8192
extent size: 16
char_fix_storage: 0
sql_log_forbid: 0
secur_flag: 2
time zone: +08:00
string case sensitive: 1
charset: 0
length in char: 0
page check mode: 0
page check algorithm id: 0
priv flag: 0
rlog enc flag: 0
use new hash: 1
blank pad mode: 0
sec priv mode: 0
huge with delta: 1
rlog gen for huge: 0
pseg_mgr_flag: 0
log file path: /dm8/data/DAMENG/DAMENG01.log
log file path: /dm8/data/DAMENG/DAMENG02.log
3.5、初始化新库
[dmdba@DM8 data]$ dminit db_name=dmdb instance_name=dmdb path=/dm8/data page_size=8 extent_size=16 charset=0 length_in_char=0
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2023-05-25
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
log file path: /dm8/data/dmdb/dmdb01.log
log file path: /dm8/data/dmdb/dmdb02.log
write to dir [/dm8/data/dmdb].
create dm database success. 2023-03-28 01:47:42
3.6、启动新初始化的库
[dmdba@DM8 dmdb]$ dmserver dm.ini
file dm.key not found, use default license!
version info: develop
DM Database Server 64 V8 03134283890-20220525-161267-10045 startup...
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
Database mode = 0, oguid = 0
License will expire on 2023-05-25
file lsn: 0
ndct db load finished
ndct second level fill fast pool finished
ndct third level fill fast pool finished
ndct second level fill fast pool finished
ndct third level fill fast pool finished
ndct fill fast pool finished
iid page's trxid[1002]
NEXT TRX ID = 1003
pseg_collect_mgr_items, total collect 0 active_trxs, 0 cmt_trxs, 0 pre_cmt_trxs, 0 to_release_trxs, 0 active_pages, 0 cmt_pages, 0 pre_cmt_pages, 0 to_release_pages, 0 mgr pages, 0 mgr recs!
iid page's trxid[2004]
NEXT TRX ID = 3006.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
trx: 3006 purged 1 pages
trx: 3025 purged 1 pages
trx: 3026 purged 1 pages
trx: 3027 purged 1 pages
trx: 3028 purged 1 pages
trx: 3029 purged 1 pages
trx: 3039 purged 1 pages
trx: 3159 purged 1 pages
trx: 3172 purged 1 pages
trx: 3173 purged 1 pages
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
SYSTEM IS READY.
3.7、修改原库PSEG_RECV参数
[dmdba@DM8 DAMENG]$ vim dm.ini
PSEG_RECV=0
3.8、拷贝新初始化实例的日志到旧库
[dmdba@DM8 dmdb]$ cp dmdb02.log /dm8/data/DAMENG/DAMENG02.log
3.9、查看原库SYSTEM文件中的值
[dmdba@DM8 DAMENG]$ dmmdf TYPE=1 FILE=SYSTEM.DBF
dmmdf V8
**********************************************************
1 db_magic=1413895244
2 next_trxid=5010
3 pemnt_magic=201885426
**********************************************************
3.10、修改redo日志db_magic的值
[dmdba@DM8 DAMENG]$ dmmdf TYPE=2 FILE=DAMENG02.log
dmmdf V8
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 3587120004
4 sta = 0
5 n_magic = 7
6 db_magic = 424454352
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 405435978
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
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
**********************************************************
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: 1413895244
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 2563106584
4 sta = 0
5 n_magic = 7
6 db_magic = 1413895244
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 405435978
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
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
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
3.11、修改redo日志pemnt_magic的值
[dmdba@DM8 DAMENG]$ dmmdf TYPE=2 FILE=DAMENG02.log
dmmdf V8
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 2563106584
4 sta = 0
5 n_magic = 7
6 db_magic = 1413895244
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 405435978
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
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
**********************************************************
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: 12
Input the new value: 201885426
**********************************************************
1 sig = DMRLOG
2 ver = 7007
3 chksum = 2363955104
4 sta = 0
5 n_magic = 7
6 db_magic = 1413895244
7 len = 268435456
8 free = 4096
9 clsn = 0
10 clsn_fil = 0
11 clsn_off = 0
12 pemnt_magic = 201885426
13 fil_id = 1
15 next_seq = 0
16 g_next_seq = 0
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
**********************************************************
Do you want to quit and save the change to file (y/n): y
Save to file success!
3.12、启动原库
[dmdba@DM8 DAMENG]$ dmserver dm.ini
file dm.key not found, use default license!
version info: develop
DM Database Server 64 V8 03134283890-20220525-161267-10045 startup...
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
Database mode = 0, oguid = 0
License will expire on 2023-05-25
file lsn: 51825
ndct db load finished
ndct second level fill fast pool finished
ndct third level fill fast pool finished
ndct second level fill fast pool finished
ndct third level fill fast pool finished
ndct fill fast pool finished
iid page's trxid[6011]
NEXT TRX ID = 6012
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
SYSTEM IS READY.
3.13、验证业务数据
SQL> SELECT COUNT(*) FROM SHEN.TEST;
行号 COUNT(*)
------ --------------------
1 1000
已用时间: 28.508(毫秒). 执行号:1100.
更多学习资料请访问:https://eco.dameng.com
最后修改时间:2023-03-29 19:22:25
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




