使用RMAN对PDB执行闪回数据库操作

可以对多租户数据库中的单个PDB执行闪回操作。对特定的PDB执行闪回数据库操作只会修改与这个PDB相关文件中的数据。CDB中的其它PDB不受影响处于可读写状态。如果使用还原点,在执行闪回数据库操作时可以使用CDB还原点,PDB还原点,PDB清晰还原点或PDB受保证的还原点。对PDB执行闪回数据库操作的步骤如下:
1.使用有sysdba或sysbackup权限的公共用户连接到root容器

SQL> conn / as sysdba
Connected.

2.确保CDB处于open状态

SQL> SELECT open_mode from V$DATABASE;

OPEN_MODE
--------------------
READ WRITE

3.登录PDB(jypdb)记录当前SCN号,然后删除表t1中的数据

SQL> conn jy/jy@jypdb
Connected.
SQL> SELECT CURRENT_SCN   FROM V$DATABASE;

CURRENT_SCN
-----------
    6024220

SQL> select count(*) from t1;

  COUNT(*)
----------
        39

SQL> delete from t1;

39 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from t1;

  COUNT(*)
----------
         0

4.确保要执行闪回数据库的PDB(jypdb)处于close状态。

SQL> conn / as sysdba
Connected.
SQL> alter pluggable database jypdb close immediate;

Pluggable database altered.

SQL> select name,open_mode from v$pdbs;

NAME                                                                                                                             OPEN_MODE
-------------------------------------------------------------------------------------------------------------------------------- ----------
PDB$SEED                                                                                                                         READ ONLY
JYPDB                                                                                                                            MOUNTED
TESTPDB                                                                                                                          READ WRITE

5.将PDB(jypdb)闪回到scn=6024220所在的状态

RMAN> flashback pluggable database jypdb to scn 6024220;

Starting flashback at 18-DEC-17
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 instance=jy1 device type=DISK


starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished flashback at 18-DEC-17

6. 将CDB设置为只读状态

RMAN> alter pluggable database jypdb open read only;

Statement processed

7.检查闪回数据库操作的结果是否满足要求

SQL> conn jy/jy@jypdb
Connected.
SQL> select count(*) from t1;

  COUNT(*)
----------
        39

8.如果闪回操作后满足你所要求的结果,那么可以执行以下两个相互排斥的选项:
.使用resetlogs选项将数据库打开。如果当前数据库为只读状态,那么使用SQL*Plus执行以下命令:

alter pluggable database jypdb close immediate;
alter pluggable database jypdb open resetlogs;

.使用Oracle Data Pump导出你所需要的对象,然后使用RMAN来恢复数据库到当前时间,通过对数据库重新应用重做日志中的所有改变来将
数据库恢复到当前时间点从而撤消闪回数据库所做的改变。

RMAN> recover pluggable database jypdb ;

Starting recover at 18-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 instance=jy1 device type=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 18-DEC-17

RMAN> alter pluggable database jypdb open read write;

Statement processed
starting full resync of recovery catalog
full resync complete

发表评论

电子邮件地址不会被公开。