首页 » Cloud, ORACLE 9i-23ai » Oracle 12c R2 New Feature: Hot Clone A PDB (12.2热克隆)

Oracle 12c R2 New Feature: Hot Clone A PDB (12.2热克隆)

在12.1版本中Clone一份PDB源库需要打开在read only只读模式, 在12.2版本中引入了local undo mode, 源PDB在read/write 读写模式也可以Clone.  这样可以在复制一份测试环境时对源库影响降到最低, 同时local undo mode也是ORACLE推荐的.

12.1 源PDB在read/write模式clone是不允许的.以前的小例子12.1 clone pdb

ORA-65081: database or pluggable database is not open in read only mode

下面会演示一下12.2 的PDB HOT Clone, 开始前先补充一点local undo的知识.

UNDO模式

undo 在12C R1版本中只支持Global Shared Undo模式, 所有container共享一个UNDO表空间, 目前保留这种模式只是为了升级过渡, 在12C R2引入了PDB Local UNDO模式,每个container都有自己的UNDO 表空间, 对于RAC是每个实例每个container都有自己的UNDO表空间, 这也正是推荐的. 无论是Shared undo还是Local undo模式,都是CDB的属性,所以在修改时当前的container都要在cdb$root下. 12.2只要配置了LOCAL undo才支持下面的新特性:Hot Clone,    Refresh PDB,   PDB Relocate,   Flashback PDB

如何检查当前UNDO模式?

SQL> select * from database_properties where property_name='LOCAL_UNDO_ENABLED';
PROPERTY_NAME PROPE DESCRIPTION
-------------------- ----- -----------------------------------
LOCAL_UNDO_ENABLED TRUE true if local undo is enabled

UNDO模式转换

How to convert CDB from Local to Shared Undo Mode

When a CDB is in local undo mode, you can change it to use shared undo mode by issuing an ALTER DATABASE LOCAL UNDO OFF statement and restarting the database.
When it is in shared undo mode, the CDB ignores any local undo tablespaces that were created when it was in local undo mode. 
Oracle recommends that you delete these local undo tablespaces.

startup upgrade
ALTER DATABASE LOCAL UNDO off; 
shutdown immediate
startup
ALTER PLUGGABLE DATABASE xxx OPEN READ WRITE; 

ALTER SESSION SET CONTAINER=xxx; 

select a.CON_ID,a.TABLESPACE_NAME,b.FILE_NAME 
from cdb_tablespaces a,CDB_DATA_FILES b 
where a.TABLESPACE_NAME=b.TABLESPACE_NAME and a.con_id=b.con_id and a.CONTENTS='UNDO'; 

drop tablespace UNDOTBS1 including contents and datafiles; 

How to convert CDB from Shared to Local Undo Mode

startup upgrade
container set cdb$root ,if not :alter session set container=cdb$root;
ALTER DATABASE LOCAL UNDO ON;
shutdown immediate;
startup
-- When a CDB is changed from shared undo mode to local undo mode, 
-- Oracle Database creates the required undo tablespaces automatically.
alter pluggable database xxx open;

Hot Clone Local PDB

因为我当前的测试环境12.2只有一套,先测试Clone LOCAL Pdb,   环境oracle 12.2.0.1 ee  on OEL 6, HOT Clone的内部原理:

Source PDB remains open for read and write
Read and copy in parallel
On-going operations imply a “dirty read”
Some data changes not included in initial file copy
Ship and apply redo to catch up with source
Apply undo to rollback uncommitted transactions

所以在较长或较大PDB Clone期间要保证REDO 日志存在, 最好源库开起archivelog mode.

[oracle@anbob ~]$ ora
SQL*Plus: Release 12.2.0.1.0 Production on Mon Mar 6 17:11:54 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c EE Extreme Perf Release 12.2.0.1.0 - 64bit Production

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBANBOB                       MOUNTED
		 
SQL> alter pluggable database pdbanbob open;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBANBOB                       READ WRITE NO
		 
SQL> create pluggable database pdbweejar from pdbanbpb;
create pluggable database pdbweejar from pdbanbpb

ERROR at line 1:
ORA-65016: FILE_NAME_CONVERT must be specified

SQL> alter session set pdb_file_name_convert='anbob','weejar';
Session altered.

