Creating a PDB in a Primary Database using CREATE PLUGGABLE DATABASE FROM

os: centos 7.6
db: oracle 19.3

oracle active dataguard 环境下,在 primary 上创建的pdb.

enabled_pdbs_on_standby

SQL> show parameter enabled_pdbs_on_standby;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
enabled_PDBs_on_standby 	     string	 *

The ENABLED_PDBS_ON_STANDBY parameter is valid only on a physical standby,it is ignored by primary databases.;

STANDBYS

CREATE PLUGGABLE DATABASE … STANDBYS={('cdb_name', 'cdb_name', ...) |
NONE | ALL [EXCEPT ('cdb_name', 'cdb_name', ...)]}

– cdb_name is the DB_UNIQUE_NAME for the physical standbys in which the PDB is to be included.

– NONE excludes the PDB from being created in any of the standby CDBs. When
a PDB is excluded from all standby CDBs, the PDB’s data files are offline and
marked as unnamed on all of the standby CDBs. Any new standby CDBs that
are instantiated after the PDB has been created must disable the PDB for
recovery explicitly to exclude it from the standby CDB. It is possible to enable
a PDB on a standby CDB after it was excluded on that standby CDB.

– ALL (the default) includes the PDB being created in all standby CDBs.

– EXCEPT cdb_name includes the PDB being created in all standby CDBs except for those CDBs listed in this clause by their DB_UNIQUE_NAME.

automatically maintain standby databases

• To automatically maintain standby databases when performing PDB remote
clones or plugins, use the following initialization parameters:

STANDBY_PDB_SOURCE_FILE_DBLINK
—For use with remote cloning. Specifies
the name of the database link used to clone the PDB at the primary. When
the redo for the PDB clone operation is applied at the standby, it uses that
database link to connect to the source database to repeat the clone process to
the destination standby database. This parameter is available only in Active
Data Guard because it accesses the database dictionary for specific
information about the link.
The source PDB for the cloning operation must be in read only mode for the
duration of both the clone to the primary and the clone to the standby.
On remote clones that do not use the STANDBY_PDB_SOURCE_FILE_DBLINK
parameter, the SQL CREATE PLUGGABLE DATABASE statement used to create
the PDB must use the STANDBYS=NONE clause.

STANDBY_PDB_SOURCE_FILE_DIRECTORY
—For use with plugins. Specifies the
directory location where files of a PDB being used for repeated plugins are
stored. When the redo for the PDB plugin operation is applied at the standby,
it searches the directory location for the data files and after finding them,
copies them to the location the standby requires them to be based on the
settings of the DB_CREATE_FILE_DEST and DB_FILE_NAME_CONVERT parameters.

CREATE PLUGGABLE DATABASE FROM

如果前面已经创建了 pdb2,先删除.生产环境禁止删除

扫描二维码关注公众号,回复: 6632051 查看本文章
SQL> alter pluggable database pdb2 close immediate;
alter pluggable database pdb2 unplug into '/tmp/pdb2.xml';
drop pluggable database pdb2 including datafiles;

SQL> drop pluggable database pdb1 keep datafiles;

在 primay 上使用 CREATE PLUGGABLE DATABASE FROM 创建新的 pdb

SQL> CREATE PLUGGABLE DATABASE pdb2 FROM pdb1 tempfile reuse 
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/ORCLP/pdb1/', 
                     '/u01/app/oracle/oradata/ORCLP/pdb2/'
					 ) 
STORAGE UNLIMITED
STANDBYS=ALL    
;

primary 上的 alert 日志

2019-06-21T11:36:02.000849+08:00
CREATE PLUGGABLE DATABASE pdb2 FROM pdb1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/ORCLP/pdb1/',
                     '/u01/app/oracle/oradata/ORCLP/pdb2/')
