首页 > Linux操作系统 > Linux操作系统 > Oracle 10g数据库闪回
数据库闪回是10g的新增内容。数据库闪回比传统的还原需要的时间短很多,因为它不是从原来的LGWR进程写入,而是由一个名为RVWR的新进程写入。从而避免了文件恢复的过程,缩减了恢复时间。而传统的恢复需要恢复数据文件,归档日志,通过日志恢复到某个时间点。
实验具体做法为:
第一步:以管理员用户登录到mount模式,开启数据库的flashback.
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 12月 13 12:31:05 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn sys/m1234 as sysdba
已连接。
SQL> startup mount
ORACLE 例程已经启动。
Total System Global Area 167772160 bytes
Fixed Size 1247876 bytes
Variable Size 79693180 bytes
Database Buffers 79691776 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL> alter database flashback on;
SQL> select dbid,name,flashback_on, from v$database;
DBID NAME FLASHBACK_ON
---------- --------- ------------------ -----------
1344481763 ORC1 YES
保持时间是1天(1440分钟)。
SQL> show parameter db_flashback;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
SQL> alter database open;
数据库已更改。
第二步:普通用户登录,truncate 表 emp1和emp3.
SQL> conn scott/m1234;
已连接。
SQL> select count(*) from emp2;
COUNT(*)
----------
0
SQL> select count(*) from emp3;
COUNT(*)
----------
17
SQL> select count(*) from emp1;
COUNT(*)
----------
17
SQL> select sysdate from dual;
SYSDATE
--------------
13-12月-10
SQL> select dbms_flashback.get_system_change_number scn from dual;
SCN
----------
2145772
SQL> truncate table emp1;
表被截断。
SQL> select dbms_flashback.get_system_change_number scn from dual;
SCN
----------
2145815
SQL> truncate table emp3;
表被截断。
SQL> select dbms_flashback.get_system_change_number scn from dual;
SCN
----------
2145850
第三步:管理员登录,进行还原。
SQL> conn system/m1234 as sysdba;
已连接。
SQL> alter database startup mount;
alter database startup mount
*
第 1 行出现错误:
ORA-01100: 数据库已装载
SQL> shutdown
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 167772160 bytes
Fixed Size 1247876 bytes
Variable Size 79693180 bytes
Database Buffers 79691776 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL> flashback database to scn 2145772;
闪回完成。
SQL> alter database open read only;
数据库已更改。
SQL> select count(*) from scott.emp1;
COUNT(*)
----------
17
SQL> select count(*) from scott.emp3;
COUNT(*)
----------
17
SQL> shutdown
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 167772160 bytes
Fixed Size 1247876 bytes
Variable Size 79693180 bytes
Database Buffers 79691776 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL> flashback database to scn 2145815;
闪回完成。
SQL> alter database open read only;
数据库已更改。
SQL> select count(*) from scott.emp1;
COUNT(*)
----------
0
SQL> select count(*) from scott.emp3;
COUNT(*)
----------
17
SQL> shutdown
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 167772160 bytes
Fixed Size 1247876 bytes
Variable Size 79693180 bytes
Database Buffers 79691776 bytes
Redo Buffers 7139328 bytes
数据库装载完毕。
SQL> flashback database to scn 2145772;
闪回完成。
SQL> alter database open resetlogs;
数据库已更改。
SQL> select count(*) from scott.emp1;
COUNT(*)
----------
17
SQL> select count(*) from scott.emp3;
COUNT(*)
----------
17
本实验的第二步使用了truncate操作,因为这个操作是不能用闪回表恢复的,记住删除这两张表的SCN,不同的SCN恢复的结果不一样。恢复时需要resetlogs。这些步骤也可以在Alert.log中看到 :
Mon Dec 13 12:48:23 2010
flashback database to scn 2145772
Mon Dec 13 12:48:24 2010
Flashback Restore Start
Flashback Restore Complete
Flashback Media Recovery Start
parallel recovery started with 2 processes
Mon Dec 13 12:48:26 2010
Recovery of Online Redo Log: Thread 1 Group 1 Seq 54 Reading mem 0
Mem# 0 errs 0: I:\ORADATA\ORC1\REDO01.LOG
Mon Dec 13 12:48:28 2010
Incomplete Recovery applied until change 2145784 ?
Flashback Media Recovery Complete
Completed: flashback database to scn 2145772
Mon Dec 13 12:48:49 2010
alter database open resetlogs
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22528444/viewspace-681780/ ,如需转载,请注明出处,否则将追究法律责任。