对CDB执行闪回数据库与对non-CDB执行闪回数据库操作是类似的,具体操作步骤如下:
1.使用SQL*Plus连接到目标数据库来判断闪回操作的的目标SCN,还原点或时间点
SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG; OLDEST_FLASHBACK_SCN OLDEST_FLASH -------------------- ------------ 5090113 17-DEC-17 SQL> SELECT CURRENT_SCN FROM V$DATABASE; CURRENT_SCN ----------- 6003920
2.删除表t1中的数据
SQL> select count(*) from t1; COUNT(*) ---------- 39 SQL> delete from t1; 39 rows deleted. SQL> commit; Commit complete.
3.关闭数据库,并确保没有任何实例打开数据库,然后启动到mount状态
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 6442450944 bytes Fixed Size 8807168 bytes Variable Size 1895828736 bytes Database Buffers 4529848320 bytes Redo Buffers 7966720 bytes Database mounted.
4.运行flashback database命令将整个CDB闪回到指定的时间点
SQL> flashback database to scn 6003920; Flashback complete.
5.在SQL*Plus命令窗口中将CDB设置为只读状态
SQL> alter database open read only; Database altered.
6.如果闪回操作后满足你所要求的结果,那么可以执行以下两个相互排斥的选项:
.使用resetlogs选项将数据库打开。如果当前数据库为只读状态,那么使用SQL*Plus执行以下命令:
shutdown immediate startup mount alter database open resetlogs
.使用Oracle Data Pump导出你所需要的对象,然后使用RMAN来恢复数据库到当前时间,通过对数据库重新应用重做日志中的所有改变来将
数据库恢复到当前时间点从而撤消闪回数据库所做的改变。
RMAN> recover database; 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:02 Finished recover at 18-DEC-17 Media recovery complete. SQL> alter database open; Database altered. SQL> alter pluggable database all open read write; Pluggable database altered.