[bbk4485]第二章Flashback Database 03

Flashback Database:Examples

To flashback:Mounted(in exlusive mode)databse

RMAN>FLASHBACK DATABASE TO TIME = "TO_DATE('2009-05-27 16:00:00','YYYY-MM-DD HH24:MI:SS')";

RMAN>FLASHBACK DATABASE TO SCN=23536;

RMAN>FLASHBACK DATABASE TO SEQUENCE=223 TRHRED=1;

Monitor progress of Flashabck Database with the V$SESSION_LONGOPS view.

SQL>FLASHBACK DATABASE TO TIMESTAMP(SYSDATE-1/24);

SQL>FLASHBACK DATABASE TO SCN 533456;

SQL>FLASHBACK DATABASE TO RESTORE POINT b4_load;

To review changes:Read-only opened database

To finalize:Read/write opened database with RESETLOGS

实现flashback database 的步骤

1、关闭数据库

shutdown

2、mount数据库

startup mount

3、执行闪回操作

FLASHBACK DATABASE TO TIMESTAME(SYSDATE-1/24);

4、打开数据库

alter database open resetlogs;

第四步骤意义解析:执行完成闪回操作之后,此时的数据文件与控制文件、联机重做日志文件的检查点是不一致的,此时数据库时无法正常打开的(只有三大核心文件对应的检查点一致的时候,数据库才可以正常顺利打开).alter database open resetlogs的执行意义就在于将数据库文件、控制文件、联机重做你日志文件对应的检查点保持一致.

/***************************************************************************************************************************************/

flashback database lab.

/***************************************************************************************************************************************/

一、实验准备

实验用户:U2

实验所使用到的表:T

SQL> desc t;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPLOYEE_ID                                        NUMBER(6)
 FIRST_NAME                                         VARCHAR2(20)
 LAST_NAME                                 NOT NULL VARCHAR2(25)
 EMAIL                                     NOT NULL VARCHAR2(25)
 PHONE_NUMBER                                       VARCHAR2(20)
 HIRE_DATE                                 NOT NULL DATE
 JOB_ID                                    NOT NULL VARCHAR2(10)
 SALARY                                             NUMBER(8,2)
 COMMISSION_PCT                                     NUMBER(2,2)
 MANAGER_ID                                         NUMBER(6)
 DEPARTMENT_ID                                      NUMBER(4)
SQL> select employee_id,last_name,salary from t;

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        198 OConnell                        2600
        199 Grant                           2600
        200 Whalen                          4400
        201 Hartstein                      13000
        202 Fay                             6000
        203 Mavris                          6500
        204 Baer                           10000
        205 Higgins                        12008
        206 Gietz                           8300
        100 King                           24000
        101 Kochhar                        17000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        102 De Haan                        17000
        103 Hunold                          9000
        104 Ernst                           6000
        105 Austin                          4800
        106 Pataballa                       4800
        107 Lorentz                         4200
        108 Greenberg                      12008
        109 Faviet                          9000
        110 Chen                            8200
        111 Sciarra                         7700
        112 Urman                           7800

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        113 Popp                            6900
        114 Raphaely                       11000
        115 Khoo                            3100
        116 Baida                           2900
        117 Tobias                          2800
        118 Himuro                          2600
        119 Colmenares                      2500
        120 Weiss                           8000
        121 Fripp                           8200
        122 Kaufling                        7900
        123 Vollman                         6500

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        124 Mourgos                         5800
        125 Nayer                           3200
        126 Mikkilineni                     2700
        127 Landry                          2400
        128 Markle                          2200
        129 Bissot                          3300
        130 Atkinson                        2800
        131 Marlow                          2500
        132 Olson                           2100
        133 Mallin                          3300
        134 Rogers                          2900

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        135 Gee                             2400
        136 Philtanker                      2200
        137 Ladwig                          3600
        138 Stiles                          3200
        139 Seo                             2700
        140 Patel                           2500
        141 Rajs                            3500
        142 Davies                          3100
        143 Matos                           2600
        144 Vargas                          2500
        145 Russell                        14000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        146 Partners                       13500
        147 Errazuriz                      12000
        148 Cambrault                      11000
        149 Zlotkey                        10500
        150 Tucker                         10000
        151 Bernstein                       9500
        152 Hall                            9000
        153 Olsen                           8000
        154 Cambrault                       7500
        155 Tuvault                         7000
        156 King                           10000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        157 Sully                           9500
        158 McEwen                          9000
        159 Smith                           8000
        160 Doran                           7500
        161 Sewall                          7000
        162 Vishney                        10500
        163 Greene                          9500
        164 Marvins                         7200
        165 Lee                             6800
        166 Ande                            6400
        167 Banda                           6200

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        168 Ozer                           11500
        169 Bloom                          10000
        170 Fox                             9600
        171 Smith                           7400
        172 Bates                           7300
        173 Kumar                           6100
        174 Abel                           11000
        175 Hutton                          8800
        176 Taylor                          8600
        177 Livingston                      8400
        178 Grant                           7000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        179 Johnson                         6200
        180 Taylor                          3200
        181 Fleaur                          3100
        182 Sullivan                        2500
        183 Geoni                           2800
        184 Sarchand                        4200
        185 Bull                            4100
        186 Dellinger                       3400
        187 Cabrio                          3000
        188 Chung                           3800
        189 Dilly                           3600

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        190 Gates                           2900
        191 Perkins                         2500
        192 Bell                            4000
        193 Everett                         3900
        194 McCain                          3200
        195 Jones                           2800
        196 Walsh                           3100
        197 Feeney                          3000

