【跟我学oracle18c】第二十六天:Multitenant :16 管理PDB快照库

16 Administering a PDB Snapshot Carousel

您可以为指定的PDB配置一个PDB快照库,手动或自动创建快照,并设置快照的最大数量。

This section contains the following topics:

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:

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 follows
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 follows
Description of "Figure 16-2 Restore a Production PDB Using a Snapshot"

See Also:

Parent topic: About PDB Snapshot Carousel

16.1.2 How PDB Snapshot Carousel Works

The carousel 对于特定的PDB,是该PDB的一个循环复制库。

数据库根据需要或自动地在库中创建连续的副本。当达到快照限制时,数据库将重写最旧的快照。

This section includes the following topics:

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 follows
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 minutes value must be less than 3000.

    • The hours value must be less than 2000.

    The database assigns each automatic snapshot a system-generated name. Note that manual snapshots are also supported for the PDB when EVERY is specified.

  • NONE

    This clause disables snapshot creation for the PDB.

See Also:

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 DATABASEstatement

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:

  1. In SQL*Plus, ensure that the current container is the PDB for which you want to set the limit.

  2. Optionally, query CDB_PROPERTIES for the current setting of the SET MAX_PDB_SNAPSHOTS property.

  3. 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 150
COL CON_ID FORMAT 99999
COL PROPERTY_NAME FORMAT a17
COL PDB_NAME FORMAT a9
COL VALUE FORMAT a3
COL DESCRIPTION FORMAT a43

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     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 0 (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:

  1. In SQL*Plus, log in as an administrator to the PDB whose snapshot mode you intend to configure.

  2. Optionally, query DBA_PDBS to determine the current snapshot mode.

  3. Run ALTER PLUGGABLE DATABASE with the SNAPSHOT MODE EVERY intervalclause, specifying either MINUTES or HOURS.

To configure automatic snapshots when creating a PDB:

  1. In SQL*Plus, log in as an administrator to the CDB root or application root.

  2. Optionally, query DBA_PDBS to determine the current snapshot mode.

  3. Run CREATE PLUGGABLE DATABASE with the SNAPSHOT MODE EVERY intervalclause, 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_pdb1
  FILE_NAME_CONVERT=('cdb1_pdb1','cdb1_pdb3')
  SNAPSHOT MODE EVERY 120 MINUTES;

See Also:

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:

  1. In SQL*Plus, log in as an administrator to the PDB whose snapshot you intend to create.

  2. Optionally, query DBA_PDBS to confirm that the snapshot mode is not set to NONE.

  3. 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 load
ALTER 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 150
COL CON_NAME FORMAT a10
COL SNAPSHOT_NAME FORMAT a20
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 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

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 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 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
      3 CDB1_PDB1  SNAP_3489077498_960130367  2993525 /disk1/oracle/dbs/snap_3489077498_2993525.pdb

See Also:

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 0(zero).

To drop a PDB snapshot:

  1. In SQL*Plus, ensure that the current container is the PDB from which you created the PDB snapshot.

  2. 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

猜你喜欢

转载自blog.csdn.net/viviliving/article/details/84637021