[20220909]bbed關於刪除記錄恢復的問題.txt

来源:https://www.cnblogs.com/lfree/archive/2022/09/21/16717220.html
-Advertisement-
Play Games

如果現在的我們離開了互聯網,生活會是什麼樣子? 互聯網++++,已經深刻滲透到人們的生活中。 不知道大家有沒有想過?每一個互聯網+結合的背後都是海量的存儲需求。你查看的每一個商品、組建的每一個戰隊、閱讀的每一篇文章,基於互聯網的每一個興趣愛好,都有它的key和value。 在 key-value 數 ...


[20220909]bbed關於刪除記錄恢復的問題.txt

--//快下班被別人問的關於刪除記錄使用bbed恢復的問題,我開始以為很快講解完,刪除記錄oracle僅僅打上一個標識,實際的記錄還存在.
--//實際上地方問的是多次DML(刪除記錄的情況),實際上只要dump還能看到,bbed還是可以恢復的,做一個例子說明:

1.環境:
SCOTT@test01p> @ver1
PORT_STRING          VERSION    BANNER                                                                       CON_ID
-------------------- ---------- ---------------------------------------------------------------------------- ------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production      0

SCOTT@test01p> create table deptx as select * from dept ;
Table created.

SCOTT@test01p> select rowid from deptx where rownum=1;
ROWID
------------------
AAAHGVAALAAAACjAAA

SCOTT@test01p> @ rowid AAAHGVAALAAAACjAAA
    OBJECT       FILE      BLOCK        ROW ROWID_DBA   DBA    TEXT
---------- ---------- ---------- ---------- ----------- ------ ----------------------------------------
     29077         11        163          0  0x2C000A3  11,163 alter system dump datafile 11 block 163

SCOTT@test01p> alter system checkpoint ;
System altered.

SCOTT@test01p> alter system checkpoint ;
System altered.

2.測試:
BBED> set dba 11,164
        DBA             0x02c000a4 (46137508 11,164)
--//註:bbed for windows 訪問的block要加1,主要問題在於無法識別數據文件的第0塊(OS塊頭)

BBED> p *kdbr
rowdata[66]
-----------
ub1 rowdata[66]                             @8162     0x2c

BBED> p kdbr
sb2 kdbr[0]                                 @142      8038
sb2 kdbr[1]                                 @144      8016
sb2 kdbr[2]                                 @146      7996
sb2 kdbr[3]                                 @148      7972

SCOTT@test01p> delete from deptx where deptno=20;
1 row deleted.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> alter system checkpoint ;
System altered.

--//通過bbed觀察如下:
BBED> p kdbr dba 11,164
sb2 kdbr[0]                                 @142      8038
sb2 kdbr[1]                                 @144      8016
sb2 kdbr[2]                                 @146      7996
sb2 kdbr[3]                                 @148      7972

BBED> x /rncc *kdbr[0]
rowdata[66]                                 @8162
-----------
flag@8162: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8163: 0x00
cols@8164:    3
col    0[2] @8165: 10
col   1[10] @8168: ACCOUNTING
col    2[8] @8179: NEW YORK

BBED> x /rncc *kdbr[1]
rowdata[44]                                 @8140
-----------
flag@8140: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH)
lock@8141: 0x02
cols@8142:    0
--//你可以發現flag 從0x2c變成 0x3c,打上了KDRHFD標識表示刪除,恢復實際上就是修改flag=0x2c(也就是取消KDRHFD標識).
--//繼續:

SCOTT@test01p> delete from deptx where deptno=30;
1 row deleted.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> alter system checkpoint ;
System altered.

BBED> p kdbr dba 11,164
sb2 kdbr[0]                                 @142      8038
sb2 kdbr[1]                                 @144      8016
sb2 kdbr[2]                                 @146      7996
sb2 kdbr[3]                                 @148      7972
--//偏移量還是不變,也就是這樣的情況下以上兩條記錄都可以恢復.

