Oracle 18C新特性之PDB snapshot Carousel--PDB快照轮播
作者:互联网
Oracle 18C新特性之PDB snapshot Carousel(快照轮播)
| 关于PDB快照 Carousel
Oracle18c新特新 pdb snapshot Carousel( PDB快照轮播(Snapshot Carousel) )提供了在pdb级别下手工或者自动生成快照的功能,为开发测试用例提供了便捷。CDB为local undo和归档模式下,指定MAX_PDB_SNAPSHOTS控制pdb最多生成快照的数量,当快照超过最大数量时,会覆盖最旧的快照。
在Oracle 18c数据库中,创建PDB时可以同时为PDB创建快照,完整的保存快照创建时间点的PDB数据。PDB快照主要有两个作用:
通过闪回恢复数据到快照时间点
使用快照PDB查询历史数据
每个PDB快照都会关联一个快照名称,可以在创建时定义也可以由系统自动生成。同时,每个快照也会关联创建时的时间戳和SCN。每个PDB允许保存的最大PDB快照数量由MAX_PDB_SNAPSHOTS属性控制,最大和默认值均为8。当创建的PDB快照数量超过定义时,最先创建的PDB快照将会被删除。使用alter database命令可以修改最大允许的PDB快照数量,如果将限制设为0,则会删除所有的PDB快照。
如下图:pdb1_prod为生产PDB,然后创建refresh PDB pdb1_test_master,让refreshPDB pdb1_test_master每天生成快照。当你需要测试用例时,那么你可以指定snapshot创建PDB。
一个通用的策略是每天在同一时间生成PDB快照。另一种策略是在数据加载之前手动抓取快照。在这两种情况下,都可以从snapshot Carousel中使用任何可用的快照恢复PDB。
1. PDB快照Carousel是如何工作的
数据库按需或自动创建carousel中的连续副本。当达到快照限制时,数据库将覆盖旧的快照。PDB快照的文件存放在文件系统上的物理文件。其不包含数据库归档文件archive log。默认存放在PDB的数据文件相同的目录中。系统自动生成的snapshot以snap_开始,唯一标示结尾的命名规则,包含了快照当前的SCN,并且扩展名为.PDB。
相关视图:MAX_PDB_SNAPSHOTS、DBA_PDB_SNAPSHOTS、DBA_PDBS
PDB创建时默认开始快照功能,可以通过两种方式对PDB快照进行定义:
1. 手工方式
创建或修改PDB是指定snapshot mode manual字句,这是PDB创建时的默认行为
create pluggable database pdb1 snapshot mode manual;
2. 定义一个自动创建的时间周期
alter pluggable database pdb1 snapshot mode every 24 hours;
当时间量以分钟表示时,指定值必须小于3000;当时间量以小时表示时,指定值不能超过2000。
PDB快照创建完成后,可以利用其创建新的PDB。使用的PDB快照可通过快照名称、快照SCN或者快照时间戳来指定。
create pluggable database pdb1_day_1 from pdb1 using snapshot <snapshot_name>;
create pluggable database pdb1_day_2 from pdb1 using snapshot at scn <snapshot_SCN>;
在出现用户错误或其他极端情况时,PDB快照还可用于对PDB的闪回。实施步骤如下:
关闭PDB1
从指定PDB快照创建新的PDB
删除PDB1
重命名新的PDB为PDB1
打开PDB1
| 设置PDB快照的最大数量
使用MAX_PDB_SNAPSHOTS参数设置PDB快照最大快照数,首先登录到需要设置的PDB中,通过视图CDB_PROPERTIES查询当前MAX_PDB_SNAPSHOT值,可以使用alter pluggabledatabase/alter database更改MAX_PDB_SNAPSHOTS值。
如下为设置PDB snapshot的例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | SET LINESIZE 1500 COL CON_ID FORMAT 99999 COL PROPERTY_NAME FORMAT a17 COL PDB_NAME FORMAT a9 COL VALUE FORMAT a12 COL DESCRIPTION FORMAT a90 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%' ORDER BY PROPERTY_NAME; CON_ID PDB_NAME PROPERTY_NAME VALUE DESCRIPTION ----- --------- ----------------- --------- --------------------------------------------------------------- 3 ORCLPDB MAX_PDB_SNAPSHOTS 7 maximum number of snapshots for a given PDB 3 ORCLPDB MAX_PDB_STORAGE UNLIMITED Maximum Space Usage of Datafiles and Local Tempfiles in Container |
下面语句将当前pdb的快照数设置为7
1 2 3 4 5 6 | 进入PDB YAO.CHONG> alter session set container = ORCLPDB; Session altered. Elapsed: 00:00:00.01 YAO.CHONG> ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=7; Pluggable database altered. |
想要删除所有的快照,我们只需要执行下面一条命令即可。
1 2 3 4 5 6 7 8 9 10 | ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=0; SET LINESIZE 150 COL CON_NAME FORMAT a10 COL SNAPSHOT_NAME FORMAT a25 COL SNAP_SCN FORMAT 9999999 COL FULL_SNAPSHOT_PATH FORMAT a45 SELECT CON_ID,CON_NAME,SNAPSHOT_NAME,SNAPSHOT_SCN AS snap_scn, FULL_SNAPSHOT_PATH FROM DBA_PDB_SNAPSHOTS ORDER BY SNAP_SCN; ##都没了 |
| 配置自动生成PDB快照
默认情况下都是手动生成快照,使用SNAPSHOT MODE EVERY子句自动产生PDB快照。
1 2 3 4 | SELECT SNAPSHOT_MODE "S_MODE" , SNAPSHOT_INTERVAL/60 "SNAP_INT_HRS" FROM DBA_PDBS; S_MODE SNAP_INT_HRS ------ ------------ MANUAL |
更改自动创建模式为每24小时自动生成PDB快照
1 2 3 4 5 6 7 8 9 10 11 12 | 进入PDB里面去执行 YAO.CHONG > alter session set container = ORCLPDB; Session altered. Elapsed: 00:00:00.01 YAO.CHONG> ALTER PLUGGABLE DATABASE SNAPSHOT MODE EVERY 24 HOURS; Pluggable database altered. Elapsed: 00:00:00.17 #确认自动生成快照的时间间隔 SELECT SNAPSHOT_MODE "S_MODE" , SNAPSHOT_INTERVAL/60 "SNAP_INT_HRS" FROM DBA_PDBS; S_MODE SNAP_INT_HRS ------ ------------ AUTO 24 |
下面是每2小时生成快照的例子
首先登录到CDB根目录。以下语句从名为cdb1_pdb1的现有PDB创建cdb1_pdb3,并将其配置为每2小时自动获取快照:
1 2 3 | CREATE PLUGGABLE DATABASE cdb1_pdb3 FROM cdb1_pdb1 FILE_NAME_CONVERT=( 'cdb1_pdb1' , 'cdb1_pdb3' ) SNAPSHOT MODE EVERY 120 MINUTES; |
| 手工创建PDB快照
使用ALTER PLUGGABLE DATABASE/CREATE PLUGGABLE DATABASE手动生成快照。使用ALTER PLUGGABLE DATABASE SNAPSHOT语句需要满足的要求。
CDB必须是LOCAL UNDO模式
用户必须有权限创建和删除PDB
1 2 3 | YAO.CHONG> ALTER PLUGGABLE DATABASE SNAPSHOT test_snapshot; Pluggable database altered. Elapsed: 00:03:15.66/快照大小481M,3分钟, |
下面查询出当前PDB的快照
1 2 3 4 5 6 7 8 9 10 11 12 | SET LINESIZE 150 COL CON_NAME FORMAT a10 COL SNAPSHOT_NAME FORMAT a30 COL SNAP_SCN FORMAT 9999999 COL FULL_SNAPSHOT_PATH FORMAT a70 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 CDB1_PDB1 CDB1_PDB1_B4WEDLOAD 2962078 /disk1/oracle/dbs/snap_3489077498_2962078.pdb 3 CDB1_PDB1 CDB1_PDB1_AFWEDLOAD 2962938 /disk1/oracle/dbs/snap_3489077498_2962938.pdb |
如果你不指定快照名,系统自动生成唯一名称的快照,下面即为不指定名字创建快照
1 2 3 4 5 6 7 8 9 10 11 12 | ALTER PLUGGABLE DATABASE SNAPSHOT; SET LINESIZE 150 COL CON_NAME FORMAT a10 COL SNAPSHOT_NAME FORMAT a25 COL SNAP_SCN FORMAT 9999999 COL FULL_SNAPSHOT_PATH FORMAT a45 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 ORCLPDB SNAP_3034367141_987737800 2995234 /home/oradata/ORCL/orclpdb/snap_3034367141_2995234.pdb |
| 删除PDB快照
将MAX_PDB_SNAPSHOTS设置为0,即删除所有PDB快照,同时也关闭此功能。同样也可以使用ALTER PLUGGABLE DATABASE删除当前的快照。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | SET LINESIZE 150 COL CON_NAME FORMAT a10 COL SNAPSHOT_NAME FORMAT a25 COL SNAP_SCN FORMAT 9999999 COL FULL_SNAPSHOT_PATH FORMAT a45 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 ORCLPDB CDB_CNDBA_20180813151200 2970060 /home/oradata/ORCL/orclpdb/snap_3034367141_2970060.pdb 3 ORCLPDB SNAP_3034367141_987737800 2995234 /home/oradata/ORCL/orclpdb/snap_3034367141_2995234.pdb ALTER PLUGGABLE DATABASE DROP SNAPSHOT CDB_CNDBA_20180813151200; 再次查询PDB快照已经被删除 CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN FULL_SNAPSHOT_PATH ---------- ---------- ------------------------- -------- --------------------------------------------------- 3 ORCLPDB SNAP_3034367141_987737800 2995234 /home/oradata/ORCL/orclpdb/snap_3034367141_2995234.pdb |
| 从snapshot创建PDB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | alter system set db_create_file_dest = '/home/oradata/ORCL/orclpdb' ; conn / as sysdba YAO.CHONG> create pluggable database pdb_snap_test from orclpdb using snapshot test_snapshot; Pluggable database created. Elapsed: 00:00:39.13 YAO.CHONG> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB READ WRITE NO 4 PDB_SNAP_TEST MOUNTED YAO.CHONG> alter pluggable database PDB_SNAP_TEST open ; Pluggable database altered. Elapsed: 00:00:09.28 YAO.CHONG> alter pluggable database PDB_SNAP_TEST close ; Pluggable database altered. Elapsed: 00:00:01.11 YAO.CHONG> drop pluggable database PDB_SNAP_TEST including datafiles; Pluggable database dropped. Elapsed: 00:00:00.67 |
| 基于SCN或时间点生产快照库
在阅读官方文档时,看到生成PDB可以基于SCN,我心中不禁暗喜,当再仔细查阅一番则不然,简直万念俱寂、黯然销魂。提供的基于SCN生成的快照库只能是基于当前生成快照时间点的SCN,似乎有些鸡肋。
1 | create pluggable database pdb_snap_test from orclpdb using snapshot at SCN 3620951; |
与recover database until scn指定scn方式打开数据库不同,pdb snapshot Carousel指定scn生成的PDB只能是创建snapshot时的固定scn,并且生成快照与snapshot生成pdb的过程中占据了大量的物理空间与IO资源。
那么问题来了,说了这么多关于PDB snapshot Carousel的优势与好处,是否就说明已经找到了最佳的解决方案呢?
Hold on.
凡事有利也有弊,同样PDB snapshot Carousel也不能幸免。
快照数量受限
虽然能够做到Carousel轮转,但毕竟数量有限,较为死板。在用户的实际测试环境中条件复杂多变,会限制测试环境的搭建.
占据大量物理空间与IO资源
对于当前用户动辄几十T的数据量,在生成snapshot与snapshot创建pdb的过程中,消耗的时间和占据的物理资源是巨大的。
拘泥固定时间点
对于PDBsnapshot Carouse而言,只能基于固定时间,即快照点创建,无法根据测试需要灵活指定时间点。面对不断变化的测试需求,如此死板的模式明显是不可能满足要求的。
版本受限
最后是客观条件的限制,利用新特性需要满足是在18C的环境下且启用了PDB功能,但目前很多用户依然是10G\11G\12C的环境,因此也仅仅只能远观而无法上手,对于实际工作很难产生推动作用。
说到这,是否还有更好的解决办法呢?
答案是必须有!
16 Administering a PDB Snapshot Carousel
您可以为指定的PDB配置一个PDB快照库,手动或自动创建快照,并设置快照的最大数量。
This section contains the following topics:
- About PDB Snapshot Carousel
A PDB snapshot is a point-in-time copy of a PDB. You can create snapshots manually using the SNAPSHOT clause of CREATE PLUGGABLE DATABASE (or ALTER PLUGGABLE DATABASE ), or automatically using the EVERY interval clause. A PDB snapshot carousel is a library of snapshots. - Setting the Maximum Number of Snapshots in a PDB Snapshot Carousel
You can set the maximum number of PDB snapshots for a PDB. - Configuring Automatic PDB Snapshots
Configure a PDB for automatic snapshots by using the SNAPSHOT MODE EVERY clause when creating or altering a PDB. - Creating PDB Snapshots Manually
To create a PDB snapshot manually, specify the SNAPSHOT snapshot_name clause in ALTER PLUGGABLE DATABASE or CREATE PLUGGABLE DATABASE . - Dropping a PDB Snapshot
You can drop a PDB snapshot by running an ALTER PLUGGABLE DATABASE statement with the DROP SNAPSHOT clause.
Parent topic: Administering a Multitenant Environment
16.1 About PDB Snapshot Carousel
PDB快照是PDB的时间点副本。您可以使用create PLUGGABLE DATABASE(或ALTER PLUGGABLE DATABASE)的SNAPSHOT子句手动创建快照,也可以使用each interval子句自动创建快照
. A PDB snapshot carousel 快照库.
This section contains the following topics:
- Purpose of PDB Snapshot Carousel
A PDB snapshot carousel is a useful way of maintaining a library of recent PDB copies for point-in-time recovery and cloning. - How PDB Snapshot Carousel Works
The carousel for a specific PDB is a circular library of copies for this PDB. - User Interface for PDB Snapshot Carousel
The SNAPSHOT MODE clause controls creation of snapshots, and determines whether creation is manual, automatic, or disabled.
Parent topic: Administering a PDB Snapshot Carousel
16.1.1 Purpose of PDB Snapshot Carousel
PDB快照库是维护最近的PDB副本库以便进行时间点恢复和克隆的一种有用方法。
克隆用于开发和测试的PDBs
在一个典型的开发用例中,您克隆一个产品PDB来进行测试。当CDB处于ARCHIVELOG模式和本地撤销模式时,源生产PDB可以以读/写模式打开,并在操作过程中充分发挥功能。这种技术被称为热克隆。当SCN完成时,热克隆在事务上与源PDB一致of the ALTER PLUGGABLE DATABASE ... OPEN statement.
例如,当名为pdb1_prod的生产PDB处于打开状态并正在使用时,您将创建一个名为pdb1_test_master的可刷新克隆。然后配置pdb1_test_master来每天创建自动快照。当您需要新的PDBs进行测试时,请创建任何快照的完整克隆,然后使用 CREATE PLUGGABLE DATABASE ... SNAPSHOT COPY .
下图显示了从4月5日拍摄的PDB快照创建的克隆pdb1_test_full1。图中显示了从pdb1_test_full1创建的三个PDBs快照副本。
Figure 16-1 Automatic Snapshots of a Refreshable Clone PDB
Description of "Figure 16-1 Automatic Snapshots of a Refreshable Clone PDB"
使用PDB快照库进行时间点恢复
典型的策略是每天在同一时间对PDB进行快照。另一种策略是在数据加载之前手动进行快照。在这两种情况下,PDB快照库都允许您使用任何可用快照恢复PDB。
例如,名为pdb1_prod的销售历史记录PDB每天在12:01生成一个自动快照。在4/9周一下午的daily data load中,您意外加载了错误的数据,损坏了PDB。您可以基于Monday 4/9快照创建一个新的生产PDB,删除损坏的PDB,然后重试数据加载。
Figure 16-2 Restore a Production PDB Using a Snapshot
Description of "Figure 16-2 Restore a Production PDB Using a Snapshot"
See Also:
" About Cloning a PDB "
Oracle Database SQL Language Reference for CREATE PLUGGABLE DATABASE syntax and semantics
Parent topic: About PDB Snapshot Carousel
16.1.2 How PDB Snapshot Carousel Works
The carousel 对于特定的PDB,是该PDB的一个循环复制库。
数据库根据需要或自动地在库中创建连续的副本。当达到快照限制时,数据库将重写最旧的快照。
This section includes the following topics:
- Contents of a PDB Snapshot
The data files of the PDB snapshot reside in an archive file on the file system. - Contents of a PDB Snapshot Carousel
The PDB snapshot carousel is the set of all existing snapshots for a PDB.
Parent topic: About PDB Snapshot Carousel
16.1.2.1 Contents of a PDB Snapshot
PDB快照的数据文件驻留在文件系统上的归档文件中。
不包括存档的重做日志文件。通常,归档文件存储在与PDB的数据文件相同的目录中。对于系统生成的快照名称,snap_以惟一标识符为前缀,该标识符包含快照SCN。该归档文件的扩展名是.pdb。
数据库使用隐式的using snapshot子句获取快照。在使用创建可插入数据库快照获取快照时,不能指定快照复制子句。
Note:
使用USING snapshot子句创建的PDB快照和使用snapshot copy子句创建的快照复制PDB是两种不同类型的快照,它们不应该混淆。USING SNAPSHOT子句创建一个不需要物化的完整PDB。快照复制子句创建了一个稀疏的PDB,如果您想删除它所基于的PDB快照,就必须将其物化。
虽然PDB快照carousel中的快照始终是完整的PDB,但是您可以在carousel中获取快照的快照副本。在这种情况下,快照副本是一个稀疏克隆。
See Also:
" How a Snapshot Copy PDB Differs from a Standard Clone "
Parent topic: How PDB Snapshot Carousel Works
16.1.2.2 Contents of a PDB Snapshot Carousel
PDB快照库是一个PDB的所有现有快照的集合。
max_pdb_snapshot属性指定库中允许的最大快照数量。当前设置在CDB_PROPERTIES视图中是可见的。
下图显示了cdb1_pdb1的库。在本例中,数据库每24小时自动获取一个快照,维护一组8个快照。创建了前8个快照之后,每个新快照都会替换旧快照。例如,星期二4/10快照替换星期一4/2快照;星期三4/11快照取代星期二4/3快照;等等。
Figure 16-3 PDB Snapshot Carousel
Description of "Figure 16-3 PDB Snapshot Carousel"
Parent topic: How PDB Snapshot Carousel Works
16.1.3 User Interface for PDB Snapshot Carousel
The SNAPSHOT MODE clause controls creation of snapshots, and determines whether creation is manual, automatic, or disabled.
CREATE PLUGGABLE DATABASE Statement
要为PDB设置快照模式,请在快照模式中使用以下值之一 clause of ALTER PLUGGABLE DATABASE or CREATE PLUGGABLE DATABASE :
MANUAL
This clause, which is the default, enables the creation of manual snapshots of the PDB. To create a snapshot on demand, specify the SNAPSHOT snapshot_name clause in an ALTER PLUGGABLE DATABASE or CREATE PLUGGABLE DATABASE statement.
EVERY snapshot_interval [MINUTES|HOURS]
This clause enables the automatic creation of snapshots after an interval of time. The following restrictions apply to the interval specified:
The database assigns each automatic snapshot a system-generated name. Note that manual snapshots are also supported for the PDB when EVERY is specified.
The minutes value must be less than 3000 .
The hours value must be less than 2000 .
NONE
This clause disables snapshot creation for the PDB.
See Also:
" About Point-in-Time Cloning of PDB Snapshots "
Oracle Database SQL Language Reference for the syntax and semantics of the SNAPSHOT clause
MAX_PDB_SNAPSHOTS Database Property
要设置PDB的最大快照数量,请在ALTER PLUGGABLE DATABASE或CREATE PLUGGABLE DATABASE中指定max_pdb_snapshot属性。属性的默认值是8,这也是最大值。当创建了允许的最大快照数量时,数据库将清除最旧的快照。CDB_PROPERTIES视图显示了max_pdb_snapshot的设置。
See Also:
Oracle Database SQL Language Reference for the syntax of the ALTER PLUGGABLE DATABASE statement
DBA_PDB_SNAPSHOTS and DBA_PDBS
The following data dictionary views provide snapshot information:
The DBA_PDB_SNAPSHOTS view metadata about the snapshots, including name, creation SCN, creation time, and file name.
The DBA_PDBS view has a SNAPSHOT_MODE and SNAPSHOT_INTERVAL column.
See Also:
Oracle Database Reference to learn about DBA_PDB_SNAPSHOTS and DBA_PDBS
Parent topic: About PDB Snapshot Carousel
16.2 Setting the Maximum Number of Snapshots in a PDB Snapshot Carousel
You can set the maximum number of PDB snapshots for a PDB.
max_pdb_snapshot数据库属性设置PDB快照旋转***中每个PDB的最大快照数量。默认最大值是8。不能将属性设置为大于8的数字。
Prerequisites
The PDB must be open in read/write mode.
To set the maximum number of PDB snapshots for a PDB:
In SQL*Plus, ensure that the current container is the PDB for which you want to set the limit.
Optionally, query CDB_PROPERTIES for the current setting of the SET MAX_PDB_SNAPSHOTS property.
Run an ALTER PLUGGABLE DATABASE or ALTER DATABASE statement with the SET MAX_PDB_SNAPSHOTS clause.
Example 16-1 Setting the Maximum Number of PDB Snapshots for a PDB
The following query shows the maximum in the carousel for cdb1_pdb1 (sample output included):
SET LINESIZE 150COL CON_ID FORMAT 99999COL PROPERTY_NAME FORMAT a17COL PDB_NAME FORMAT a9COL VALUE FORMAT a3COL DESCRIPTION FORMAT a43SELECT r.CON_ID, p.PDB_NAME, PROPERTY_NAME,PROPERTY_VALUE AS value, DESCRIPTIONFROM CDB_PROPERTIES r, CDB_PDBS pWHERE r.CON_ID = p.CON_IDAND PROPERTY_NAME LIKE 'MAX_PDB%' ORDER BY PROPERTY_NAME;CON_ID PDB_NAME PROPERTY_NAME VAL DESCRIPTION------ --------- ----------------- --- -------------------------------------------3 CDB1_PDB1 MAX_PDB_SNAPSHOTS 8 maximum number of snapshots for a given PDB
The following SQL statement sets the maximum number of PDB snapshots for the current PDB to 7:
ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=7;
Example 16-2 Dropping All Snapshots in a PDB Snapshot Carousel
To drop all snapshots in a PDB snapshot carousel, set the MAX_PDB_SNAPSHOTS database property to (zero), as shown in the following statement:
ALTER PLUGGABLE DATABASE SET MAX_PDB_SNAPSHOTS=0;
This technique is faster than executing ALTER PLUGGABLE DATABASE ... DROP SNAPSHOTsnapshot_name for every snapshot.
See Also:
" About Container Access in a CDB "
Parent topic: Administering a PDB Snapshot Carousel
16.3 Configuring Automatic PDB Snapshots
在创建或更改PDB时,通过使用快照模式EVERY子句为自动快照配置PDB。
默认情况下,PDB是为手动快照配置的。
Prerequisites
Note the following prerequisites for the ALTER PLUGGABLE DATABASE SNAPSHOT statement:
The CDB must be in local undo mode.
The administrator must have the privileges to create a PDB and drop a PDB.
To configure automatic snapshots when altering a PDB:
In SQL*Plus, log in as an administrator to the PDB whose snapshot mode you intend to configure.
Optionally, query DBA_PDBS to determine the current snapshot mode.
Run ALTER PLUGGABLE DATABASE with the SNAPSHOT MODE EVERY interval clause, specifying either MINUTES or HOURS .
To configure automatic snapshots when creating a PDB:
In SQL*Plus, log in as an administrator to the CDB root or application root.
Optionally, query DBA_PDBS to determine the current snapshot mode.
Run CREATE PLUGGABLE DATABASE with the SNAPSHOT MODE EVERY interval clause, specifying either MINUTES or HOURS .
Example 16-3 为现有PDB每天配置一个自动快照
本例假设您已登录到要更改其快照模式的PDB。查询数据字典,确认PDB目前处于手动模式(包括示例输出):
SELECT SNAPSHOT_MODE "S_MODE", SNAPSHOT_INTERVAL/60 "SNAP_INT_HRS" FROM DBA_PDBS;S_MODE SNAP_INT_HRS------ ------------MANUAL
Change the snapshot mode to every 24 hours:
ALTER PLUGGABLE DATABASE SNAPSHOT MODE EVERY 24 HOURS;
Confirm the change to automatic mode:
SELECT SNAPSHOT_MODE "S_MODE", SNAPSHOT_INTERVAL/60 "SNAP_INT_HRS" FROM DBA_PDBS;S_MODE SNAP_INT_HRS------ ------------AUTO 24
Example 16-4 Creating a PDB That Takes Snapshots Every Two Hours
This example assumes that you are logged in to the CDB root. The following statement creates cdb1_pdb3 from an existing PDB named cdb1_pdb1 , and configures it to take snapshots automatically every 2 hours:
CREATE PLUGGABLE DATABASE cdb1_pdb3 FROM cdb1_pdb1FILE_NAME_CONVERT=('cdb1_pdb1','cdb1_pdb3')SNAPSHOT MODE EVERY 120 MINUTES;
See Also:
" Creating a Point-in-Time Clone of a PDB Snapshot: Example "
" Configuring a CDB to Use Local Undo Mode "
Parent topic: Administering a PDB Snapshot Carousel
16.4 Creating PDB Snapshots Manually
To create a PDB snapshot manually, specify the SNAPSHOT snapshot_name clause in ALTER PLUGGABLE DATABASE or CREATE PLUGGABLE DATABASE .
Prerequisites
Note the following prerequisites for the ALTER PLUGGABLE DATABASE SNAPSHOT statement:
The CDB must be in local undo mode.
The administrator must have the privileges to create a PDB and drop a PDB.
To create a PDB snapshot:
In SQL*Plus, log in as an administrator to the PDB whose snapshot you intend to create.
Optionally, query DBA_PDBS to confirm that the snapshot mode is not set to NONE .
Run an ALTER PLUGGABLE DATABASE statement with the SNAPSHOT clause.
Example 16-5 Creating a Snapshot with a User-Specified Name
以下SQL语句创建两个cdb1_pdb1的PDB快照,一个在周三数据加载之前,一个在周三数据加载之后:
ALTER PLUGGABLE DATABASE SNAPSHOT cdb1_pdb1_b4wedload;-- data loadALTER PLUGGABLE DATABASE SNAPSHOT cdb1_pdb1_afwedload;
The following query of DBA_PDB_SNAPSHOTS shows the locations of two snapshots of the PDB named cdb1_pdb1 (sample output included):
SET LINESIZE 150COL CON_NAME FORMAT a10COL SNAPSHOT_NAME FORMAT a20COL SNAP_SCN FORMAT 9999999COL FULL_SNAPSHOT_PATH FORMAT a45SELECT CON_ID, CON_NAME, SNAPSHOT_NAME,SNAPSHOT_SCN AS snap_scn, FULL_SNAPSHOT_PATHFROM DBA_PDB_SNAPSHOTSORDER BY SNAP_SCN;CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN FULL_SNAPSHOT_PATH------- ---------- -------------------- -------- ---------------------------------------------3 CDB1_PDB1 CDB1_PDB1_B4WEDLOAD 2962078 /disk1/oracle/dbs/snap_3489077498_2962078.pdb3 CDB1_PDB1 CDB1_PDB1_AFWEDLOAD 2962938 /disk1/oracle/dbs/snap_3489077498_2962938.pdb
If you do not specify a PDB snapshot name, then the database generates a unique name.
Example 16-6 创建具有系统指定名称的快照
下面的SQL语句创建一个快照,但没有指定名称:
ALTER PLUGGABLE DATABASE SNAPSHOT;
The following sample query shows that the database assigned the snapshot a name prefixed with SNAP_ :
SET LINESIZE 150COL CON_NAME FORMAT a10COL SNAPSHOT_NAME FORMAT a25COL SNAP_SCN FORMAT 9999999COL FULL_SNAPSHOT_PATH FORMAT a45SELECT CON_ID, CON_NAME, SNAPSHOT_NAME,SNAPSHOT_SCN AS snap_scn, FULL_SNAPSHOT_PATHFROM DBA_PDB_SNAPSHOTSORDER BY SNAP_SCN;CON_ID CON_NAME SNAPSHOT_NAME SNAP_SCN FULL_SNAPSHOT_PATH------- ---------- ------------------------- -------- ---------------------------------------------3 CDB1_PDB1 CDB1_PDB1_B4WEDLOAD 2962078 /disk1/oracle/dbs/snap_3489077498_2962078.pdb3 CDB1_PDB1 CDB1_PDB1_AFWEDLOAD 2962938 /disk1/oracle/dbs/snap_3489077498_2962938.pdb3 CDB1_PDB1 SNAP_3489077498_960130367 2993525 /disk1/oracle/dbs/snap_3489077498_2993525.pdb
See Also:
" About Container Access in a CDB "
" Configuring a CDB to Use Local Undo Mode "
Parent topic: Administering a PDB Snapshot Carousel
16.5 Dropping a PDB Snapshot
You can drop a PDB snapshot by running an ALTER PLUGGABLE DATABASE statement with the DROP SNAPSHOT clause.
To drop all PDB snapshots based on a PDB, set the MAX_PDB_SNAPSHOTS property in the PDB to (zero).
To drop a PDB snapshot:
In SQL*Plus, ensure that the current container is the PDB from which you created the PDB snapshot.
Run an ALTER PLUGGABLE DATABASE statement with the DROP SNAPSHOT clause.
Example 16-7 Dropping a PDB Snapshot
The following SQL statement drops a PDB snapshot named sales_snap :
ALTER PLUGGABLE DATABASE DROP SNAPSHOT sales_snap;
See Also:
" About Container Access in a CDB "
Parent topic: Administering a PDB Snapshot Carousel
ORACLE 18C新特性-PDB快照轮播(SNAPSHOT CAROUSEL)
版权声明:本文为Buddy Yuan原创文章,未经允许不得转载。原文地址: Oracle 18c新特性-PDB快照轮播(Snapshot Carousel)
Oracle 18c推出的一个新功能就是PDB快照轮播,最多可以创建8个pdb的快照,而这8个构成的一组快照就被称作快照轮播。当达到第8个快照限制时,新的快照就会覆盖最旧的快照,就像redo log一样。PDB的快照主要作用是当出现了问题可以闪回到快照的时间点,另一个功能是基于快照来查询历史数据。
<span style="color:#444444"><span style="color:#222222">SQL> SELECT r.CON_ID, p.PDB_NAME, PROPERTY_NAME, 2 PROPERTY_VALUE AS value, DESCRIPTION 3 FROM CDB_PROPERTIES r, CDB_PDBS p 4 WHERE r.CON_ID = p.CON_ID 5 AND PROPERTY_NAME LIKE 'MAX_PDB%' 6 AND description like 'maximum%' 7 ORDER BY PROPERTY_NAME; CON_ID PDB_NAME PROPERTY_NAME VALUE DESCRIPTION ---------- -------------------- -------------------- -------------------- ---------------------------------------------------------------------- 3 ORCLPDB1 MAX_PDB_SNAPSHOTS 8 maximum number of snapshots for a given PDB </span></span>
默认情况下是手动创建快照,我们可以把它改成自动创建。
<span style="color:#444444"><span style="color:#222222">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 </span></span>
要返回手动模式,输入mode manual即可。
<span style="color:#444444"><span style="color:#222222">SQL> alter pluggable database snapshot mode manual; Pluggable database altered. SQL> alter pluggable database snapshot; Pluggable database altered. </span></span>
手动创建快照,可以自己指定名字,也可以使用系统自动生成的名字。通过查看DBA_PDB_SNAPSHOTS视图,可以找到快照存放的路径及创建快照的SCN号。
<span style="color:#444444"><span style="color:#222222">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 </span></span>
如果要删除快照,则有两种方法,第一种就是使用alter pluggable database删除,第二种是修改max_pdb_snapshots参数,当max_pdb_snapshots参数设置成0时,将删除全部快照。
<span style="color:#444444"><span style="color:#222222">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 </span></span>
演示了上述功能之后,还有一个功能,就是我们可以根据快照创建pdb。
<span style="color:#444444"><span style="color:#222222">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. </span></span>
这样我们就根据快照创建了一个新的PDB,假设当前PDB出现了数据覆盖,我们就可以使用这个历史快照的PDB来恢复数据。
当然还有一个很好用的功能就是我们在创建pdb的过程中把他设置成15分钟产生一个快照。当然配置这个功能有一个先决条件:CDB必须处于本地undo模式.
<span style="color:#444444"><span style="color:#222222">SQL> create pluggable database ORCLPDB3 from ORCLPDB1 file_name_convert=('ORCLPDB1','ORCLPDB3') snapshot mode every 5 minutes; Pluggable database created. </span></span>
可以看到每隔5分钟自动创建一个快照
<span style="color:#444444"><span style="color:#222222">[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 </span></span>
我们可以做个实验测试一下。在生成快照之前创建一个表插入点数据,这里上一次快照是23:43分。
<span style="color:#444444"><span style="color:#222222">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 </span></span>
23点48分产生了新的快照,此时我们使用新的快照做一个克隆,登陆到ORCLPDB4数据库后,我们会发现是有数据的。
<span style="color:#444444"><span style="color:#222222">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 </span></span>
这个功能对于测试人员非常有用,例如移动电信现在有BCV环境,专门用于经分抽数及测试,而这个BCV环境是底层同步的一个克隆。使用18c数据库,我们就可以直接创建快照,然后使用快照克隆一个新数据库形成BCV环境给经分抽数及测试使用了。
标签:18C,快照,NAME,snapshot,SNAPSHOT,PDB,CON 来源: https://blog.51cto.com/lhrbest/2706691