Oracle 18c推出的一個(gè)新功能就是PDB快照輪播,最多可以創(chuàng)建8個(gè)pdb的快照,而這8個(gè)構(gòu)成的一組快照就被稱(chēng)作快照輪播。當(dāng)達(dá)到第8個(gè)快照限制時(shí),新的快照就會(huì)覆蓋最舊的快照,就像redo log一樣。PDB的快照主要作用是當(dāng)出現(xiàn)了問(wèn)題可以閃回到快照的時(shí)間點(diǎn),另一個(gè)功能是基于快照來(lái)查詢(xún)歷史數(shù)據(jù)。
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
默認(rèn)情況下是手動(dòng)創(chuàng)建快照,我們可以把它改成自動(dòng)創(chuàng)建。
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
要返回手動(dòng)模式,輸入mode manual即可。
SQL> alter pluggable database snapshot mode manual;
Pluggable database altered.
SQL> alter pluggable database snapshot;
Pluggable database altered.
手動(dòng)創(chuàng)建快照,可以自己指定名字,也可以使用系統(tǒng)自動(dòng)生成的名字。通過(guò)查看DBA_PDB_SNAPSHOTS視圖,可以找到快照存放的路徑及創(chuàng)建快照的SCN號(hào)。
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
如果要?jiǎng)h除快照,則有兩種方法,第一種就是使用alter pluggable database刪除,第二種是修改max_pdb_snapshots參數(shù),當(dāng)max_pdb_snapshots參數(shù)設(shè)置成0時(shí),將刪除全部快照。
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
演示了上述功能之后,還有一個(gè)功能,就是我們可以根據(jù)快照創(chuàng)建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.
這樣我們就根據(jù)快照創(chuàng)建了一個(gè)新的PDB,假設(shè)當(dāng)前PDB出現(xiàn)了數(shù)據(jù)覆蓋,我們就可以使用這個(gè)歷史快照的PDB來(lái)恢復(fù)數(shù)據(jù)。
當(dāng)然還有一個(gè)很好用的功能就是我們?cè)趧?chuàng)建pdb的過(guò)程中把他設(shè)置成15分鐘產(chǎn)生一個(gè)快照。當(dāng)然配置這個(gè)功能有一個(gè)先決條件:CDB必須處于本地undo模式.
SQL> create pluggable database ORCLPDB3 from ORCLPDB1 file_name_convert=('ORCLPDB1','ORCLPDB3') snapshot mode every 5 minutes;
Pluggable database created.
可以看到每隔5分鐘自動(dòng)創(chuàng)建一個(gè)快照
[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
我們可以做個(gè)實(shí)驗(yàn)測(cè)試一下。在生成快照之前創(chuàng)建一個(gè)表插入點(diǎn)數(shù)據(jù),這里上一次快照是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點(diǎn)48分產(chǎn)生了新的快照,此時(shí)我們使用新的快照做一個(gè)克隆,登陸到ORCLPDB4數(shù)據(jù)庫(kù)后,我們會(huì)發(fā)現(xiàn)是有數(shù)據(jù)的。
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
這個(gè)功能對(duì)于測(cè)試人員非常有用,例如移動(dòng)電信現(xiàn)在有BCV環(huán)境,專(zhuān)門(mén)用于經(jīng)分抽數(shù)及測(cè)試,而這個(gè)BCV環(huán)境是底層同步的一個(gè)克隆。使用18c數(shù)據(jù)庫(kù),我們就可以直接創(chuàng)建快照,然后使用快照克隆一個(gè)新數(shù)據(jù)庫(kù)形成BCV環(huán)境給經(jīng)分抽數(shù)及測(cè)試使用了。
總結(jié)
以上所述是小編給大家介紹的Oracle 18c新特性-PDB快照輪播(Snapshot Carousel),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!