Oracle闪回技术

文章目录

    • 1、配置闪回恢复区
    • 2、数据库闪回配置
    • 3、使用 scn/时间 闪回数据库
    • 4、闪回查询
    • 5、闪回表
    • 6、闪回版本查询
    • 7、闪回事务查询

1、配置闪回恢复区

SQL> set time on;
SQL> show parameter db_recovery_file_dest;
SQL> alter system set db_recovery_file_dest_size=5G scope=both;

2、数据库闪回配置

①数据库必须在归档模式
②数据库参数 db_flashback_retention_target 指定可以在多长时间内闪回数据库,单位分钟
③在 mount 状态下使用

SQL> archive log list;
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter system set db_flashback_retention_target = 7200;
SQL> alter database flashback on;
SQL> alter database open;

3、使用 scn/时间 闪回数据库

①获取 scn 值
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> select OLDEST_FLASHBACK_SCN,OLDEST_FLASHBACK_TIME from v$flashback_database_log;

OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI
-------------------- -------------------
             1291626 2021-05-05 11:25:14


②闪回数据库
SQL> shutdown immediate;
SQL> startup mount;
SQL> flashback database to scn 1291626;
#SQL> FLASHBACK DATABASE TO TIMESTAMP TO_TIMESTAMP('2021-05-05 11:25:14','yyyy-mm-dd hh24:mi:ss');
SQL> alter database open resetlogs;

4、闪回查询

SQL> select * from guo1 as of timestamp to_timestamp('2021-05-05 12:19:00','yyyy-mm-dd hh24:mi:ss');
SQL> select * from guo1 as of timestamp sysdate-10/1440;

5、闪回表

SQL> conn test/Wft2021
SQL> alter table guo1 enable row movement;
SQL> flashback table test.guo1 to timestamp to_timestamp('2021-05-05 11:49:17','yyyy-mm-dd hh24:mi:ss');
#SQL> create table guo1_bak as select * from guo1 as of timestamp to_timestamp('2021-05-05 12:19:00','yyyy-mm-dd hh24:mi:ss');

SQL> select * from dba_recyclebin;
SQL> show recyclebin;
SQL> drop table guo1;
SQL> flashback table test.guo1 to before drop;

6、闪回版本查询

SQL> select to_char(versions_starttime,'yyyy-mm-dd hh24:mi:ss') as starttime,versions_xid,EMPNO from guo1 versions between timestamp to_date('2021-05-05 12:19:00','yyyy-mm-dd hh24:mi:ss') and sysdate;

7、闪回事务查询

SQL> grant select any transaction to test;
SQL> select undo_sql from flashback_transaction_query where xid='06000C003B050000';

你可能感兴趣的:(Oracle,#,Oracle数据备份,恢复与闪回)