A shallow summary of oracle log miner

本文介绍了如何使用 Oracle LogMiner 工具来解析归档日志文件,以找到删除或修改的数据记录及其对应的 SQL 语句。适用于当需要恢复部分误删数据而非整个数据库时的情景。
Sometimes, we should recover one or more rows data which is deleted carelessly by users, but it is not necessary to recover the whole db and the flashback does not recovery the data because it's timeout.
For this moment, we should mine the log file to find the redo or undo data to recover the loss data and  find who delete the data.

How to use the log miner?

After oracle 9i, oracle provides a tool to mine the log file, there is a package of oracle dbms for the logmnr named dbms_logmnr. 

Make sure the db is archive log mode

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +FAR/arch1
Oldest online log sequence     833
Next log sequence to archive   834
Current log sequence           834
SQL>

Example of log miner analyze procedure:
SQL>
SQL> create table test(id number);

Table created.

SQL> insert into test values(1);

1 row created.

SQL> /

1 row created.

SQL> /

1 row created.

SQL> commit;

Commit complete.

SQL> begin
  2  for i in 1..100 loop
  3  insert into test values(i);
  4  commit;
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

Switch log file  by user system

SQL> alter system switch logfile;

System altered.

SQL>

Engine the log miner.



select name, thread#, sequence#, first_change#, next_change# from V$ARCHIVED_LOG;
NAME                    THREAD#  SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
-------------------- ---------- ---------- ------------- ------------
                              1        831    4062556971   4064186822
                              2        634    4063922165   4064177226
                              2        635    4064177226   4064275220
                              2        636    4064275220   4064429426
                              1        832    4064186822   4066775319
+FAR/arch1/1_833_817          1        833    4066775319   4066914873
620325.dbf

+FAR/arch1/1_834_817          1        834    4066914873   4071821640
620325.dbf


NAME                    THREAD#  SEQUENCE# FIRST_CHANGE# NEXT_CHANGE#
-------------------- ---------- ---------- ------------- ------------
+FAR/arch2/2_637_817          2        637    4064429426   4071821645
620325.dbf


SQL> exec dbms_logmnr.add_logfile(logfilename=>'+FAR/arch1/1_834_817620325.dbf', options=>dbms_logmnr.new);

PL/SQL procedure successfully completed.

SQL>

options: dbms_logmnr.new   stand for  the first log file to be analyzed.

SQL> exec dbms_logmnr.start_logmnr(options => sys.dbms_logmnr.dict_from_online_catalog);

PL/SQL procedure successfully completed.

SQL>

select scn, timestamp, seg_name, seg_owner, sql_redo, sql_undo from v$logmnr_contents where seg_name='TEST' and set_owner='RAY';

     SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
4071818078 11-SEP-13 TEST       RAY        create table test(id number);
4071818819 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '1
                                           1');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAA';

4071818840 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '1
                                           1');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAB';

4071818851 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '1
                                           1');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAC';

4071819125 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '1

       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
                                           1');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAD';

4071819127 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '2
                                           2');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAE';

4071819129 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '3
                                           3');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAF';

4071819131 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '4
                                           4');                                     ' and ROWID = 'AAAY8eAAFAAABbNAAG';

...............

       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------

4071819228 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           53');                                    3' and ROWID = 'AAAY8eAAFAAABbNAA3';

4071819231 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           54');                                    4' and ROWID = 'AAAY8eAAFAAABbNAA4';

4071819233 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           55');                                    5' and ROWID = 'AAAY8eAAFAAABbNAA5';

4071819235 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5

       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
                                           56');                                    6' and ROWID = 'AAAY8eAAFAAABbNAA6';

4071819237 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           57');                                    7' and ROWID = 'AAAY8eAAFAAABbNAA7';

4071819239 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           58');                                    8' and ROWID = 'AAAY8eAAFAAABbNAA8';

4071819241 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '5
                                           59');                                    9' and ROWID = 'AAAY8eAAFAAABbNAA9';


       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
