您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關Oracle 18c新特性-PDB快照輪播的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
Oracle 18c推出的一個新功能就是PDB快照輪播,最多可以創建8個pdb的快照,而這8個構成的一組快照就被稱作快照輪播。當達到第8個快照限制時,新的快照就會覆蓋最舊的快照,就像redo log一樣。PDB的快照主要作用是當出現了問題可以閃回到快照的時間點,另一個功能是基于快照來查詢歷史數據。
SQL> SELECT r.CON_ID, p.PDB_NAME, PROPERTY_NAME, PROPERTY_VALUE AS value, DESCRIPTION FROM CDB_PROPERTIES r, CDB_PDBS p WHERE r.CON_ID = p.CON_ID AND PROPERTY_NAME LIKE 'MAX_PDB%' AND description like 'maximum%' ORDER BY PROPERTY_NAME; CON_ID PDB_NAME PROPERTY_NAME VALUE DESCRIPTION ---------- -------------------- -------------------- -------------------- ---------------------------------------------------------------------- 3 ORCLPDB1 MAX_PDB_SNAPSHOTS maximum number of snapshots for a given PDB
默認情況下是手動創建快照,我們可以把它改成自動創建。
SQL> select snapshot_mode,snapshot_interval/60 from dba_pdbs; SNAPSH SNAPSHOT_INTERVAL/60 ------ -------------------- MANUAL SQL> alter pluggable database snapshot mode every 4 hours; Pluggable database altered. SQL> select snapshot_mode,snapshot_interval/60 from dba_pdbs; SNAPSH SNAPSHOT_INTERVAL/60 ------ -------------------- AUTO 4
要返回手動模式,輸入mode manual即可。
SQL> alter pluggable database snapshot mode manual; Pluggable database altered. SQL> alter pluggable database snapshot; Pluggable database altered.
手動創建快照,可以自己指定名字,也可以使用系統自動生成的名字。通過查看DBA_PDB_SNAPSHOTS視圖,可以找到快照存放的路徑及創建快照的SCN號。
SQL> SELECT CON_ID, CON_NAME, SNAPSHOT_NAME, SNAPSHOT_SCN AS snap_scn, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN FULL_SNAPSHOT_PATH ---------- -------------------- ------------------------- ---------- --------------------------------------------------------------------------- 3 ORCLPDB1 SNAP_2953839490_989014667 2821702 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2821702.pdb 3 ORCLPDB1 PDB_SNAP 2823303 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2823303.pdb 3 ORCLPDB1 SNAP_2953839490_989015970 2823679 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2823679.pdb [oracle@oracle-18c-vagrant ORCLPDB1]$ ls -lsh total 1.3G 4.0K drwxr-x---. 8 oracle oinstall 4.0K Oct 8 22:39 ORCLCDB 171M -rw-r--r--. 1 oracle oinstall 171M Oct 8 22:18 snap_2953839490_2821702.pdb 171M -rw-r--r--. 1 oracle oinstall 171M Oct 8 22:38 snap_2953839490_2823303.pdb 171M -rw-r--r--. 1 oracle oinstall 171M Oct 8 22:40 snap_2953839490_2823679.pdb 371M -rw-r-----. 1 oracle oinstall 371M Oct 8 22:39 sysaux01.dbf 271M -rw-r-----. 1 oracle oinstall 271M Oct 8 22:39 system01.dbf 56K -rw-r-----. 1 oracle oinstall 63M Oct 1 23:21 temp01.dbf 101M -rw-r-----. 1 oracle oinstall 101M Oct 8 22:39 undotbs01.dbf 5.1M -rw-r-----. 1 oracle oinstall 5.1M Oct 8 22:39 users01.dbf
如果要刪除快照,則有兩種方法,第一種就是使用alter pluggable database刪除,第二種是修改max_pdb_snapshots參數,當max_pdb_snapshots參數設置成0時,將刪除全部快照。
SQL> alter pluggable database drop snapshot SNAP_2953839490_989015970; Pluggable database altered. SQL> SELECT CON_ID, CON_NAME, SNAPSHOT_NAME, SNAPSHOT_SCN AS snap_scn, SNAPSHOT_TIME, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN SNAPSHOT_TIME FULL_SNAPSHOT_PATH ---------- -------------------- ------------------------- ---------- ------------- --------------------------------------------------------------------------- 3 ORCLPDB1 SNAP_2953839490_989014667 2821702 1539008272 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2821702.pdb 3 ORCLPDB1 PDB_SNAP 2823303 1539009503 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2823303.pdb SQL> alter pluggable database set max_pdb_snapshots=0; Pluggable database altered. SQL> SELECT CON_ID, CON_NAME, SNAPSHOT_NAME, SNAPSHOT_SCN AS snap_scn, SNAPSHOT_TIME, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; no rows selected
演示了上述功能之后,還有一個功能,就是我們可以根據快照創建pdb。
SQL> alter pluggable database set max_pdb_snapshots=8; Pluggable database altered SQL> alter pluggable database snapshot pdb_snap; Pluggable database altered. SQL> SELECT CON_ID, CON_NAME, SNAPSHOT_NAME, SNAPSHOT_SCN AS snap_scn, SNAPSHOT_TIME, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN SNAPSHOT_TIME FULL_SNAPSHOT_PATH ---------- -------------------- ------------------------- ---------- ------------- --------------------------------------------------------------------------- 3 ORCLPDB1 PDB_SNAP 2825283 1539010328 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/snap_2953839490_2825283.pdb SQL> ! [oracle@oracle-18c-vagrant ~]$ mkdir -p /opt/oracle/oradata/ORCLCDB/ORCLPDB2 SQL> create pluggable database ORCLPDB2 from ORCLPDB1 using snapshot PDB_SNAP create_file_dest='/opt/oracle/oradata/ORCLCDB/ORCLPDB2'; create pluggable database ORCLPDB2 from ORCLPDB1 using snapshot PDB_SNAP create_file_dest='/opt/oracle/oradata/ORCLCDB/ORCLPDB2' * ERROR at line 1: ORA-65040: operation not allowed from within a pluggable database SQL> alter session set container=CDB$ROOT; Session altered. SQL> create pluggable database ORCLPDB2 from ORCLPDB1 using snapshot PDB_SNAP create_file_dest='/opt/oracle/oradata/ORCLCDB/ORCLPDB2'; Pluggable database created. SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB1 READ WRITE NO 5 ORCLPDB2 MOUNTED SQL> alter pluggable database ORCLPDB2 open; Pluggable database altered.
這樣我們就根據快照創建了一個新的PDB,假設當前PDB出現了數據覆蓋,我們就可以使用這個歷史快照的PDB來恢復數據。
當然還有一個很好用的功能就是我們在創建pdb的過程中把他設置成15分鐘產生一個快照。當然配置這個功能有一個先決條件:CDB必須處于本地undo模式.
SQL> create pluggable database ORCLPDB3 from ORCLPDB1 file_name_convert=('ORCLPDB1','ORCLPDB3') snapshot mode every 5 minutes; Pluggable database created.
可以看到每隔5分鐘自動創建一個快照
[oracle@oracle-18c-vagrant ORCLPDB3]$ ls -lrt snap* -rw-r--r--. 1 oracle oinstall 179134736 Oct 8 23:13 snap_2091710291_2830531.pdb -rw-r--r--. 1 oracle oinstall 179167158 Oct 8 23:18 snap_2091710291_2832545.pdb -rw-r--r--. 1 oracle oinstall 179285979 Oct 8 23:23 snap_2091710291_2833104.pdb -rw-r--r--. 1 oracle oinstall 179284365 Oct 8 23:28 snap_2091710291_2833687.pdb -rw-r--r--. 1 oracle oinstall 179302205 Oct 8 23:33 snap_2091710291_2834965.pdb -rw-r--r--. 1 oracle oinstall 179315484 Oct 8 23:38 snap_2091710291_2836695.pdb -rw-r--r--. 1 oracle oinstall 115724288 Oct 8 23:43 snap_2091710291_2837222.pdb
我們可以做個實驗測試一下。在生成快照之前創建一個表插入點數據,這里上一次快照是23:43分。
SQL> alter session set container=ORCLPDB3; Session altered. SQL> create table a1 as select * from dba_objects; Table created. SQL> select count(1) from a1; COUNT(1) ---------- 72897 [oracle@oracle-18c-vagrant ORCLPDB3]$ ls -lrt snap* -rw-r--r--. 1 oracle oinstall 179134736 Oct 8 23:13 snap_2091710291_2830531.pdb -rw-r--r--. 1 oracle oinstall 179167158 Oct 8 23:18 snap_2091710291_2832545.pdb -rw-r--r--. 1 oracle oinstall 179285979 Oct 8 23:23 snap_2091710291_2833104.pdb -rw-r--r--. 1 oracle oinstall 179284365 Oct 8 23:28 snap_2091710291_2833687.pdb -rw-r--r--. 1 oracle oinstall 179302205 Oct 8 23:33 snap_2091710291_2834965.pdb -rw-r--r--. 1 oracle oinstall 179315484 Oct 8 23:38 snap_2091710291_2836695.pdb -rw-r--r--. 1 oracle oinstall 179353508 Oct 8 23:43 snap_2091710291_2837222.pdb -rw-r--r--. 1 oracle oinstall 5767168 Oct 8 23:48 snap_2091710291_2839217.pdb SQL> SELECT CON_ID, CON_NAME, SNAPSHOT_NAME, SNAPSHOT_SCN AS snap_scn, SNAPSHOT_TIME, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN SNAPSHOT_TIME FULL_SNAPSHOT_PATH ---------- -------------------- ------------------------- ---------- ------------- --------------------------------------------------------------------------- 7 ORCLPDB3 SNAP_2091710291_989017984 2830531 1539011592 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2830531.pdb 7 ORCLPDB3 SNAP_2091710291_989018284 2832545 1539011887 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2832545.pdb 7 ORCLPDB3 SNAP_2091710291_989018584 2833104 1539012188 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2833104.pdb 7 ORCLPDB3 SNAP_2091710291_989018884 2833687 1539012489 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2833687.pdb 7 ORCLPDB3 SNAP_2091710291_989019184 2834965 1539012787 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2834965.pdb 7 ORCLPDB3 SNAP_2091710291_989019484 2836695 1539013087 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2836695.pdb 7 ORCLPDB3 SNAP_2091710291_989019784 2837222 1539013386 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2837222.pdb 7 ORCLPDB3 SNAP_2091710291_989020084 2839217 1539013686 /opt/oracle/oradata/ORCLCDB/ORCLPDB3/snap_2091710291_2839217.pdb
23點48分產生了新的快照,此時我們使用新的快照做一個克隆,登陸到ORCLPDB4數據庫后,我們會發現是有數據的。
SQL> alter session set container=CDB$ROOT; Session altered. SQL> create pluggable database ORCLPDB4 from ORCLPDB3 using snapshot SNAP_2091710291_989020084 create_file_dest='/opt/oracle/oradata/ORCLCDB/ORCLPDB4'; Pluggable database created SQL> alter pluggable database ORCLPDB4 open; Pluggable database altered. SQL> alter session set container=ORCLPDB4; Session altered. SQL> select count(1) from a1; COUNT(1) ---------- 72897
這個功能對于測試人員非常有用,例如移動電信現在有BCV環境,專門用于經分抽數及測試,而這個BCV環境是底層同步的一個克隆。使用18c數據庫,我們就可以直接創建快照,然后使用快照克隆一個新數據庫形成BCV環境給經分抽數及測試使用了。
感謝各位的閱讀!關于“Oracle 18c新特性-PDB快照輪播的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。