SCOTT@test01p> update deptx set dname=upper(dname) where deptno=10;
1 row updated.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> alter system checkpoint ;
System altered.

BBED> p kdbr dba 11,164
sb2 kdbr[0]                                 @142      8038
sb2 kdbr[1]                                 @144      8016
sb2 kdbr[2]                                 @146      7996
sb2 kdbr[3]                                 @148      7972
--//我執行update操作,但是行目錄並沒有修改,主要原因在於DML修改的記錄長度沒有變化,oracle並不會改變行目錄的偏移。
--//而是就地修改相關記錄信息。

SCOTT@test01p> update deptx set dname=upper(dname)||'0' where deptno=10;
1 row updated.

SCOTT@test01p> commit ;
Commit complete.

SCOTT@test01p> alter system checkpoint ;
System altered.

BBED> p kdbr dba 11,164
sb2 kdbr[0]                                 @142      7945
sb2 kdbr[1]                                 @144      2
sb2 kdbr[2]                                 @146     -1
sb2 kdbr[3]                                 @148      7972
--//在DML後修改記錄長度發生變化後,oracle在修改kdbr[0]的偏移時,同時也修改kdbr[1],kdbr[2]的信息,
--//這個應該是oracle的一個設計理念,順手把以前沒做的事情做完...
--//你可以從修改的信息可以推斷,如果下次操作是插入,使用那個行目錄時應該從kdbr[1],kdbr[2]選擇。
--//如果你仔細觀察可以發現刪除記錄的行目錄記錄的偏移記錄的信息形成1個鏈表結構,sb2 kdbr[2] = -1 表示鏈表結構的尾部.
--//並且可以通過行目錄偏移 kdbr[N] 是否 >= kdbh.kdbhnrow (當前為4),來確定是否指向正確的記錄信息。

BBED> p kdbh dba 11,164
struct kdbh, 14 bytes                       @124
   ub1 kdbhflag                             @124      0x00 (NONE)
   b1 kdbhntab                              @125      1
   b2 kdbhnrow                              @126      4
=======================================================
   sb2 kdbhfrre                             @128      1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
   sb2 kdbhfsbo                             @130      26
   sb2 kdbhfseo                             @132      7945
   b2 kdbhavsp                              @134      7987
   b2 kdbhtosp                              @136      7987

--//kdbhfrre = 1 ,表示鏈表結構的開頭,也就是如果在塊DML有插入時,會先使用kdbr[1]行目錄.
--//你可以發現這時kdbr[1],kdbr[2]執行的偏移並沒有覆蓋,要恢復一定ok的.

BBED> assign  kdbr[1] = 8016;
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
sb2 kdbr[0]                                 @144      8016

BBED> assign  kdbr[2] = 7996;
sb2 kdbr[0]                                 @146      7996


BBED> x /rncc *kdbr[1]
rowdata[71]                                 @8140
-----------
flag@8140: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH)
lock@8141: 0x02
cols@8142:    0

BBED> x /rncc *kdbr[2]
rowdata[51]                                 @8120
-----------
flag@8120: 0x3c (KDRHFL, KDRHFF, KDRHFD, KDRHFH)
lock@8121: 0x03
cols@8122:    0

--//修改flag取消KDRHFD標識:
BBED> assign  offset 8140 = 0x2c;
ub1 rowdata[0]                              @8140     0x2c

BBED> assign  offset 8120 = 0x2c;
ub1 rowdata[0]                              @8120     0x2c


BBED> x /2rncc *kdbr[2]
rowdata[51]                                 @8120
-----------
flag@8120: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8121: 0x03
cols@8122:    3

col    0[2] @8123: 30
col    1[5] @8126: SALES
col    2[7] @8132: CHICAGO

rowdata[71]                                 @8140
-----------
flag@8140: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8141: 0x02
cols@8142:    3

col    0[2] @8143: 20
col    1[8] @8146: RESEARCH
col    2[6] @8155: DALLAS
--//現在2條記錄都可以顯見,剩下就是恢復對應數據塊的完整性以及一致性問題.