STORAGE UNLIMITED
STANDBYS=ALL
2019-06-21T11:36:02.532420+08:00
PDB1(3): AUDSYS.AUD$UNIFIED (SQL_TEXT) - CLOB populated
2019-06-21T11:36:32.987595+08:00
PDB2(4):Endian type of dictionary set to little
****************************************************************
Pluggable Database PDB2 with pdb id - 4 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
local undo-1, localundoscn-0x0000000000000118
****************************************************************
2019-06-21T11:36:34.130716+08:00
PDB2(4):Media Recovery Start
2019-06-21T11:36:34.131046+08:00
PDB2(4):Serial Media Recovery started
PDB2(4):max_pdb is 4
2019-06-21T11:36:34.264516+08:00
PDB2(4):Recovery of Online Redo Log: Thread 1 Group 1 Seq 28 Reading mem 0
PDB2(4):  Mem# 0: /u01/app/oracle/oradata/ORCLP/redo01.log
2019-06-21T11:36:34.342591+08:00
PDB2(4):Incomplete Recovery applied until change 2508565 time 06/21/2019 11:36:29
2019-06-21T11:36:34.360892+08:00
PDB2(4):Media Recovery Complete (orclp1)
PDB2(4):Autotune of undo retention is turned on. 
2019-06-21T11:36:35.299551+08:00
PDB2(4):Undo initialization recovery: err:0 start: 143335454 end: 143335566 diff: 112 ms (0.1 seconds)
PDB2(4):[29984] Successfully onlined Undo Tablespace 2.
PDB2(4):Undo initialization online undo segments: err:0 start: 143335566 end: 143335573 diff: 7 ms (0.0 seconds)
PDB2(4):Undo initialization finished serial:0 start:143335454 end:143335575 diff:121 ms (0.1 seconds)
PDB2(4):Database Characterset for PDB2 is AL32UTF8
2019-06-21T11:36:35.406148+08:00
PDB2(4):JIT: pid 29984 requesting stop
PDB2(4):Buffer Cache flush started: 4
PDB2(4):Buffer Cache flush finished: 4
2019-06-21T11:36:36.850692+08:00
Completed: CREATE PLUGGABLE DATABASE pdb2 FROM pdb1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/ORCLP/pdb1/',
                     '/u01/app/oracle/oradata/ORCLP/pdb2/')
STORAGE UNLIMITED
STANDBYS=ALL

standby 上的 alert 日志

2019-06-21T11:36:32.466822+08:00
Recovery created pluggable database PDB2
PDB2(4):Tablespace-SYSTEM during PDB create skipped since source is in            r/w mode or this is a refresh clone
PDB2(4):File #13 added to control file as 'UNNAMED00013'. Originally created as:
PDB2(4):'/u01/app/oracle/oradata/ORCLP/pdb2/system01.dbf'
PDB2(4):because the pluggable database was created with nostandby
PDB2(4):or the tablespace belonging to the pluggable database is
PDB2(4):offline.

PDB2(4):Tablespace-SYSAUX during PDB create skipped since source is in            r/w mode or this is a refresh clone
PDB2(4):File #14 added to control file as 'UNNAMED00014'. Originally created as:
PDB2(4):'/u01/app/oracle/oradata/ORCLP/pdb2/sysaux01.dbf'
PDB2(4):because the pluggable database was created with nostandby
PDB2(4):or the tablespace belonging to the pluggable database is
PDB2(4):offline.

2019-06-21T11:36:33.559151+08:00
PDB2(4):Tablespace-UNDOTBS1 during PDB create skipped since source is in            r/w mode or this is a refresh clone
PDB2(4):File #15 added to control file as 'UNNAMED00015'. Originally created as:
PDB2(4):'/u01/app/oracle/oradata/ORCLP/pdb2/undotbs01.dbf'
PDB2(4):because the pluggable database was created with nostandby
PDB2(4):or the tablespace belonging to the pluggable database is
PDB2(4):offline.

PDB2(4):Tablespace-TEMP during PDB create skipped since source is in            r/w mode or this is a refresh clone

PDB2(4):Tablespace-USERS during PDB create skipped since source is in            r/w mode or this is a refresh clone
PDB2(4):File #16 added to control file as 'UNNAMED00016'. Originally created as:
PDB2(4):'/u01/app/oracle/oradata/ORCLP/pdb2/users01.dbf'
PDB2(4):because the pluggable database was created with nostandby
PDB2(4):or the tablespace belonging to the pluggable database is
PDB2(4):offline.

这是什么情况?在 priamry 上创建 pdb 成功,但是在 standby 失败了.

异常处理

这种方式貌似要特殊处理一下,重点关注下文档 ID 1916648.1

priamry 节点上查看

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT

SQL> alter pluggable database pdb2 open;
SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDB1 			  READ WRITE NO
	 4 PDB2 			  READ WRITE NO

SQL> select name, recovery_status from v$pdbs;

NAME												     RECOVERY
---------------------------------------------------------------------------------------------------- --------
PDB$SEED											     ENABLED
PDB1												     ENABLED
PDB2												     ENABLED

standby 节点上查看

SQL> show pdbs;

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDB1 			  READ ONLY  NO
	 4 PDB2 			  MOUNTED
	 
SQL> select name, recovery_status from v$pdbs;

NAME												     RECOVERY
---------------------------------------------------------------------------------------------------- --------
PDB$SEED											     ENABLED
PDB1												     ENABLED
PDB2												     ENABLED

SQL> alter session set container=cdb$root;
select * from v$recover_file;

     FILE# ONLINE  ONLINE_ ERROR								CHANGE# TIME			CON_ID
