首页 > 数据治理 > 数据治理 > Oracle flashback
一、recyclebin
1.查询回收站信息
show parameter recyclebin;
select * from recyclebin;
recyclebin是user_recyclebin的公共同义词
select * from user_recyclebin;
USER_RECYCLEBIN displays information about the recycle bin owned by the current user
select * from dba_recyclebin;
DBA_RECYCLEBIN displays information about all recycle bins in the database.
2.启动关闭回收站
ALTER SYSTEM SET recyclebin = ON;
ALTER SYSTEM SET recyclebin = off;
3.闪回表
flashback table table_name to before drop;
FLASHBACK TABLE <<Dropped_Table_Name>> TO BEFORE DROP RENAME TO <<New_Table_Name>>;
测试1:drop表t1之后,再次创建表t1,然后还原drop的t1
10点
drop table t1;
14点
create table t1 as select * from t2;
14:10分
drop table t1 purge;
恢复10点,两种方法都行,第三种为改名
flashback table t1 to before drop;
flashback table "BIN$vktCO1b/IhXgVQoAJ/0dDQ==$0" to before drop;
flashback table t2 to before drop rename to t1;
测试2:表按时间点恢复
SQL> flashback table t1 to before drop;
Flashback complete.
SQL> ALTER TABLE T1 ENABLE ROW MOVEMENT;
Table altered.
SQL> flashback table t1 TO TIMESTAMP TO_TIMESTAMP('2021-03-25:04:00:26','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> alter table t1 disable row movement;
Table altered.
4.删除表并清空回收站
drop table t2 purge;
二、闪回数据库
1.说明:
闪回数据库只能闪回库,不能闪回表空间,闪回依赖于db_flashback_retention_target(单位是分)和磁盘实际保留数据,且注意控制文件没有被还原或重建过,因为闪回备份的信息是存放在控制文件里,闪回可以修复逻辑坏块不能修复物理坏块。在nologging下,不建议使用flashback database,因为可能导致文件块损坏;闪回数据库闪回不包括临时表空间;将相关表空间offline,在闪回数据库时,不闪回此表空间,可能失败,成功之后,restore 表空间,recover表空间并online,将offline的表空间的scn恢复成与其它的一致;
2.查看闪回是否开启:
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
3.开启关闭闪回
alter database flashback on;
alter database flashback off;
单库还原例子:
SQL> select * from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI RETENTION_TARGET FLASHBACK_SIZE ESTIMATED_FLASHBACK_SIZE
-------------------- ------------------- ---------------- -------------- ------------------------
6681184 2021-03-24 15:53:52 1440 157286400 0
SQL>flashback database to scn 6681184;
SQL>FLASHBACK DATABASE TO RESTORE POINT 'RS_POINT';
SQL>flashback database to timestamp to_date('2021-03-24 22:00:07','yyyy-mm-dd hh24:mi:ss');
SQL>flashback database to before timestamp to_date('2021-03-24 21:00:07','yyyy-mm-dd hh24:mi:ss');
SQL>alter database open resetlogs;
dg还原例子:
select * from v$flashback_database_log;
备库flashback database to scn xxx;
然后alter database open;
如果想要从备库恢复某表到主库,则可以
1)从主库建备库的dblink,然后通过创建的方式来恢复
tnsping pj_xmc OK
SQL> create public database link xmc_recover connect to xmc identified by xmc using ‘pj_xmc’;
SQL> create table t2 as select * from xmc.t2@xmc_recover;
然后应用,会自动追归档
2)将备库转换为snapshot standby,然后开启到read write 然后expdp/impdp
recover managed standby database cancel;
alter database convert to snapshot standby;
告警日志如下:
Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_01/17/2021 08:15:21
SQL> alter database open;
SQL> select open_mode,DATABASE_ROLE from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ WRITE SNAPSHOT STANDBY
导出完毕之后,将snapshot standby关闭,并启动到mount,并切换
alter database convert to physical standby;
alter database open;
recover managed standby database using current logfile disconnect from session;
主库flashback database to scn xxx;
alter database open resetlogs;
然后备库就挂掉了,重新搭建
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30654353/viewspace-2765500/ ,如需转载,请注明出处,否则将追究法律责任。