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.

参考

相关推荐
百度智能云技术站1 小时前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
梦想平凡3 小时前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
夏木~4 小时前
Oracle 中什么情况下 可以使用 EXISTS 替代 IN 提高查询效率
数据库·oracle
吴冰_hogan6 小时前
MySQL InnoDB 存储引擎 Redo Log(重做日志)详解
数据库·oracle
CodeCraft Studio6 小时前
【实用技能】如何在 SQL Server 中处理 Null 或空值?
数据库·oracle·sqlserver
武汉联从信息6 小时前
浅谈ORACLE中间件SOA BPM,IDM,OID,UCM,WebcenterPortal服务器如何做迁移切换
oracle
Elastic 中国社区官方博客7 小时前
Elasticsearch:什么是查询语言?
大数据·数据库·elasticsearch·搜索引擎·oracle
夜光小兔纸8 小时前
oracle dblink 的创建及使用
数据库·oracle
Smile丶凉轩8 小时前
MySQL库的操作
数据库·mysql·oracle
p@nd@10 小时前
Oracle筑基篇-调度算法-LRU的引入
数据库·oracle·操作系统·lru