ITPub博客

首页 > 数据库 > Oracle > flashback系列文章三(flashback database)

flashback系列文章三(flashback database)

原创 Oracle 作者:thamsyangsw 时间:2013-12-31 22:38:26 0 删除 编辑
从oracle10g开始,新增flashback database功能。
需要首先开启flashback_on,把数据库启动到mount状态

SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              75499088 bytes
Database Buffers          205520896 bytes
Redo Buffers                2973696 bytes
Database mounted.


SQL> alter database flashback on;

Database altered.

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES
SQL> alter database open;

Database altered.
类似于redo log,在启用flashback database之后oracle会启用rvwr进程,把undo写入到闪回日志文件中
[oracle@rac1 ~]$ ps -ef|grep rvwr|grep -v grep
oracle    7421     1  0 16:28 ?        00:00:00 ora_rvwr_dcits

SQL> show parameter recovery

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     0


[oracle@rac1 flashback]$ date
Tue Dec 31 17:58:38 CST 2013
[oracle@rac1 flashback]$ pwd
/u01/app/oracle/flash_recovery_area/DCITS/flashback
[oracle@rac1 flashback]$ ll
total 8020
-rw-r-----  1 oracle oinstall 8200192 Dec 31 17:56 o1_mf_9d501fd4_.flb
可见flashback设置成on之后已经生成了一个flashback日志了


db_flashback_retention_target参数以分钟为单位,定义了数据库能够闪回的时间上限。
SQL> show parameter db_flashback_retention_target

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target        integer     1440


创建个测试表,记录下时间和scn,等下用timestamp和scn恢复下数据库

SQL> conn scott/tiger
Connected.
SQL> create table test(id number);

Table created.

SQL> insert into test values(100);

1 row created.

SQL> insert into test values(200);

1 row created.

SQL> commit;

Commit complete.

SQL> select to_char(sysdate,;yyyy-mm-dd hh24:mi:ss') from dual;
ERROR:
ORA-01756: quoted string not properly terminated


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

TO_CHAR(SYSDATE,'YY
-------------------
2013-12-31 22:06:20

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
                  835057

SQL> drop table test;

Table dropped.

下面我们分别用时间戳和scn进行恢复数据库

SQL> conn sys/oracle as sysdba
Connected.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              71304784 bytes
Database Buffers          209715200 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> flashback database to scn 835057;

Flashback complete.


SQL> alter database open read only;

Database altered.

SQL> conn scott/tiger
Connected.
SQL> select * from test;

        ID
----------
       100
       200

可以看见删掉的表被恢复了。
下面类似的通过timestamp来flashback database

SQL> conn sys/oracle as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              71304784 bytes
Database Buffers          209715200 bytes
Redo Buffers                2973696 bytes
Database mounted.

SQL> flashback database to timestamp to_timestamp('2013-12-31 22:06:20','yyyy-mm-dd hh24:mi:ss');

Flashback complete.

SQL> alter database open read only;

Database altered.

SQL> conn scott/tiger
Connected.
SQL> select * from test;

        ID
----------
       100
       200

如果确认恢复完毕了,使用resetlogs重新启动下数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size              71304784 bytes
Database Buffers          209715200 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SQL> alter database open resetlogs;

Database altered.




 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26613085/viewspace-1066111/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-01-12

  • 博文量
    161
  • 访问量
    1235403