誤刪 Oracle 庫中的數(shù)據(jù),在不考慮全庫備份和利用歸檔日志情況,如何恢復(fù)數(shù)據(jù)呢?
下面介紹幾種方法恢復(fù)數(shù)據(jù):
1、利用 Oracle 提供的閃回方法進(jìn)行數(shù)據(jù)恢復(fù),適用于 delete 刪除方式
首先獲取刪除數(shù)據(jù)的時(shí)間點(diǎn):
select * from v$sql where sql_text like '%table_name%';
根據(jù)結(jié)果中的 sql_text 內(nèi)容,找到 delete 執(zhí)行語句對(duì)應(yīng)的刪除時(shí)間點(diǎn),執(zhí)行下面語句查詢出刪除的數(shù)據(jù)。
select * from table_name as of timestamp to_timestamp(‘刪除時(shí)間點(diǎn)’,‘yyyy-mm-dd hh24:mi:ss’)
where (刪除時(shí)的條件);
檢查數(shù)據(jù)無誤后,執(zhí)行下面操作,將數(shù)據(jù)插回原表中。注意主鍵不重復(fù)
insert into table_name
select * from from table_name as of timestamp to_timestamp(‘刪除時(shí)間點(diǎn)’,‘yyyy-mm-dd hh24:mi:ss’)
where (刪除時(shí)的條件);
2、利用 Oracle 虛擬回收站功能
原理是因?yàn)?Oracle 數(shù)據(jù)庫在刪除表時(shí)會(huì)將刪除信息存放于某虛擬回收站中而非直接清空,在此種狀態(tài)下數(shù)據(jù)庫標(biāo)記該表的數(shù)據(jù)庫為可以復(fù)寫,所以在該塊未被重新使用前依然可以恢復(fù)數(shù)據(jù)。該方法多用于 drop 刪除。
首先查詢 user_table 視圖,找到被刪除的表:
select table_name,dropped from user_tables;
select object_name,original_name,type,droptime from user_recyclebin;
注意此時(shí)的,object_name 和 original_name 就是回收站存放的表名和原來刪除的表名,如果表名沒有被重新命名,可以通過下面語句進(jìn)行恢復(fù):
flashback table original_name to before drop;
如果不知道源表名,或者需要重新命名新的表名存放數(shù)據(jù),則可以通過回收站中的object_name進(jìn)行恢復(fù),命令如下:
flashback table object_name to before drop new_table_name;
3、用 Oracle 數(shù)據(jù)庫的閃回功能可以將數(shù)據(jù)庫恢復(fù)到過去某一狀態(tài)
注意,此時(shí)是整庫恢復(fù),具體語法如下:
SQL>alter database flashback on
SQL>flashback database to scn SCNNO;
SQL>flashback database to timestamp to_timestamp(‘frombyte 2021-09-02 23:59:59’,‘yyyy-mm-dd hh24:mi:ss’);
4、徹底刪除數(shù)據(jù)
如果確定需要?jiǎng)h除的數(shù)據(jù)又不想無謂的占用空間,可以使用以下3種方式:
1)采用 truncate 方式進(jìn)行截?cái)?。(不能進(jìn)行數(shù)據(jù)恢復(fù))
2)在 drop 時(shí)加上 purge 選項(xiàng):
drop table table_name purge;
3)通過刪除 recyclebin 區(qū)域來永久性刪除表:
drop table table_name cascade constraints purge table table_name;
5. 關(guān)于清空回收站
1)刪除當(dāng)前用戶回收站文章來源:http://www.zghlxwxcb.cn/news/detail-757404.html
purge recyclebin;
2)刪除全體用戶在回收站的數(shù)據(jù)文章來源地址http://www.zghlxwxcb.cn/news/detail-757404.html
purge dba_recyclebin;
到了這里,關(guān)于Oracle 庫恢復(fù)刪除數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!