本文主要是介绍Oracle Database 18c新特性:PDB Snapshot Carousel,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PDB Snapshot Carousel(快照轮盘)是针对PDB的定期快照,可以将快照恢复为其它的PDB。
只能在Exadata上使用,否则报错:
ORA-12754: Feature PDB SNAPSHOT CAROUSEL is disabled due to missing capability
不过可以有变通方法:
alter system set "_exadata_feature_on"=true scope=spfile;
shutdown immediate
startup
SQL> show parameter exadataNAME TYPE VALUE
------------------------------------ ----------- ------------------------------
_exadata_feature_on boolean TRUE
创建PDB时,即可配置快照轮盘,可以指定不配置,手工创建,周期性创建(分钟或小时)。例如:
CREATE PLUGGABLE DATABASE orclpdb2ADMIN USER pdb_admin IDENTIFIED BY Password1FILE_NAME_CONVERT=('pdbseed','pdb2')SNAPSHOT MODE EVERY 24 HOURS;ALTER PLUGGABLE DATABASE orclpdb2 OPEN;
ALTER PLUGGABLE DATABASE orclpdb2 SAVE STATE;
col pdb_name format a10
SELECT con_id,pdb_name,snapshot_mode,snapshot_interval
FROM cdb_pdbs
ORDER BY 1;CON_ID PDB_NAME SNAPSH SNAPSHOT_INTERVAL
---------- ---------- ------ -----------------2 PDB$SEED MANUAL3 ORCLPDB1 MANUAL4 ORCLPDB2 AUTO 1440
连接到PDB可以修改配置:
SQL> alter session set container=orclpdb2;Session altered.SQL> ALTER PLUGGABLE DATABASE SNAPSHOT MODE EVERY 60 MINUTES;Pluggable database altered.SQL> ALTER PLUGGABLE DATABASE SNAPSHOT MODE MANUAL;Pluggable database altered.SQL> ALTER PLUGGABLE DATABASE SNAPSHOT MODE NONE;Pluggable database altered.
获取最大快照数量的配置,默认为8:
SET LINESIZE 150 TAB OFF
COLUMN property_name FORMAT A20
COLUMN pdb_name FORMAT A10
COLUMN property_value FORMAT A15
COLUMN description FORMAT A50SELECT pr.con_id,p.pdb_name,pr.property_name, pr.property_value,pr.description
FROM cdb_properties prJOIN cdb_pdbs p ON pr.con_id = p.con_id
WHERE pr.property_name = 'MAX_PDB_SNAPSHOTS'
ORDER BY pr.property_name;CON_ID PDB_NAME PROPERTY_NAME PROPERTY_VALUE DESCRIPTION
---------- ---------- -------------------- --------------- --------------------------------------------------3 ORCLPDB1 MAX_PDB_SNAPSHOTS 8 maximum number of snapshots for a given PDB4 ORCLPDB2 MAX_PDB_SNAPSHOTS 8 maximum number of snapshots for a given PDB
修改最大快照数量配置,必须连接到PDB:
ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=0; -- 删除所有快照
ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=8;
手工创建快照:
ALTER PLUGGABLE DATABASE SNAPSHOT; -- 系统生成快照名ALTER PLUGGABLE DATABASE SNAPSHOT my_snapshot; -- 自定义快照名
输出:
SQL> ALTER PLUGGABLE DATABASE SNAPSHOT;
Pluggable database altered.SQL> set timing on
SQL> ALTER PLUGGABLE DATABASE SNAPSHOT my_snapshot;Pluggable database altered.Elapsed: 00:01:34.69
查看快照信息:
SET LINESIZE 150 TAB OFF
COLUMN con_name FORMAT A10
COLUMN snapshot_name FORMAT A30
COLUMN snapshot_scn FORMAT 9999999
COLUMN full_snapshot_path FORMAT A60SELECT con_id,con_name,snapshot_name, snapshot_scn,full_snapshot_path
FROM cdb_pdb_snapshots
ORDER BY con_id, snapshot_scn;CON_ID CON_NAME SNAPSHOT_NAME SNAPSHOT_SCN FULL_SNAPSHOT_PATH
---------- ---------- ------------------------------ ------------ ------------------------------------------------------------4 ORCLPDB2 SNAP_3634619871_1021278962 2439933 /opt/oracle/oradata/ORCLCDB/pdb2/snap_3634619871_2439933.pdb4 ORCLPDB2 MY_SNAPSHOT 2440487 /opt/oracle/oradata/ORCLCDB/pdb2/snap_3634619871_2440487.pdbSQL> host du -csh /opt/oracle/oradata/ORCLCDB/pdb2/*.dbf
331M /opt/oracle/oradata/ORCLCDB/pdb2/sysaux01.dbf
271M /opt/oracle/oradata/ORCLCDB/pdb2/system01.dbf
56K /opt/oracle/oradata/ORCLCDB/pdb2/temp012019-10-08_15-27-52-891-PM.dbf
101M /opt/oracle/oradata/ORCLCDB/pdb2/undotbs01.dbf
701M totalSQL> host ls -l /opt/oracle/oradata/ORCLCDB/pdb2/snap_*
-rw-r--r--. 1 oracle oinstall 108001840 Oct 10 08:37 /opt/oracle/oradata/ORCLCDB/pdb2/snap_3634619871_2439933.pdb
-rw-r--r--. 1 oracle oinstall 108000948 Oct 10 08:39 /opt/oracle/oradata/ORCLCDB/pdb2/snap_3634619871_2440487.pdb
可以看到,由700M压缩到100M。
删除快照,保留一个快照后续恢复使用:
ALTER PLUGGABLE DATABASE DROP SNAPSHOT SNAP_3634619871_1021278962;
-- ALTER PLUGGABLE DATABASE DROP SNAPSHOT my_snapshot;
删除PDB将删除所有相关快照。因此只能将快照恢复为另一PDB。
CREATE PLUGGABLE DATABASE orclpdb2_copy FROM orclpdb2 USING SNAPSHOT my_snapshot FILE_NAME_CONVERT=('pdbseed','orclpdb2_copy');
第一次恢复报错:
*
ERROR at line 1:
ORA-65365: unable to create pluggable database
原因是需要指定CREATE_FILE_DEST:
$ oerr ora 65365
65365, 00000, "unable to create pluggable database"
// *Cause: An attempt was made to create a pluggable database (PDB) using a
// snapshot when Oracle Managed Files (OMF) was not enabled or if the
// CREATE_FILE_DEST clause was not specified.
// *Action: Enable OMF or specify CREATE_FILE_DEST clause and retry creating
// the pluggable database.
//
再次恢复:
SQL> CREATE PLUGGABLE DATABASE orclpdb2_copy FROM orclpdb2 USING SNAPSHOT my_snapshot CREATE_FILE_DEST = '/opt/oracle/oradata/ORCLCDB/pdb2';Pluggable database created.SQL> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORCLPDB1 READ WRITE NO4 ORCLPDB2 READ WRITE NO6 ORCLPDB2_COPY MOUNTED
删除这个恢复的数据库:
SQL> alter pluggable database orclpdb2 close;Pluggable database altered.SQL> DROP PLUGGABLE DATABASE orclpdb2_copy INCLUDING DATAFILES;Pluggable database dropped.
查看快照任务,在CDB$ROOT中:
SET LINESIZE 200COLUMN owner FORMAT A10
COLUMN job_name FORMAT A30
COLUMN repeat_interval FORMAT A50SELECT owner,job_name,repeat_interval
FROM dba_scheduler_jobs
WHERE job_name LIKE '%SNAPSHOT'
ORDER BY owner, job_name;OWNER JOB_NAME REPEAT_INTERVAL
---------- ------------------------------ --------------------------------------------------
SYS ORCLPDB2_3634619871_SNAPSHOT FREQ = MINUTELY; INTERVAL = 60
修改任务配置,指定每小时的15分钟执行:
BEGINDBMS_SCHEDULER.set_attribute (name => 'ORCLPDB2_3634619871_SNAPSHOT',attribute => 'REPEAT_INTERVAL',value => 'FREQ=HOURLY; INTERVAL=60; BYMINUTE=15;');
END;
/
PL/SQL procedure successfully completed.
查看任务的具体操作:
COLUMN job_action FORMAT A75SELECT job_action
FROM dba_scheduler_jobs
WHERE job_name = 'ORCLPDB2_3634619871_SNAPSHOT';
参考
- https://oracle-base.com/articles/18c/multitenant-pdb-snapshot-carousel-18c
- https://docs.oracle.com/en/database/oracle/oracle-database/18/dblic/Licensing-Information.html#GUID-0F9EB85D-4610-4EDF-89C2-4916A0E7AC87
这篇关于Oracle Database 18c新特性:PDB Snapshot Carousel的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!