---------- ------- ------- ----------------------------------------------------------------- ---------- ------------------- ----------
	13 OFFLINE OFFLINE FILE MISSING 							      0 			     4
	14 OFFLINE OFFLINE FILE MISSING 							      0 			     4
	15 OFFLINE OFFLINE FILE MISSING 							      0 			     4
	16 OFFLINE OFFLINE FILE MISSING 							      0 			     4

standby 节点上查看信息

$ sqlplus / as sysdba

SQL> alter session set container=cdb$root;
set lines 200;
set pages 200;
col con_id format 99;
col name format a80;
select file#,con_id, name from v$datafile where con_id=4;
select * from v$recover_file;

SQL> 
     FILE# CON_ID NAME
---------- ------ --------------------------------------------------------------------------------
	13	4 /u01/app/oracle/product/19.0.0/db_1/dbs/UNNAMED00013
	14	4 /u01/app/oracle/product/19.0.0/db_1/dbs/UNNAMED00014
	15	4 /u01/app/oracle/product/19.0.0/db_1/dbs/UNNAMED00015
	16	4 /u01/app/oracle/product/19.0.0/db_1/dbs/UNNAMED00016

SQL> 
     FILE# ONLINE  ONLINE_ ERROR								CHANGE# TIME		    CON_ID
---------- ------- ------- ----------------------------------------------------------------- ---------- ------------------- ------
	13 OFFLINE OFFLINE FILE MISSING 							      0 			 4
	14 OFFLINE OFFLINE FILE MISSING 							      0 			 4
	15 OFFLINE OFFLINE FILE MISSING 							      0 			 4
	16 OFFLINE OFFLINE FILE MISSING 							      0 			 4

standby 节点上执行恢复

SQL> alter session set container=cdb$root;
alter system set standby_file_management=auto;
alter database recover managed standby database cancel;

SQL> alter session set container=pdb2;
alter pluggable database disable recovery;

RMAN> run{
 set newname for pluggable database pdb2 to new;
 restore pluggable database pdb2 from service tns_orcl_orclp ;
 switch datafile all;
 }
 
SQL> alter session set container=cdb$root;
shutdown immediate;

SQL> startup mount;
SQL> alter session set container=pdb2;
alter pluggable database enable recovery;


SQL> alter session set container=cdb$root;
alter database recover managed standby database disconnect from session;
select open_mode from v$database;

alter database open;
select open_mode from v$database;

alter pluggable database pdb2 open;


SQL> alter session set container=pdb2;
alter tablespace temp add tempfile '/u01/app/oracle/oradata/ORCLS1/pdb2/temp01.dbf' 
size 1g reuse autoextend on next 1g maxsize unlimited;

经过分析发现,dataguard 环境下,只要 source pdb 是 READ ONLY,那么在primary 上执行创建pdb时,在 standby 上就能顺利创建.

参考:
https://www.eygle.com/archives/2009/07/dataguard_ora_01111.html

<<Data Guard Impact on Oracle Multitenant Environments (文档 ID 2049127.1)>>
https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=jaq4mie22_77&_afrLoop=200677102874764#RestoreControlfileStep7

<<How to Restore - Dropped Pluggable database (PDB) in Multitenant (文档 ID 2034953.1)>>
https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=jaq4mie22_77&_afrLoop=200677102874764#BODYTEXT

<<Data Guard Impact on Oracle Multitenant Environments (文档 ID 2049127.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=491556257459343&id=2049127.1&_adf.ctrl-state=qj0kopej7_57

<<Using standby_pdb_source_file_dblink and standby_pdb_source_file_directory to Maintain Standby Databases when Performing PDB Remote Clones or Plugins (文档 ID 2274735.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=491589006771750&id=2274735.1&_adf.ctrl-state=qj0kopej7_114

<<Reusing the Source Standby Database Files When Plugging a PDB into the Primary Database of a Data Guard Configuration (文档 ID 2273829.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=507056659200847&parent=DOCUMENT&sourceId=2049127.1&id=2273829.1&_afrWindowMode=0&_adf.ctrl-state=aiwu1g5fe_151

<<Making Use Deferred PDB Recovery and the STANDBYS=NONE Feature with Oracle Multitenant (文档 ID 1916648.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=507030330889269&parent=DOCUMENT&sourceId=2049127.1&id=1916648.1&_afrWindowMode=0&_adf.ctrl-state=aiwu1g5fe_102

<<Cloning a Pluggable Database from an RMAN Container Database Backup (文档 ID 2042607.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=507020513523383&parent=DOCUMENT&sourceId=2049127.1&id=2042607.1&_afrWindowMode=0&_adf.ctrl-state=aiwu1g5fe_53

<<Step by Step Process of Migrating non-CDBs and PDBs Using ASM for File Storage (文档 ID 1576755.1)>>
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=509109952689624&parent=DOCUMENT&sourceId=1916648.1&id=1576755.1&_afrWindowMode=0&_adf.ctrl-state=aiwu1g5fe_249

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/93524410