本文小编为大家详细介绍“Oracle闪回数据库怎么实现”,内容详细,步骤清晰,细节处理妥当,希望这篇“Oracle闪回数据库怎么实现”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
在Oracle Database 12.1中,闪回数据库操作仅限于根容器,因此会影响与根容器关联的所有可插拔数据库(PDB)。 Oracle Database 12.2现在支持可插拔数据库的闪回,使闪回数据库在多租户架构中再次相关。
将数据库启动到mount阶段,开启闪回,然后open,再启用FLASHBACK
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> STARTUP MOUNT ORACLE instance started. Total System Global Area 1308622848 bytes Fixed Size 8792440 bytes Variable Size 905971336 bytes Database Buffers 385875968 bytes Redo Buffers 7983104 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL> alter database open; Database altered.
指定闪回恢复区目录和大小
SQL> alter system set db_recovery_file_dest_size=5G; System altered. SQL> alter system set db_recovery_file_dest='/home/oracle/archivelog'; System altered. SQL> alter database flashback on; Database altered.
关闭闪回
SQL> alter database flashback off; Database altered.
查看结果
SQL> SELECT flashback_on FROM v$database; FLASHBACK_ON ------------------------------------ YES
闪回日志保留的数量是受参数DB_FLASHBACK_RETENTION_TARGET控制的,该参数表示保留时间(分钟),默认为7天。
SQL> show parameter DB_FLASHBACK_RETENTION_TARGE NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ db_flashback_retention_target integer 1440
恢复点实际上是记录当时的SCN。要想恢复到之前创建的还原点,要保证还原点之后的闪回日志是完整的。
在CDB级别创建恢复点与non-CDB相同。 以下示例在CDB级别分别创建和删除正常,保证的还原点。
正常的还原点
CREATE RESTORE POINT cdb1_before_changes; DROP RESTORE POINT cdb1_before_changes;
保证的还原点(Guaranteed restore point)
CREATE RESTORE POINT cdb1_before_changes GUARANTEE FLASHBACK DATABASE; DROP RESTORE POINT cdb1_before_changes;
下面是在PDB级别创建还原点的几个选项。
SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB MOUNTED
–切换到PDB
SQL> alter session set container=orclpdb; Session altered. SQL> startup Pluggable Database opened.
–正常的还原点
SQL> create restore point pdb1_point1; Restore point created. SQL> drop restore point pdb1_point1; Restore point dropped.
–保证的还原点(Guaranteed restore point)
SQL> create restore point pdb1_point1 GUARANTEE FLASHBACK DATABASE; Restore point created. SQL> drop restore point pdb1_point1; Restore point dropped.
注:如果容器数据库是以本地模式运行的就不用看这个章节。
本地模式运行的容器数据库,闪回PDB不依赖它。但是如果CDB再共享模式下运行,那么闪回到干净的还原点将更有效。这些是当可插拔数据库关闭的时候没有未完成的事务。
语法和上面相似,只是多加了个单词。而且要关闭PDB
如:
切换到PDB下执行:
SQL> alter session set container=orclpdb; SQL> shutdown immediate;
– 干净正常的还原点
SQL> CREATE CLEAN RESTORE POINT cdb1_before_changes; SQL> DROP RESTORE POINT cdb1_before_changes;
– 干净保证的还原点(Guaranteed restore point)
SQL> CREATE CLEAN RESTORE POINT cdb1_before_changes GUARANTEE FLASHBACK DATABASE; SQL> DROP RESTORE POINT cdb1_before_changes;
CDB ROOT下执行:
SQL> ALTER PLUGGABLE DATABASE orclpdb CLOSE;
– 干净正常的还原点
SQL> CREATE CLEAN RESTORE POINT cdb1_before_changes FOR PLUGGABLE DATABASE orclpdb ; SQL> DROP RESTORE POINT cdb1_before_changes ;FOR PLUGGABLE DATABASE orclpdb ;
– 干净保证的还原点(Guaranteed restore point)
SQL> CREATE CLEAN RESTORE POINT cdb1_before_changes GUARANTEE FLASHBACK DATABASE FOR PLUGGABLE DATABASE orclpdb; SQL> DROP RESTORE POINT cdb1_before_changes ;FOR PLUGGABLE DATABASE orclpdb ; SQL> ALTER PLUGGABLE DATABASE orclpdb OPEN;
可以通过查看V$RESTORE_POINT视图中的CLEAN_PDB_RESTORE_POINT列所示。
闪回CDB如下:
SQL>SHUTDOWN IMMEDIATE; SQL>STARTUP MOUNT; SQL>FLASHBACK DATABASE TO RESTORE POINT cdb1_before_changes; ALTER DATABASE OPEN RESETLOGS;
– 打开所有PDB
SQL>ALTER PLUGGABLE DATABASE ALL OPEN RESETLOGS;
闪回还支持多种形式的闪回,如按时间,SCN,或者某个时间点之前。
如:
FLASHBACK DATABASE TO TIMESTAMP my_date; FLASHBACK DATABASE TO BEFORE TIMESTAMP my_date; FLASHBACK DATABASE TO SCN my_scn; FLASHBACK DATABASE TO BEFORE SCN my_scn; FLASHBACK DATABASE TO RESTORE POINT my_restore_point;
根据数据库运行的模式不同,操作也会有所不同。下面是本地UNDO模式的操作步骤:
SQL>ALTER PLUGGABLE DATABASE orclpdb CLOSE; SQL>FLASHBACK PLUGGABLE DATABASE orclpdb TO RESTORE POINT pdb1_before_changes; SQL>ALTER PLUGGABLE DATABASE orclpdb OPEN RESETLOGS;
如果使用的共享UNDO模式,语法有点不同,就是你需要制定辅助实例的位置。
SQL>FLASHBACK PLUGGABLE DATABASE orclpdb TO SCN my_scn AUXILIARY DESTINATION '/u01/auxiliary'; SQL>FLASHBACK PLUGGABLE DATABASE orclpdb TO RESTORE POINT my_restore_point AUXILIARY DESTINATION '/u01/auxiliary';
–创建还原点
SQL>CREATE RESTORE POINT pdb1_before_changes FOR PLUGGABLE DATABASE pdb1;
–创建表
SQL>CREATE TABLE t1 ( id NUMBER ); SQL>INSERT INTO t1 VALUES (1); SQL>COMMIT; SQL>SELECT * FROM t1; ID ---------- 1
闪回到指定还原点
SQL>Flashback the PDB to the restore point. SQL>ALTER PLUGGABLE DATABASE pdb1 CLOSE; SQL>FLASHBACK PLUGGABLE DATABASE pdb1 TO RESTORE POINT pdb1_before_changes; SQL>ALTER PLUGGABLE DATABASE pdb1 OPEN RESETLOGS;
–检查数据是否存在
SQL>SELECT * FROM t1; SELECT * FROM t1 * ERROR at line 1: ORA-00942: table or view does not exist
可以看到已经闪回到创建表之前的那个状态了。
读到这里,这篇“Oracle闪回数据库怎么实现”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。