oracle清理日常備份數(shù)據(jù)及恢復(fù)誤刪除表

字號(hào):


    一、清理日常備份的數(shù)據(jù)表
    1、背景:系統(tǒng)表空間占用率已經(jīng)超過(guò)90%。于是做了一個(gè)相關(guān)的垃圾數(shù)據(jù)進(jìn)行清理的工作。
    2、查詢(xún)需清理表清單:因?yàn)槿粘T跀?shù)據(jù)庫(kù)操作的時(shí)候,經(jīng)常會(huì)進(jìn)行一些表的備份。咨詢(xún)前任系統(tǒng)管理員,他們?cè)趥浞荼淼臅r(shí)候一般是在原表上加日期或者使用bak進(jìn)行標(biāo)識(shí)。于是使用
    select owner, num_rows * avg_row_len,table_name from dba_tables where table_name like '%bak%' and regexp_like(table_name,'/d+') and (table_name not like 't_im_inventory%' and table_name not like 'vt%' and table_name not like 'ncm%' and table_name not like 't_hr_schm%' and table_name not like 'sys%' and owner='jingya');
    查詢(xún)出相關(guān)可能性的表占用的空間,排除其他可能表之后,合計(jì)占用空間接近100g。
    3、測(cè)試:在測(cè)試系統(tǒng)中將已經(jīng)初步確定的表進(jìn)行刪除,進(jìn)行相關(guān)業(yè)務(wù)的測(cè)試。沒(méi)有問(wèn)題。
    4、正式操作:依照公司的變更流程,對(duì)正式系統(tǒng)進(jìn)行操作;
    二、誤刪除表的恢復(fù)
    在做完一的工作之后,業(yè)務(wù)運(yùn)行了2天無(wú)故障,第三天的時(shí)候,財(cái)務(wù)報(bào)修說(shuō)財(cái)務(wù)合并報(bào)表自動(dòng)抵消項(xiàng)生成分錄少一項(xiàng)。分析后確定是誤刪除了一張報(bào)表使用到的數(shù)據(jù)表。需要對(duì)該表進(jìn)行恢復(fù)。
    恢復(fù)的代碼如下:
    --1 從閃回中查詢(xún)誤drop的表select object_name, original_name, partition_name, type, ts_name, createtime, droptime from recyclebin where original_name = 't_csl_itemdataentry001'; --2 恢復(fù)到刪除前flashback table bin$ap6v8ohdaalgu8cozgebog==$0 to before drop; --3 查詢(xún)數(shù)據(jù)select count(*) from t_csl_itemdataentry001
    確定問(wèn)題解決。