-- Multi-threaded based on cpu count by default
-- File copy progress can be monitored in v$session_longops:

SQL> create pluggable database pdbweejar from pdbanbob;
Pluggable database created.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBANBOB                       READ WRITE NO
         6 PDBWEEJAR                      MOUNTED
		 

SQL> alter pluggable database pdbweejar open;
Pluggable database altered.

SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDBANBOB                       READ WRITE NO
         6 PDBWEEJAR                      READ WRITE NO
		 
SQL> alter session set container=pdbweejar;
Session altered. 

SQL> select * from v$dbfile
     FILE# NAME                                                                  CON_ID               
---------- -------------------------------------------------------------------- ----------
        14 /u02/app/oracle/oradata/weejar/pdbweejar/system01.dbf                      6         
        15 /u02/app/oracle/oradata/weejar/pdbweejar/sysaux01.dbf                      6         
        16 /u02/app/oracle/oradata/weejar/pdbweejar/undotbs01.dbf                     6         
        17 /u02/app/oracle/oradata/weejar/pdbweejar/users01.dbf                       6         
        18 /u02/app/oracle/oradata/weejar/pdbweejar/lower01.dbf                       6        


SQL> alter session set container=pdbanbob;
Session altered.

SQL> set lines 300
SQL> select * from v$dbfile;

     FILE# NAME                                                                                 CON_ID
---------- -------------------------------------------------------------------------------- ----------
         9 /u02/app/oracle/oradata/anbob/pdbanbob/system01.dbf                                       3
        10 /u02/app/oracle/oradata/anbob/pdbanbob/sysaux01.dbf                                       3
        11 /u02/app/oracle/oradata/anbob/pdbanbob/undotbs01.dbf                                      3
        12 /u02/app/oracle/oradata/anbob/pdbanbob/users01.dbf                                        3
        13 /u02/app/oracle/oradata/anbob/pdbanbob/lower01.dbf                                        3
		
SQL> select * from database_properties;

PROPERTY_NAME               PROPERTY_VALUE       DESCRIPTION
--------------------------- -------------------- ------------------------------------------------------------
CON_VSN                     5                    version number for the CDB or the Application Container
DICTIONARY_ENDIAN_TYPE      LITTLE               Endian type of the data dictionary
LOCAL_UNDO_ENABLED          TRUE                 true if local undo is enabled
OLS_OID_STATUS              0                    OLS OID Status used for Label Security
GLOBAL_DB_NAME              ANBOB.COM            Global database name

Hot Clone REMOTE PDB

ENABLE ARCHIVELOG MODE IN CDB$ROOT
    CDB$ROOT-SQL> startup mount
    CDB$ROOT-SQL> alter database archivelog;
    CDB$ROOT-SQL> alter database open;
ENABLE LOCAL UNDO IN CDB$ROOT
    CDB$ROOT-SQL> startup mount
    CDB$ROOT-SQL> alter database open upgrade;
    CDB$ROOT-SQL> alter database local undo on;
CREATE COMMON USER IN CDB$ROOT
     CDB$ROOT-SQL> create user c##admin identified by <password> container=all;
     CDB$ROOT-SQL> grant sysoper to c##admin container=all;
CREATE PUBLIC DATABASE LINK IN CDB$ROOT
    CDB$ROOT-SQL> create public database link cdb1_link connect to c##admin 
     identified by <password> using ‘<tns alias>’;
CREATE PLUGGABLE DATABASE PDB_DEV FROM PDB@DBLINK;

Summary:
12.2引入了local undo解决了12.1时clone pdb时源PDB需要READ-ONLY的前提. 减少了clone pdb时对源库的影响. 12.2 可以在shared undo和local undo之前来回的转换, 事务可以透明的转移, 从LOCAL 转到 SHARED里,第一次打开PDB时会应用local undo接着使用shared undo, 后就不再需要local undo, 但是local undo mode是ORACLE建议的配置. 这样才可以使用HOT CLONE和Refresh PDB及快速的闪回PDB时使用.

References:
Undo Modes in 12.2 Multitenant Databases – Local and Shared Modes (文档 ID 2169828.1)

打赏

,

对不起,这篇文章暂时关闭评论。