4071819243 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '6
                                           60');                                    0' and ROWID = 'AAAY8eAAFAAABbNAA+';

4071819244 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '6
                                           61');                                    1' and ROWID = 'AAAY8eAAFAAABbNAA/';

4071819247 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '6
                                           62');                                    2' and ROWID = 'AAAY8eAAFAAABbNABA';

4071819249 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '6
                                           63');                                    3' and ROWID = 'AAAY8eAAFAAABbNABB';

...........
       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
                                           78');                                    8' and ROWID = 'AAAY8eAAFAAABbNABQ';

4071819285 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '7
                                           79');                                    9' and ROWID = 'AAAY8eAAFAAABbNABR';

4071819288 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           80');                                    0' and ROWID = 'AAAY8eAAFAAABbNABS';

4071819290 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           81');                                    1' and ROWID = 'AAAY8eAAFAAABbNABT';


       SCN TIMESTAMP SEG_NAME   SEG_OWNER  SQL_REDO                                 SQL_UNDO
---------- --------- ---------- ---------- ---------------------------------------- ----------------------------------------
4071819292 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           82');                                    2' and ROWID = 'AAAY8eAAFAAABbNABU';

4071819294 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           83');                                    3' and ROWID = 'AAAY8eAAFAAABbNABV';

4071819296 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           84');                                    4' and ROWID = 'AAAY8eAAFAAABbNABW';

4071819298 11-SEP-13 TEST       RAY        insert into "RAY"."TEST"("ID") values (' delete from "RAY"."TEST" where "ID" = '8
                                           85');                                    5' and ROWID = 'AAAY8eAAFAAABbNABX';




SQL> exec dbms_logmnr.end_logmnr;

PL/SQL procedure successfully completed.

For oracle log miner, we should pay attention to another main points.
### 如何在 Git 中执行浅克隆并限制提交历史记录的深度 在 Git 中,浅克隆(shallow clone)是一种通过限制克隆仓库的历史记录深度来减少所需磁盘空间和网络传输时间的技术。这种技术特别适用于大型仓库或仅需要最新代码而不关心完整历史记录的场景。以下是如何实现浅克隆并限制提交历史记录深度的方法[^1]。 可以通过 `git clone` 命令的 `--depth` 选项来执行浅克隆,并指定要克隆的历史记录深度。例如,以下命令将克隆一个仓库并仅保留最近的 5 次提交: ```bash git clone --depth 5 <repository-url> ``` 如果需要进一步调整浅克隆后的仓库行为,例如从远程仓库获取更多历史记录,可以使用 `git fetch` 命令并结合 `--depth` 选项。例如,以下命令将更新本地仓库的历史记录深度为 10: ```bash git fetch --depth=10 ``` 需要注意的是,浅克隆的仓库在某些操作上可能会受到限制,例如无法访问完整的提交历史记录或无法执行基于完整历史记录的操作(如 `git bisect` 或 `git blame`)。如果需要恢复完整的仓库历史记录,可以使用以下命令移除浅克隆限制: ```bash git fetch --unshallow ``` 此外,浅克隆的分支切换行为与普通克隆有所不同。只有在成功执行 `git checkout` 后,分支才会被重置或创建[^2]。 ### 示例代码 以下是一个完整的示例,展示如何执行浅克隆并限制历史记录深度: ```bash # 浅克隆仓库并限制历史记录深度为 3 git clone --depth 3 https://github.com/example/repo.git # 进入克隆的仓库目录 cd repo # 如果需要增加历史记录深度到 5 git fetch --depth=5 # 如果需要恢复完整的仓库历史记录 git fetch --unshallow ``` ### 注意事项 - 浅克隆适合于只需要最新代码的场景,但不适合需要完整历史记录的工作流。 - 浅克隆可能会影响某些依赖完整历史记录的 Git 工具或功能[^1]。 - 如果仓库包含大文件,可以结合 Git LFS 使用以优化存储和传输效率[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值