啟用歸檔日誌(前滾恢復)的資料庫,恢復時需套用備份後的所有日誌。但 LOAD 為追求極速,僅在 DELETE 階段記錄違反唯一約束的刪除行,幾乎不產生日誌。為避免前滾時因缺日誌導致表空間異常,DB2 提供三種 LOAD 復原選項:
COPY NO(預設)COPY YESNONRECOVERABLEWindows 環境下為目錄結構:資料庫別名.Type\實例\Node0000\Catn0000\yyyymmdd\hhmmss.序號
Type 編碼:0=完整備份、3=表空間備份、4=LOAD 產生備份。
db2 backup db sample
-- 產生 SAMPLE.0 目錄,時間戳 20051230174105
db2 load from staff.del of del insert into staff
db2 list tablespaces show detail
-- 表空間狀態 0x0020 = 備份暫掛
此狀態下可 SELECT,但 UPDATE/DELETE 會報 SQL0290N。解除方式:
db2 backup db sample tablespace (userspace1)
-- 產生 SAMPLE.3 目錄,表空間恢復正常
db2 restore db sample taken at 20051230174105db2 rollforward db sample to end of logs and stop → 表空間進入「恢復暫掛」(0x0100)db2 restore db sample tablespace (userspace1) taken at 20051230184841(套用步驟 2 產生的表空間備份)db2 rollforward db sample to end of logs and stop tablespace (userspace1) → 表空間進入「前滾暫掛」(0x0080)再轉正常db2 load from staff.del of del insert into staff copy yes to .
-- 產生 SAMPLE.4 目錄,表空間直接正常
前滾恢復時自動套用 Type=4 備份,無需人工介入,表空間全程正常,資料完整保留。
db2 load from staff.del of del insert into staff nonrecoverable
-- 表空間正常,但無備份產生
前滾恢復時跳過該事務,表標記無效(SQL1477N),僅能 Drop 重建或從 LOAD 後的完整備份恢復。
| 指標 | COPY NO | COPY YES | NONRECOVERABLE |
|---|---|---|---|
| 備份產生 | 無(需手動) | 自動(Type=4) | 無 |
| 載入後表空間 | 備份暫掛 | 正常 | 正常 |
| 前滾恢復 | 需表空間備份配合 | 自動無縫 | 不可恢復,表失效 |
| 適用場景 | 需控制備份時點 | 生產標準選項 | 可重建資料、測試環境 |