BBED> sum apply
Check value for File 11, Block 164:
current = 0x9fe2, required = 0x9fe2

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: row locked by non-existent transaction
        table=0   slot=2
        lockid=3   ktbbhitc=3
Block 163 failed with check code 6101

--//lock 偏移8121 =0x0.
BBED> assign offset 8121=0x0;
ub1 rowdata[0]                              @8121     0x00

BBED> sum apply
Check value for File 11, Block 164:
current = 0x9ce2, required = 0x9ce2

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: entries on the free list are not ordered
        next=8016 nrow=4 chas=1
Block 163 failed with check code 6106

BBED> assign kdbh.kdbhfrre=-1
sb2 kdbhfrre                                @128     -1

BBED> sum apply
Check value for File 11, Block 164:
current = 0x631c, required = 0x631c

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: xaction header lock count mismatch
        trans=2 ilk=1 nlo=2
Block 163 failed with check code 6108

--//lock 偏移8141 =0x0.
BBED> assign offset 8141=0x0;
ub1 rowdata[0]                              @8141     0x00

BBED> sum apply
Check value for File 11, Block 164:
current = 0x611c, required = 0x611c

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: the amount of space used is not equal to block size
        used=119 fsc=0 avsp=7987 dtl=8064
Block 163 failed with check code 6110

--//dtl-used-fsc = avsp
--//8064-119-0 = 7945

BBED> assign kdbh.kdbhavsp=7945;
b2 kdbhavsp                                 @134      7945

BBED> sum apply
Check value for File 11, Block 164:
current = 0x6126, required = 0x6126

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: space available on commit is incorrect
        tosp=7987 fsc=0 stb=0 avsp=7945
Block 163 failed with check code 6111

BBED> assign kdbh.kdbhtosp=7945;
b2 kdbhtosp                                 @136      7945

BBED> sum apply
Check value for File 11, Block 164:
current = 0x611c, required = 0x611c

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163
--//OK現在恢復完成.

SCOTT@test01p> alter system flush BUFFER_CACHE;
System altered.

SCOTT@test01p> select * from deptx;
    DEPTNO DNAME                LOC
---------- -------------------- -------------
        10 ACCOUNTING0          NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON
--//刪除記錄已經恢復.
--//原來deptno= 10 的記錄沒有覆蓋,理論將也可以恢復.繼續嘗試看看.

BBED> assign kdbr[0]=8038
sb2 kdbr[0]                                 @142      8038

BBED> x /rncc *kdbr[0]
rowdata[93]                                 @8162
-----------
flag@8162: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8163: 0x00
cols@8164:    3

col    0[2] @8165: 10
col   1[10] @8168: ACCOUNTING
col    2[8] @8179: NEW YORK
--//這樣修改行目錄偏移指向執行原來的位置.

BBED> sum apply
Check value for File 11, Block 164:
current = 0x6173, required = 0x6173

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: xaction header lock count mismatch
        trans=2 ilk=1 nlo=0
Block 163 failed with check code 6108

BBED> assign offset 8163  = 0x02
ub1 rowdata[0]                              @8163     0x02

BBED> sum apply
Check value for File 11, Block 164:
current = 0x6373, required = 0x6373

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163

Block Checking: DBA = 46137507, Block Type = KTB-managed data block
data header at 0x2c4027c
kdbchk: the amount of space used is not equal to block size
        used=118 fsc=0 avsp=7945 dtl=8064
Block 163 failed with check code 6110

--//dtl-used-fsc = avsp
--//8064-118-0 = 7946

BBED> assign kdbh.kdbhavsp=7946;
b2 kdbhavsp                                 @134      7946

BBED> assign kdbh.kdbhtosp=7946;
b2 kdbhtosp                                 @136      7946

BBED> sum apply
Check value for File 11, Block 164:
current = 0x6373, required = 0x6373

