Oracle Study之案例--数据恢复神器Flashback(3)

Flashback Database:

案例分析:

flashback database:利用flashback log 对整个database 做回退到过去的某个时间点(用于DDL 的误操作如drop 和 truncate),类似于RMAN的不完全恢复(media recovery incompelete)

因为flashback database是不完全恢复,在恢复到过去的时间点前应该对数据库备份!
1、查看flashback database是否开启
07:21:27 SQL> select flashback_on from v$database;                                                                                       
FLASHBACK_ON
------------------
NO

2、创建recovery area
07:21:33 SQL> show parameter recover                                                                                                     
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery
                                                 _area
db_recovery_file_dest_size           big integer 2G
recovery_parallelism                 integer     2                                                                                                  ---recovery area可以存储flashback log、archive log、rman backup等                      
[[email protected] ~]$ mkdir -p /disk1/recovery/prod

配置recovery area:
07:22:49 SQL> alter system set db_recovery_file_dest=‘/disk1/recovery/prod‘ scope=spfile;                                                
System altered.

在归档模式下启用flashback database:

07:25:06 SQL> alter database flashback on;                                                                                               
Database altered.

07:25:29 SQL> select flashback_on from v$database;                                                                                       
FLASHBACK_ON
------------------
YES

07:25:38 SQL> alter database open;                                                                                                       
Database altered.

案例1:flashback database恢复DDL误操作(基于SCN)

flashback database可以用于基于时间点或SCN的数据恢复(可以通过logminer来查看DDL操作的时间点)

1)模拟环境
15:18:17 [email protected] test1 >select current_scn from v$database;

CURRENT_SCN
-----------
   1264788
   
07:26:30 SQL> select * from test;                                                                                                        
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
16 rows selected.
07:26:36 SQL> drop table test purge;                                                                                                     
Table dropped.

07:27:20 SQL> create table test as select * from emp where rownum=1;                                                                     
Table created.
07:27:25 SQL> select * from test;                                                                                                        
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      
查看flashback 日志:
[[email protected] ~]$ ls /disk1/recovery/prod/PROD/flashback/
o1_mf_74q999lb_.flb

关闭数据库后,在mount状态下恢复:
07:29:22 SQL> shutdown immediate                                                                                                      
Database closed.
Database dismounted.
ORACLE instance shut down.

07:29:53 SQL> startup mount                                                                                                              
ORACLE instance started.
Total System Global Area  314572800 bytes
Fixed Size                  1219184 bytes
Variable Size              71304592 bytes
Database Buffers          239075328 bytes
Redo Buffers                2973696 bytes
Database mounted.

通过flashback database将库恢复到过去的scn:
07:30:02 SQL> flashback database to scn 1264788;                                                                                         
Flashback complete.

将database以read only方式打开,先验证下恢复是否成功,如果不成功,再从新进入mount下恢复
07:31:29 SQL> alter database open read only;                                                                                             
Database altered.

07:31:34 SQL> select * from scott.test;                                                                                                  
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
16 rows selected.

--恢复成功,重新以resetlogs的方式open database
07:31:40 SQL> shutdown immedaite                                                                                                         
SP2-0717: illegal SHUTDOWN option
07:31:45 SQL> shutdown immediate                                                                                                         
Database closed.
Database dismounted.
ORACLE instance shut down.
07:32:02 SQL> startup mount                                                                                                              
ORACLE instance started.
Total System Global Area  314572800 bytes
Fixed Size                  1219184 bytes
Variable Size              71304592 bytes
Database Buffers          239075328 bytes
Redo Buffers                2973696 bytes
Database mounted.
07:32:10 SQL> alter database open resetlogs;                                                                                             
Database altered.

验证:
07:32:25 SQL> select * from scott.test;                                                                                                  
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
16 rows selected.

因为flashback database是不完全恢复,在恢复到过去的时间点前应该对数据库备份!

案例2:基于timestamp的flashback database

