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.

参考

相关推荐
BearHan1 小时前
Sqlsugar调用Oracle的存储过程
oracle·存储过程·orm
superman超哥1 小时前
04 深入 Oracle 并发世界:MVCC、锁、闩锁、事务隔离与并发性能优化的探索
数据库·oracle·性能优化·dba
Mephisto.java3 小时前
【大数据学习 | kafka高级部分】kafka的kraft集群
大数据·sql·oracle·kafka·json·hbase
Mephisto.java3 小时前
【大数据学习 | kafka高级部分】kafka的文件存储原理
大数据·sql·oracle·kafka·json
毕业设计制作和分享11 小时前
ssm《数据库系统原理》课程平台的设计与实现+vue
前端·数据库·vue.js·oracle·mybatis
Dingww101116 小时前
梧桐数据库中的网络地址类型使用介绍分享
数据库·oracle·php
2401_8570262317 小时前
Spring Boot框架下的知识管理与多维分类
spring boot·后端·oracle
shiran小坚果1 天前
AWS RDS MySQL内存使用
数据库·mysql·云计算·database·aws
刘艳兵的学习博客1 天前
刘艳兵-DBA027-在Oracle数据库,通常可以使用如下方法来得到目标SQL的执行计划,那么通过下列哪些方法得到的执行计划有可能是不准确的?
数据库·oracle·面试·database·刘艳兵
秋意钟1 天前
MySql事务
数据库·mysql·oracle