Oracle-表闪回&快照恢复

表闪回

误操作

不小心删除了表数据,或者更新了表数据。这时候记下操作的大致时间。

1
2
3
4
SELECT * FROM  PS_C_RE_STATUS_TBL 
/*误操作*/
delete from PS_C_RE_STATUS_TBL

备份误操作后产生的数据(最新的数据)

1
2
3
/*创建当前数据备份表*/
create table PS_C_RE_STATUS_TBL_back as select * from PS_C_RE_STATUS_TBL
SELECT * FROM PS_C_RE_STATUS_TBL_back

开启表闪回功能,并且闪回表到指定时间

1
2
3
4
5
6
7
8
/*开启表闪回*/
alter table PS_C_RE_STATUS_TBL enable row movement;

/*表闪回指定数据*/
FLASHBACK TABLE PS_C_RE_STATUS_TBL TO TIMESTAMP TO_TIMESTAMP('2020-12-21 11:11:00', 'YYYY-MM-DD HH24:MI:SS');

/*关闭表闪回*/
alter table PS_C_RE_STATUS_TBL disable row movement;

快照恢复

1
2
3
4
5
6
7
/*获取30分钟之前的快照 TIMESTAMP(SYSTIMESTAMP - 1 / 48)插入表中*/
INSERT INTO PSPCMTXT
SELECT *
FROM (SELECT *
FROM PSPCMTXT AS OF TIMESTAMP(SYSTIMESTAMP - 1 / 48))
WHERE OBJECTID1 = 104
AND OBJECTVALUE1 = '包名';