04:04:28 SQL> show user;
USER is "SYS"
04:08:04 SQL> conn scott/tiger
Connected.
04:08:13 SQL> select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘) from dual;
TO_CHAR(SYSDATE,‘YY
-------------------
2011-03-18 04:08:42

04:09:02 SQL> conn /as sysdba
Connected.
04:09:07 SQL> select current_scn from v$database;
CURRENT_SCN
-----------
    1437597
04:09:10 SQL> conn scott/tiger
Connected.
04:09:29 SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
EMP                            TABLE
DEPT                           TABLE
BONUS                          TABLE
SALGRADE                       TABLE
QUEST_SL_TEMP_EXPLAIN1         TABLE
EMP1                           TABLE
ERRLOG                         TABLE
PART_SALES                     TABLE
T01                            TABLE
DEPT1                          TABLE
10 rows selected.
select * from t01;
        ID NA
---------- --
         1 TM
04:10:07 SQL> insert into t01 values(2,‘aa‘);
1 row created.
04:10:17 SQL> insert into t01 values(3,‘bb‘);
1 row created.
04:10:26 SQL> commit;
Commit complete.
04:10:30 SQL> drop table t01;
Table dropped.

04:10:59 SQL> conn /as sysdba
Connected.
04:11:03 SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
04:11:28 SQL> startup mount
ORACLE instance started.
Total System Global Area  314572800 bytes
Fixed Size                  1219184 bytes
Variable Size             184550800 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes
Database mounted.

将database恢复到过去的时间点:
04:12:07 SQL> flashback database to timestamp to_timestamp(‘2011-03-18 04:10:26‘,‘yyyy-mm-dd hh24:mi:ss‘);
Flashback complete.
04:13:34 SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
04:14:10 SQL> alter database open noresetlogs;
alter database open noresetlogs
*
ERROR at line 1:
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

04:14:18 SQL> alter database open resetlogs;
Database altered.

04:15:35 SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- -------------------
         1          1          0   52428800          2 YES UNUSED                       0
         2          1          0   52428800          2 YES UNUSED                       0
         3          1          0   52428800          2 YES UNUSED                       0
         4          1          0   52428800          2 YES UNUSED                       0
         5          1          0   52428800          2 YES UNUSED                       0
         6          1          1   52428800          2 NO  CURRENT                1437637 2011-03-18 04:14:27
6 rows selected.
04:15:59 SQL> conn scott/tiger
Connected.
04:16:18 SQL> select * from t01;
        ID NA
---------- --
         1 TM
04:34:35 SQL> desc v$flashback_database_log;
 Name                                                                                Null?    Type
 ----------------------------------------------------------------------------------- -------- -   OLDEST_FLASHBACK_SCN                                                               NUMBER
 OLDEST_FLASHBACK_TIME                                                             DATE
 RETENTION_TARGET                                                                  NUMBER
 FLASHBACK_SIZE                                                                    NUMBER
 ESTIMATED_FLASHBACK_SIZE                                                          NUMBER
04:34:37 SQL> select * from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI RETENTION_TARGET FLASHBACK_SIZE TIMATED_FLASHBACK_SIZE
-------------------- ------------------- ---------------- -------------- ----------------------             
1436931 2011-03-18 03:51:43             1440        8192000           115703808

---未完待续。。。

时间: 2024-10-08 16:40:06

Oracle Study之案例--数据恢复神器Flashback(3)的相关文章

Oracle Study之案例--数据恢复神器Flashback(1)

Oracle Study之案例--数据恢复神器Flashback(1) Flashback: Flashback 技术是以Undo segment中的内容为基础的, 因此受限于UNDO_RETENTON参数.要使用flashback 的特性,必须启用自动撤销管理表空间. 在Oracle 11g里又出了一个新特性:Oracle Flashback Data Archive. FDA通过将变化数据另外存储到创建的闪回归档区(Flashback Archive)中,以和undo区别开来,这样就可以为闪

Oracle Study之案例--数据恢复神器Flashback(2)

一.Flashback Table: 对于DML的误操作,可以通过Undo block对表进行回退(两种模式:基于时间和基于SCN) 案例分析: 1.基于SCN(可以通过logminer找到DML操作的时间点和SCN) 模拟测试环境: SQL> select current_scn from v$database; CURRENT_SCN -----------      1264179 07:16:18 SQL> select * from test;                    

Oracle Study之案例--Oracle 11g DataGuard Snapshot Standby

Oracle Study之案例--Oracle 11g  DataGuard Snapshot Standby Oracle 11g的Data Guard不仅仅带给我们的是Active Data Guard实时查询特性,同时还带来了另外一个新特性,这便是Snapshot Standby数据库功能,此项功能可将备库置身于"可读写状态"用于不方便在生产环境主库中测试的内容,比如模拟上线测试等任务.当备库读写状态下任务完成后,可以非常轻松的完成Snapshot Standby数据库角色切换回

Oracle Study之案例--异构平台传输表空间(Linux至AIX)

Oracle Study之案例--异构平台传输表空间(Linux至AIX) 系统架构: 可                   源    库               目标库 操作系统 Linux RH6    AIX 5.3-09 主机名 rh6(192.168.8.245) aix211(192.168.8.211) 数据版本 Oracle 11gR2 Oracle 11gR2 数据库名 prod orcl 表空间 test1 test1    可传输表空间概述 Oracle 的可传输表空

Oracle Study之案例--RMAN ORA-19921错误

Oracle Study之案例--RMAN ORA-19921错误 系统环境: 操作系统: AIX5.3 Oracle:   Oracle 10gR2 错误现象:         数据库在通过rman连接时出现以下错误: [11:01:51 [email protected]: ~]$rman target / Recovery Manager: Release 10.2.0.1.0 - Production on Mon Jan 19 11:01:53 2015 Copyright (c) 1

Oracle Study之案例--Oracle ASSM管理方式下的BITMAP

Oracle Study之案例--Oracle ASSM管理方式下的Bitmap      在基于此在LMT(Extent Local Management)下Oracle建议我们使用ASSM(Automatic Segment-Space Management),看看 Oracle doc是如何来解释ASSM的: This keyword tells Oracle that you want to use bitmaps to manage the free space with in seg

Oracle Study之案例--重建数据库控制文件

Oracle Study之案例--重建数据库控制文件 系统环境: 操作系统: Linux RH6 数据库:   Oracle 11gR2    案例分析:           数据库中所有的控制文件被意外破坏,非归档的库,在有trace备份的情况下,重建控制文件. 1.控制文件trace脚本 [[email protected] ~]$ cat crctr.sql  CREATE CONTROLFILE REUSE DATABASE "TEST3" NORESETLOGS  NOARC

Oracle Study之案例--AIX安装RAC错误之(rootpre)

Oracle Study之案例--AIX安装RAC错误之(rootpre) Oracle 10g for AIX 5309 rootpre执行时报以下错误: # ./rootpre.sh Required file ./pw-syscall32 is missing. 解决办法: 1.下载补丁号2896876,上传至服务端重新执行即可 2.以下方法没有尝试(仅作参考) Copy the "rootpre" sub-directory to a temporary location an

Oracle Study之案例--RMAN备份配置参数

Oracle Study之案例--RMAN备份配置参数 1.PARALLELISM  我们还可以通过parallelism参数来指定同时"自动"创建多少个通道:RMAN > configure device type disk parallelism 3 ; 表示启动三个通道,可以加快备份恢复的速度. 案例分析: RMAN> show all; using target database control file instead of recovery catalog CO