场景描述
- 误 drop 了生产库中的用户 U1
- U1 用户下面有 3 张表(T1-T3),表中数据如下所示:
SQL> conn u1/u1
Connected.
SQL> select TABLE_NAME from user_tables;
TABLE_NAME
------------------------------
T1
T2
T3
SQL> select * from t1;
ID NAME
---------- --------------------
2 xyz
SQL> select * from t2;
ID
----------
10
SQL> select * from t3;
ID LAST_NAME FIRST_NAME
---------- -------------------- --------------------
1 Zhang lili
2 li lei
前期准备
- 第一步,查询 v$log、v$archived_log中每个日志的 First SCN/ First Time 和 Next SCN/Next Time,根据时间推测该删除操作会在哪个日志中
- 第二步,使用 Toad 挖掘日志( 因为删除一个用户,会先删除用户下的所有对象,然后再删除用户,所以要找到删除属于它的对象的最早的 SCN,在本例中应选择 1794239)
执行闪回
-
环境描述
- 生产库的版本是 11.2.0.4,搭建了 Data Guard,备库启用了闪回特性
- 在备库执行闪回操作
-
1)停止 Redo Apply
SQL> alter database recover managed standby database cancel;
Database altered.
- 如果不停止 Redo Apply 的话,在执行闪回时会报错
SQL> FLASHBACK DATABASE TO SCN 1794239;
FLASHBACK DATABASE TO SCN 1794239
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active
- 2)闪回数据库
SQL> FLASHBACK DATABASE TO SCN 1794239;
Flashback complete.
- 3)查看用户相关信息,确认用户是否已经恢复
- 4)在备库使用 exp 导出用户数据(无法使用数据泵技术,因为备库的模式是 read only,所以使用了 exp 导出数据)
exp system/oracle owner=u1 file=/tmp/test.dump
- 5)需要在主库建立用户 U1 并授权
- 如果不建立用户,在导入的时候会报错(ORA-01435: user does not exist)
- 如果不授权,在导入的时候会报错(ORA-01950: no privileges on tablespace 'USERS')
SQL> create user u1 identified by "123abc";
SQL> grant connect,resource to u1;
- 6)在备库连接主库 orcl,然后导入文件
[oracle@db11gstandby ~]$ imp system/oracle@orcl file=/tmp/test.dump full=y
Import: Release 11.2.0.4.0 - Production on Wed Jun 21 19:32:17 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
. importing SYSTEM's objects into SYSTEM
. importing U1's objects into U1
. . importing table "T1" 1 rows imported
. . importing table "T2" 1 rows imported
. . importing table "T3" 2 rows imported
Import terminated successfully without warnings.
- 7)注意:在闪回操作完成后,开启 Redo Apply,此时备库又可以与主库同步