107 rows selected.
从HR.EMPLOYEES中复制表结构,表数据至T;

二、模拟误操作你,将表中所有人员工资都改成1000;并记录误操作时间:

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') "sysdate" from dual;

sysdate
-------------------
2013-05-15 17:53:00
记录误操作之前时间
SQL> update t set salary=1000;

107 rows updated.

SQL> commit;

Commit complete.
误操作修改工资为1000,并提交数据.
SQL> select employee_id,last_name,salary from t;

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        198 OConnell                        1000
        199 Grant                           1000
        200 Whalen                          1000
        201 Hartstein                       1000
        202 Fay                             1000
        203 Mavris                          1000
        204 Baer                            1000
        205 Higgins                         1000
        206 Gietz                           1000
        100 King                            1000
        101 Kochhar                         1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        102 De Haan                         1000
        103 Hunold                          1000
        104 Ernst                           1000
        105 Austin                          1000
        106 Pataballa                       1000
        107 Lorentz                         1000
        108 Greenberg                       1000
        109 Faviet                          1000
        110 Chen                            1000
        111 Sciarra                         1000
        112 Urman                           1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        113 Popp                            1000
        114 Raphaely                        1000
        115 Khoo                            1000
        116 Baida                           1000
        117 Tobias                          1000
        118 Himuro                          1000
        119 Colmenares                      1000
        120 Weiss                           1000
        121 Fripp                           1000
        122 Kaufling                        1000
        123 Vollman                         1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        124 Mourgos                         1000
        125 Nayer                           1000
        126 Mikkilineni                     1000
        127 Landry                          1000
        128 Markle                          1000
        129 Bissot                          1000
        130 Atkinson                        1000
        131 Marlow                          1000
        132 Olson                           1000
        133 Mallin                          1000
        134 Rogers                          1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        135 Gee                             1000
        136 Philtanker                      1000
        137 Ladwig                          1000
        138 Stiles                          1000
        139 Seo                             1000
        140 Patel                           1000
        141 Rajs                            1000
        142 Davies                          1000
        143 Matos                           1000
        144 Vargas                          1000
        145 Russell                         1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        146 Partners                        1000
        147 Errazuriz                       1000
        148 Cambrault                       1000
        149 Zlotkey                         1000
        150 Tucker                          1000
        151 Bernstein                       1000
        152 Hall                            1000
        153 Olsen                           1000
        154 Cambrault                       1000
        155 Tuvault                         1000
        156 King                            1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        157 Sully                           1000
        158 McEwen                          1000
        159 Smith                           1000
        160 Doran                           1000
        161 Sewall                          1000
        162 Vishney                         1000
        163 Greene                          1000
        164 Marvins                         1000
        165 Lee                             1000
        166 Ande                            1000
        167 Banda                           1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        168 Ozer                            1000
        169 Bloom                           1000
        170 Fox                             1000
        171 Smith                           1000
        172 Bates                           1000
        173 Kumar                           1000
        174 Abel                            1000
        175 Hutton                          1000
        176 Taylor                          1000
        177 Livingston                      1000
        178 Grant                           1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        179 Johnson                         1000
        180 Taylor                          1000
        181 Fleaur                          1000
        182 Sullivan                        1000
        183 Geoni                           1000
        184 Sarchand                        1000
        185 Bull                            1000
        186 Dellinger                       1000
        187 Cabrio                          1000
        188 Chung                           1000
        189 Dilly                           1000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        190 Gates                           1000
        191 Perkins                         1000
        192 Bell                            1000
        193 Everett                         1000
        194 McCain                          1000
        195 Jones                           1000
        196 Walsh                           1000
        197 Feeney                          1000

