应用范围
Oracle Server企业版,版本号:10.2.0.1到11.2.0.2.0版本。
本文适用于任何操作系统平台。
本文目的
本文将详细叙述如何通过flshback技术来恢复被错误删除的用户。
范围及应用
本文对各种经验的DBA都适用。
操作先决条件
-数据库必须为归档模式
-数据库必须开启了Flashback功能。
-所恢复的用户,删除时间必须在db_flashback_retention_target参数所指定的范围 内,且所有的闪回及归档日志必须都有效。
-用户的schema,所有的对象都不允许有NOLOGGING操作。
使用数据库闪回功能恢复被删除的用户
本测试包含以下步骤:
步骤1:确保闪回日志有效
步骤2:模拟人为错误,即删除用户(Drop User)
步骤3:使用闪回功能
步骤4:以只读模式打开数据库闪回功能
步骤5:检查用户及数据是否有效
步骤6:对删除的shema进行完全导出操作
步骤7:使用完全恢复来使其恢复到当前状态
步骤8:导入用户来解决人为错误,即删除用户(Drop User)错误
下面今夕详细说明:
***完整的恢复被删除的用户***
1. 确保数据库处于闪回模式
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
SQL> show parameter flash
NAME VALUE
------------------------------- -----------
db_flashback_retention_target 1440
SQL> select oldest_flashback_scn,oldest_flashback_time from $flashback_database_log ;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIM
--------------------------------- --------------------------------
24300236 29-MAY-2009 12:56:13
2. 模拟操作,以一个用户创建表,并删除此用户。
SQL> conn falshback_test/flashback
Connected.
SQL> create table flashback_testing ( col1 varchar2(20));
Table created.
SQL> insert into flashback_testing values ( 'flashback testing');
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
Session altered.
SQL> select sysdate from dual;
SYSDATE
--------------------
29-MAY-2009 14:32:50
SQL> conn / as sysdba
Connected.
SQL> drop user falshback_test CASCADE;
User dropped.
3. 为了恢复丢失的schema,使用数据库闪回特性来恢复到删除用户之前的某个时间点
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 289406976 bytes
Fixed Size 1290208 bytes
Variable Size 142606368 bytes
Database Buffers 142606336 bytes
Redo Buffers 2904064 bytes
Database mounted.
SQL> flashback database to timestamp to_date('29-MAY-2009 14:30:00','DD-MON-YYYY
HH24:MI:SS');
Flashback complete.
4. 以只读模式打开数据库
SQL> alter database open read only;
Database altered.
5. 检查用户及其数据
SQL> conn FALSHBACK_TEST/flashback
Connected.
SQL> select * from flashback_testing;
COL1
--------------------
flashback testing
SQL> exit
6. 导出用户
C:\>exp owner=falshback_test file=E:\temp\exp1.dmp
Export: Release 10.2.0.4.0 - Production on Fri May 29 20:23:40 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Username: / as sysdba
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user FALSHBACK_TEST
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user FALSHBACK_TEST
About to export FALSHBACK_TEST's objects ...
. about to export FALSHBACK_TEST's tables via Conventional Path ...
. . exporting table FLASHBACK_TESTING 1 rows exported
. exporting synonyms
. exporting views
....
. exporting statistics
Export terminated successfully without warnings
7. 关闭数据库,恢复数据库到当前状态
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 289406976 bytes
Fixed Size 1290208 bytes
Variable Size 142606368 bytes
Database Buffers 142606336 bytes
Redo Buffers 2904064 bytes
Database mounted.
SQL> recover database;
Media recovery complete.
SQL> alter database open;
Database altered.
现在,数据库已恢复到未删除用户时的状态,但我们在其删除前将其从数据库中全部导出并转储了。
8. 创建被删除的用户,且通过转储的数据导入到数据库中
SQL> create user falshback_test identified by flashback default tablespace users quota unlimited on users;
User created.
SQL> -- Grant the necessary priviledge to that user
C:\>imp full=y file=E:\temp\exp1.dmp
Import: Release 10.2.0.4.0 - Production on Fri May 29 20:26:14 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Username: / as sysdba
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
. importing SYS's objects into SYS
. importing FALSHBACK_TEST's objects into FALSHBACK_TEST
. . importing table "FLASHBACK_TESTING" 1 rows imported
Import terminated successfully without warnings.
现在,数据库已经恢复了删除的表,也没有数据丢失了。
本文局限
l 如果任何闪回日志或归档日志丢失,则以上操作均无法进行
l 如果恢复这些NOLOGGING事务块之后,进行了NOLOGGING操作,将发生故障。因此,应尽量避免在一个使用了NOLOGGING操作的时间点或SCN,进行数据库闪回操作。
相关产品
* Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition
关键字
FLASHBACK; RECOVER DATABASE