Oracle数据库中的PDB snapshot 与 snapshot copy PDB

概述

这两个概念容易混淆,简单来说:

  • snapshot copy PDB是12c新增的功能,依赖于底层存储快照
  • PDB snapshot是18c的功能,不必依赖底层存储快照
  • 他们的区别,也可以认为是snapshot和snapshot copy的区别

snapshot copy PDB

按照文档的的说法:

A snapshot copy PDB does not include a complete copy of the source data files. Rather, Oracle Database creates a storage-level snapshot of the underlying file system, and then creates the clone PDB from the snapshot.

也就是说:

  • snapshot copy PDB要求底层文件系统支持快照技术,例如ACFS
  • snapshot copy PDB包含的是稀疏文件,只有修改的数据库才会被存储

示例如下,但由于我底层文件系统不支持存储快照,因此失败:

sql 复制代码
SQL> create pluggable database orclpdb2_snapshot from orclpdb2 snapshot copy;
create pluggable database orclpdb2_snapshot from orclpdb2 snapshot copy
*
ERROR at line 1:
ORA-65169: error encountered while attempting to copy file
/u01/app/oracle/oradata/ORCL2/orclpdb2/users01.dbf
ORA-17525: Database clone using storage snapshot not supported on file
/u01/app/oracle/oradata/ORCL2/orclpdb2/users01.dbf


SQL> !oerr ora 17525
17525, 00000, "Database clone using storage snapshot not supported on file %s"
// *Cause:  Cloning a database using storage level snapshot is not supported
//          on the underlying storage.
// *Action: Use storage product that has snapshot based cloning support
//          for Oracle.

PDB snapshot

PDB snapshot是支持PDB Snapshot Carousel的底层技术。

按照文档的说法:

A PDB snapshot is a point-in-time copy of a PDB. The source PDB can be open read-only or read/write while the snapshot is created. You can create snapshots manually using the SNAPSHOT clause of CREATE PLUGGABLE DATABASE (or ALTER PLUGGABLE DATABASE), or automatically using the EVERY interval clause. If the storage system supports sparse clones, then the preceding command creates a sparse copy. Otherwise, the command creates a full copy.

也就是说,创建PDB snapshot时:

  • 源PDB可以是只读或读写状态,
  • 可以手工或自动创建
  • 生成的PDB可以是完全拷贝或稀疏拷贝,后者需要底层存储系统支持。

PDB snapshot主要有2个作用:

  1. 克隆PDB以用于开发测试
  2. 用于时间点恢复

PDB snapshot是Exadata的特性,如果不是Exadata,则会报错:

sql 复制代码
SQL> ALTER PLUGGABLE DATABASE SNAPSHOT;
ALTER PLUGGABLE DATABASE SNAPSHOT
*
ERROR at line 1:
ORA-12754: Feature PDB SNAPSHOT CAROUSEL is disabled due to missing capability

如果确实不是Exadata,也可以设置隐含参数以模拟Exadata。

sql 复制代码
connect / as sysdba
alter system set "_exadata_feature_on"=true scope=spfile;
shutdown immediate;
startup;

如果SNAPSHOT_MODE不是NONE,则可以手工创建PDB snapshot。

sql 复制代码
SET LINESIZE 150 TAB OFF

COLUMN pdb_name FORMAT A10
COLUMN snapshot_mode FORMAT A15

SELECT p.con_id,
       p.pdb_name,
       p.snapshot_mode,
       p.snapshot_interval
FROM   cdb_pdbs p
ORDER BY 1;

    CON_ID PDB_NAME   SNAPSHOT_MODE   SNAPSHOT_INTERVAL
---------- ---------- --------------- -----------------
         3 ORCLPDB1   MANUAL

手工创建PDB snapshot:

sql 复制代码
SQL> ALTER PLUGGABLE DATABASE SNAPSHOT;

Pluggable database altered.

查询PDB snapshot:

sql 复制代码
SET LINESIZE 150
COL CON_NAME FORMAT a9
COL ID FORMAT 99
COL SNAPSHOT_NAME FORMAT a17
COL SNAP_SCN FORMAT 9999999
COL FULL_SNAPSHOT_PATH FORMAT a61

SELECT CON_ID AS ID, CON_NAME, SNAPSHOT_NAME, 
       SNAPSHOT_SCN AS snap_scn, FULL_SNAPSHOT_PATH 
FROM   DBA_PDB_SNAPSHOTS
ORDER BY SNAP_SCN;

 ID CON_NAME  SNAPSHOT_NAME     SNAP_SCN FULL_SNAPSHOT_PATH
--- --------- ----------------- -------- -------------------------------------------------------------
  3 ORCLPDB2  SNAP_1677908289_1  3229763 /u01/app/oracle/oradata/ORCL2/orclpdb2/snap_1677908289_322976
              154256623                  3.pdb
sql 复制代码
SET LINESIZE 200
SET PAGESIZE 50000

COL ID FORMAT 99
COL CON_NAME FORMAT a10
COL SNAPSHOT_NAME FORMAT a26
COL SNAPSHOT_SCN FORMAT 9999999999
COL FULL_SNAPSHOT_PATH FORMAT a70

SELECT CON_ID AS ID, CON_NAME, SNAPSHOT_NAME, 
       SNAPSHOT_SCN, FULL_SNAPSHOT_PATH 
FROM   DBA_PDB_SNAPSHOTS;

 ID CON_NAME   SNAPSHOT_NAME               SNAPSHOT_SCN FULL_SNAPSHOT_PATH
--- ---------- -------------------------- ------------- ----------------------------------------------------------------------
  3 ORCLPDB2   SNAP_1677908289_1154256623       3229763 /u01/app/oracle/oradata/ORCL2/orclpdb2/snap_1677908289_3229763.pdb

pdb的后缀说明这时一个完全拷贝,而非稀疏拷贝。

下面的输出为0,也可以说明是完全拷贝。因为只有是稀疏拷贝时,DBA_PDB_SNAPSHOTFILE表才有行:

sql 复制代码
SQL> SELECT COUNT(*) FROM DBA_PDB_SNAPSHOTFILE;

  COUNT(*)
----------
         0

删除PDB snapshot:

sql 复制代码
SQL> ALTER PLUGGABLE DATABASE DROP SNAPSHOT SNAP_1677908289_1154256623;

Pluggable database altered.

参考

相关推荐
Mephisto.java33 分钟前
【大数据学习 | Spark】Spark的改变分区的算子
大数据·elasticsearch·oracle·spark·kafka·memcache
远歌已逝4 小时前
维护在线重做日志(二)
数据库·oracle
LKID体12 小时前
Python操作neo4j库py2neo使用(一)
python·oracle·neo4j
斗-匕13 小时前
Spring事务管理
数据库·spring·oracle
一行玩python13 小时前
SQLAlchemy,ORM的Python标杆!
开发语言·数据库·python·oracle
王ASC15 小时前
ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值。ojdbc8版本23.2.0.0驱动BUG【已解决】
数据库·sql·oracle
不爱学习的啊Biao16 小时前
初识mysql数据库
数据库·mysql·oracle
SRC_BLUE_1716 小时前
SQLI LABS | Less-55 GET-Challenge-Union-14 Queries Allowed-Variation 2
oracle·c#·less
.19 小时前
接口 测试
数据库·oracle
LIT-涛1 天前
JavaEE初学07
数据库·oracle·java-ee