107 rows selected.
查询误操作之后的表数据

三、开始进行flashback database操作

SQL> conn /as sysdba
Connected.
1、以sysdba身份登录数据
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
shutdown database
SQL> startup mount
ORACLE instance started.

Total System Global Area 3256942592 bytes
Fixed Size                  2217752 bytes
Variable Size            1845496040 bytes
Database Buffers         1392508928 bytes
Redo Buffers               16719872 bytes
Database mounted.
mount databvase
SQL> FLASHBACK DATABASE TO TIMESTAMP TO_TIMESTAMP('2013-05-15 17:53:00','yyyy-mm-dd hh24:mi:ss');

Flashback complete.
执行闪回操作
SQL> alter database open resetlogs;

Database altered.
resetlogs opt

四、验证数据

SQL> conn U2/U2
Connected.
SQL> select employee_id,last_name,salary from t;

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        198 OConnell                        2600
        199 Grant                           2600
        200 Whalen                          4400
        201 Hartstein                      13000
        202 Fay                             6000
        203 Mavris                          6500
        204 Baer                           10000
        205 Higgins                        12008
        206 Gietz                           8300
        100 King                           24000
        101 Kochhar                        17000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        102 De Haan                        17000
        103 Hunold                          9000
        104 Ernst                           6000
        105 Austin                          4800
        106 Pataballa                       4800
        107 Lorentz                         4200
        108 Greenberg                      12008
        109 Faviet                          9000
        110 Chen                            8200
        111 Sciarra                         7700
        112 Urman                           7800

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        113 Popp                            6900
        114 Raphaely                       11000
        115 Khoo                            3100
        116 Baida                           2900
        117 Tobias                          2800
        118 Himuro                          2600
        119 Colmenares                      2500
        120 Weiss                           8000
        121 Fripp                           8200
        122 Kaufling                        7900
        123 Vollman                         6500

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        124 Mourgos                         5800
        125 Nayer                           3200
        126 Mikkilineni                     2700
        127 Landry                          2400
        128 Markle                          2200
        129 Bissot                          3300
        130 Atkinson                        2800
        131 Marlow                          2500
        132 Olson                           2100
        133 Mallin                          3300
        134 Rogers                          2900

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        135 Gee                             2400
        136 Philtanker                      2200
        137 Ladwig                          3600
        138 Stiles                          3200
        139 Seo                             2700
        140 Patel                           2500
        141 Rajs                            3500
        142 Davies                          3100
        143 Matos                           2600
        144 Vargas                          2500
        145 Russell                        14000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        146 Partners                       13500
        147 Errazuriz                      12000
        148 Cambrault                      11000
        149 Zlotkey                        10500
        150 Tucker                         10000
        151 Bernstein                       9500
        152 Hall                            9000
        153 Olsen                           8000
        154 Cambrault                       7500
        155 Tuvault                         7000
        156 King                           10000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        157 Sully                           9500
        158 McEwen                          9000
        159 Smith                           8000
        160 Doran                           7500
        161 Sewall                          7000
        162 Vishney                        10500
        163 Greene                          9500
        164 Marvins                         7200
        165 Lee                             6800
        166 Ande                            6400
        167 Banda                           6200

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        168 Ozer                           11500
        169 Bloom                          10000
        170 Fox                             9600
        171 Smith                           7400
        172 Bates                           7300
        173 Kumar                           6100
        174 Abel                           11000
        175 Hutton                          8800
        176 Taylor                          8600
        177 Livingston                      8400
        178 Grant                           7000

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        179 Johnson                         6200
        180 Taylor                          3200
        181 Fleaur                          3100
        182 Sullivan                        2500
        183 Geoni                           2800
        184 Sarchand                        4200
        185 Bull                            4100
        186 Dellinger                       3400
        187 Cabrio                          3000
        188 Chung                           3800
        189 Dilly                           3600

EMPLOYEE_ID LAST_NAME                     SALARY
----------- ------------------------- ----------
        190 Gates                           2900
        191 Perkins                         2500
        192 Bell                            4000
        193 Everett                         3900
        194 McCain                          3200
        195 Jones                           2800
        196 Walsh                           3100
        197 Feeney                          3000

107 rows selected.
validate data

 

posted @ 2013-05-15 18:00  ArcerZhang  阅读(256)  评论(0编辑  收藏  举报