View Oracle archive status
docker exec -it oracle /bin/bash
# 登陆数据库
sqlplus
# 查看归档状态
archive log list;
Turn on Oracle archiving
-- 关闭数据库
shutdown immediate;
-- 启动数据库至mount状态
startup mount;
alter database archivelog;
alter database open;
archive log list;
Enable additional logs
If additional logging is not enabled, incremental records cannot be recorded.
# 表级别开启附加日志
alter table 用户名.表名 add supplemental log data(all) columns;
# 库级别开启附加日志
alter database add supplemental log data(all) columns;
alter database add supplemental log data;
Use LOGMNR to view incremental data
The parsing dictionary used here is an online parsing dictionary, which can omit multiple operation steps.
Get the log file to parse
select member from v$logfile;
It is also possible to obtain only the current log file here, but there may be cases where the increments are unevenly distributed and the obtained increments are lost.
SQL> SELECT member from v$logfile where group# = (SELECT group# as g FROM v$log where status = 'CURRENT');
Add log file
The first log file added needs to be used options=>dbms_logmnr.NEW
, subsequent log files useoptions=>dbms_logmnr.ADDFILE
SQL>EXEC dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/oradata/xe/redo03.log',options=>dbms_logmnr.NEW);
SQL>EXEC dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/oradata/xe/redo02.log',options=>dbms_logmnr.ADDFILE);
SQL>EXEC dbms_logmnr.add_logfile(logfilename=>'/u01/app/oracle/oradata/xe/redo01.log',options=>dbms_logmnr.ADDFILE);
Start log parsing
The current scn can be obtained through select current_scn from v$database
, or can be obtained from the number of incremental records queried.
SQL> EXEC dbms_logmnr.start_logmnr(options=>dbms_logmnr.DICT_FROM_ONLINE_CATALOG, startScn=>xxxx, endScn=>xxxx);
Read incremental records
-- seg_name为表名,sql_redo为增量记录的原生SQL语句
SQL> SELECT seg_name, operation, sql_redo, timestamp, scn FROM v$logmnr_contents WHERE seg_owner = ‘xxxx’ and operation in ('UPDATE', 'DELETE', 'INSERT');
Turn off incremental parsing
SQL> EXEC dbms_logmnr.end_logmnr;
The above operations are all based on Oracle containers, and the actual Oracle server needs to adjust the operations according to the configuration.