BBED> verify
DBVERIFY - Verification starting
FILE = D:\APP\ORACLE\ORADATA\TEST\TEST01P\USERS01.DBF
BLOCK = 163
--//ok,現在恢復到原始建立時的狀態.

SCOTT@test01p> alter system flush BUFFER_CACHE;
System altered.

SCOTT@test01p> select * from deptx;
    DEPTNO DNAME                LOC
---------- -------------------- -------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON

3.總結:
--//很久不使用bbed,有點生疏了。
--//我前面的恢復定位行目錄信息時使用原來顯示的信息,實際的恢復只能通過find檢索0x2c,0x3c字元定位。
--//然後通過執行 x /rncc offset NNNN,確定顯示的信息是否正確。獲得NNNN偏移是絕對偏移,必須減去kdbh的偏移(這裡是124,前面
--//有3個ITL槽),這樣才能確定行目錄的相對偏移值。
--//總之到對應的數據塊操作相對複雜!!!

BBED> p kdbr dba 11,164
sb2 kdbr[0]                                 @142      8038
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sb2 kdbr[1]                                 @144      8016
sb2 kdbr[2]                                 @146      7996
sb2 kdbr[3]                                 @148      7972

BBED> p kdbh dba 11,164
struct kdbh, 14 bytes                       @124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ub1 kdbhflag                             @124      0x00 (NONE)
   b1 kdbhntab                              @125      1
   b2 kdbhnrow                              @126      4
   sb2 kdbhfrre                             @128      1
   sb2 kdbhfsbo                             @130      26
   sb2 kdbhfseo                             @132      7945
   b2 kdbhavsp                              @134      7987
   b2 kdbhtosp                              @136      7987


