您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。