BBED> x /rncc *kdbr[0]
rowdata[66]                                 @8162
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------
flag@8162: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8163: 0x00
cols@8164:    3
col    0[2] @8165: 10
col   1[10] @8168: ACCOUNTING
col    2[8] @8179: NEW YORK
--// 8162-124 = 8038
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 最近在項目中啟用了Nullable 可為空的類型,這個特性確實很好用,在 WebAPI 的入參上可以直接採用 ? 來標記一個欄位是否允許為空,但是使用過程中遇到瞭如下一個問題,比如創建部門介面 我們定義入參模型如下: public class DtoDepartment { /// <summary ...
  • .NET 6 EFCore WebApi 使用 JMeter 進行吞吐量測試 開發環境 VS2022 .NET 6 測試環境 測試工具 介面壓力測試工具:JMeter 資料庫 MySQL 5.7 資料庫和WebApi服務在同一臺伺服器上,JMeter在本人筆記本上。 測試設置 200個線程併發,每個 ...
  • 一、 環境準備 本次配置基於DR負載均衡模式,設置一個VIP(Virtual IP)為19.50.67.173,用戶只需要訪問這個IP地址即可獲得後端服務 其中,負載均衡主機為19.50.67.165(LVS1),備機為 19.50.67.169(LVS2)。Web伺服器A為19.50.67.171 ...
  • forklift Mac版是一款強大的文件管理程式,彌補了Finder文件管理比較單一的功能,強大到能遠程連接Ftp,SFTP,Amazon S3,WebDAV,SMB,NIS,AFP等網路共用服務協議。相對其他文件管理器如Path Finder,forklift mac更加小巧快速。 除此之外Fo ...
  • PowerPoint 無法打開文件 出現的問題 今天下載老師放在學習通的ppt,居然不能打開,記錄一下 點擊修複後出現: 這並不是文件損壞了,而是powerpoint出於安全的考慮,為了保護我們的電腦,不能打開其他電腦的文件。 解決辦法 右鍵選擇屬性,進入常規界面,勾選解除鎖定,點擊引用,點擊確 ...
  • 個人超級電腦是一個新概念,目前這個市場類似上世紀70年的PC革命時代。本篇是回答一位用戶提問,LAXCUS分散式操作系統如何成為一臺“個人超級電腦”。 ...
  • mysql二進位安裝腳本部署 單實例 [root@localhost ~]# mkdir mysql //創建存放腳本目錄 [root@localhost ~]# ls anaconda-ks.cfg mysql [root@localhost ~]# cd mysql/ [root@localho ...
  • 1.shell命令的執行機制:fork+exec執行命令(任何的shell都會執行) 2.shell中的用戶輸入處理 1 命令行參數:選項、參數 2 運行時輸入 3 read命令: 4 1.基本讀取、 5 2.超時處理-t選項、 6 3.隱藏方式讀取-s選項) 7 4.從文件中讀取 3.shell的 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 在我們開發過程中基本上不可或缺的用到一些敏感機密數據,比如SQL伺服器的連接串或者是OAuth2的Secret等,這些敏感數據在代碼中是不太安全的,我們不應該在源代碼中存儲密碼和其他的敏感數據,一種推薦的方式是通過Asp.Net Core的機密管理器。 機密管理器 在 ASP.NET Core ...
  • 新改進提供的Taurus Rpc 功能,可以簡化微服務間的調用,同時可以不用再手動輸出模塊名稱,或調用路徑,包括負載均衡,這一切,由框架實現並提供了。新的Taurus Rpc 功能,將使得服務間的調用,更加輕鬆、簡約、高效。 ...
  • 順序棧的介面程式 目錄順序棧的介面程式頭文件創建順序棧入棧出棧利用棧將10進位轉16進位數驗證 頭文件 #include <stdio.h> #include <stdbool.h> #include <stdlib.h> 創建順序棧 // 指的是順序棧中的元素的數據類型,用戶可以根據需要進行修改 ...
  • 前言 整理這個官方翻譯的系列,原因是網上大部分的 tomcat 版本比較舊,此版本為 v11 最新的版本。 開源項目 從零手寫實現 tomcat minicat 別稱【嗅虎】心有猛虎,輕嗅薔薇。 系列文章 web server apache tomcat11-01-官方文檔入門介紹 web serv ...
  • C總結與剖析:關鍵字篇 -- <<C語言深度解剖>> 目錄C總結與剖析:關鍵字篇 -- <<C語言深度解剖>>程式的本質:二進位文件變數1.變數:記憶體上的某個位置開闢的空間2.變數的初始化3.為什麼要有變數4.局部變數與全局變數5.變數的大小由類型決定6.任何一個變數,記憶體賦值都是從低地址開始往高地 ...
  • 如果讓你來做一個有狀態流式應用的故障恢復,你會如何來做呢? 單機和多機會遇到什麼不同的問題? Flink Checkpoint 是做什麼用的?原理是什麼? ...
  • C++ 多級繼承 多級繼承是一種面向對象編程(OOP)特性,允許一個類從多個基類繼承屬性和方法。它使代碼更易於組織和維護,並促進代碼重用。 多級繼承的語法 在 C++ 中,使用 : 符號來指定繼承關係。多級繼承的語法如下: class DerivedClass : public BaseClass1 ...
  • 前言 什麼是SpringCloud? Spring Cloud 是一系列框架的有序集合,它利用 Spring Boot 的開發便利性簡化了分散式系統的開發,比如服務註冊、服務發現、網關、路由、鏈路追蹤等。Spring Cloud 並不是重覆造輪子,而是將市面上開發得比較好的模塊集成進去,進行封裝,從 ...
  • class_template 類模板和函數模板的定義和使用類似,我們已經進行了介紹。有時,有兩個或多個類,其功能是相同的,僅僅是數據類型不同。類模板用於實現類所需數據的類型參數化 template<class NameType, class AgeType> class Person { publi ...
  • 目錄system v IPC簡介共用記憶體需要用到的函數介面shmget函數--獲取對象IDshmat函數--獲得映射空間shmctl函數--釋放資源共用記憶體實現思路註意 system v IPC簡介 消息隊列、共用記憶體和信號量統稱為system v IPC(進程間通信機制),V是羅馬數字5,是UNI ...