测试数据库复制--之复制CDB附带PDB的部分表空间
---------------------------------------------------------------------------------------------------------
环境:
OS:CENTOS 7.8 64bit
DB:12.1.0.2 64bit
----------------------------------------------------------------------------------------------------------
一、目标库准备
1.创建参数文件并创建相关目录:
[oracle@dbserver ~]$ more /home/oracle/initcdb2.ora
control_files='/u01/app/oracle/oradata/cdb2/control01.ctl'
enable_pluggable_database=true
db_create_file_dest='/u01/app/oracle/oradata/cdb2'
memory_target=800M
db_name=cdb2
compatible=12.1.0.2
mkdir -p /u01/app/oracle/oradata/cdb2
2.创建SPFILE启动到nomount
[oracle@dbserver ~]$ export ORACLE_SID=cdb2
[oracle@dbserver ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Fri Nov 6 02:48:29 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile='/home/oracle/initcdb2.ora';
File created.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
3.准备静态监听
[oracle@dbserver admin]$ more listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = cdb2)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1)
(SID_NAME = cdb2)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
4.准备密码文件
[oracle@dbserver dbs]$ cp $ORACLE_HOME/dbs/orapwcdb1 $ORACLE_HOME/dbs/orapwcdb2
二、在源库中进行复制:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED NO
SQL> select tablespace_name,con_id from cdb_tablespaces;
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 3
SYSAUX 3
TEMP 3
USERS 3
EXAMPLE 3
SYSTEM 1
SYSAUX 1
UNDOTBS1 1
TEMP 1
USERS 1
[oracle@dbserver ~]$ rman target sys/oracle@localhost/cdb1 auxiliary sys/oracle@localhost/cdb2
Recovery Manager: Release 12.1.0.2.0 - Production on Fri Nov 6 02:55:05 2020
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: CDB1 (DBID=1028826191)
connected to auxiliary database: CDB2 (not mounted)
RMAN> duplicate target database to cdb2
2> tablespace pdb1:example
3> from active database;
Starting Duplicate Db at 06-NOV-20
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=174 device type=DISK
current log archived
contents of Memory Script:
{
sql clone "alter system set db_name =
''CDB1'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''CDB2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone from service 'localhost/cdb1' primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''CDB1'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''CDB2'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
Starting restore at 06-NOV-20
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output file name=/u01/app/oracle/oradata/cdb2/control01.ctl
Finished restore at 06-NOV-20
database mounted
Automatically adding tablespace SYSTEM
Automatically adding tablespace SYSAUX
Automatically adding tablespace PDB$SEED:SYSTEM
Automatically adding tablespace PDB$SEED:SYSAUX
Automatically adding tablespace PDB1:SYSTEM
Automatically adding tablespace PDB1:SYSAUX
Automatically adding tablespace UNDOTBS1
Checking that duplicated tablespaces are self-contained
DBGSQL: TARGET>
DBGSQL: begin
DBGSQL: sys.dbms_tts.transport_set_check(' EXAMPLE', true, true);
DBGSQL: end;
DBGSQL:
DBGSQL: sqlcode = 6550
Oracle instance started
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CDB2'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
}
executing Memory Script
sql statement: alter system set db_name = ''CDB2'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 11/06/2020 02:56:16
RMAN-05501: aborting duplication of target database
ORA-06550: line 3, column 7:
PLS-00201: identifier 'SYS.DBMS_TTS' must be declared
ORA-06550: line 3, column 7:
PL/SQL: Statement ignored
出现这个错误有点纳闷,系统包怎么会不存在呢。
登录源库PDB1去查看
SQL> alter session set container=pdb1;
SQL> desc dbms_tts;
ERROR:
ORA-04043: object dbms_tts does not exist
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 PDB1 MOUNTED
原来是要复制的PDB1都没有打开,太疏忽了。
SQL> startup;
再次进行复制测试,没有出现问题。
[oracle@dbserver ~]$ rman target sys/oracle@localhost/cdb1 auxiliary sys/oracle@localhost/cdb2
Recovery Manager: Release 12.1.0.2.0 - Production on Fri Nov 6 03:01:02 2020
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: CDB1 (DBID=1028826191)
connected to auxiliary database: CDB2 (not mounted)
RMAN> duplicate target database to cdb2
2> tablespace pdb1:example
3> from active database;
Starting Duplicate Db at 06-NOV-20
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=174 device type=DISK
current log archived
contents of Memory Script:
{
sql clone "alter system set db_name =
''CDB1'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''CDB2'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone from service 'localhost/cdb1' primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''CDB1'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''CDB2'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
Starting restore at 06-NOV-20
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=12 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/cdb2/control01.ctl
Finished restore at 06-NOV-20
database mounted
Automatically adding tablespace SYSTEM
Automatically adding tablespace SYSAUX
Automatically adding tablespace PDB$SEED:SYSTEM
Automatically adding tablespace PDB$SEED:SYSAUX
Automatically adding tablespace PDB1:SYSTEM
Automatically adding tablespace PDB1:SYSAUX
Automatically adding tablespace UNDOTBS1
Checking that duplicated tablespaces are self-contained
Skipping tablespace USERS
Skipping tablespace PDB1:USERS
contents of Memory Script:
{
set newname for clone datafile 1 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 5 to new;
set newname for clone datafile 7 to new;
set newname for clone datafile 8 to new;
set newname for clone datafile 9 to new;
set newname for clone datafile 11 to new;
restore
from service 'localhost/cdb1' clone database
skip forever tablespace "USERS",
"PDB1":"USERS" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 06-NOV-20
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_example_%u_.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 06-NOV-20
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'localhost/cdb1'
archivelog from scn 1849323;
switch clone datafile all;
}
executing Memory Script
Starting restore at 06-NOV-20
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=27
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service localhost/cdb1
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=28
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 06-NOV-20
datafile 1 switched to datafile copy
input datafile copy RECID=15 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0qobw_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=16 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qrg6_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=17 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_undotbs1_htb0qvhj_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=18 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0qwkp_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=19 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qxml_.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=20 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0r0og_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=21 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0r1q6_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=22 STAMP=1055732542 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_example_htb0r4s1_.dbf
contents of Memory Script:
{
set until scn 1849413;
recover
clone database
skip forever tablespace "USERS",
"PDB1":"USERS" delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 06-NOV-20
using channel ORA_AUX_DISK_1
Executing: alter database datafile 6 offline drop
Executing: alter database datafile 10 offline drop
starting media recovery
archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/product/12.1.0/db_1/dbs/arch1_27_1055108754.dbf
archived log for thread 1 with sequence 28 is already on disk as file /u01/app/oracle/product/12.1.0/db_1/dbs/arch1_28_1055108754.dbf
archived log file name=/u01/app/oracle/product/12.1.0/db_1/dbs/arch1_27_1055108754.dbf thread=1 sequence=27
archived log file name=/u01/app/oracle/product/12.1.0/db_1/dbs/arch1_28_1055108754.dbf thread=1 sequence=28
media recovery complete, elapsed time: 00:00:00
Finished recover at 06-NOV-20
Oracle instance started
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''CDB2'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
}
executing Memory Script
sql statement: alter system set db_name = ''CDB2'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance started
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "CDB2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 SIZE 50 M ,
GROUP 2 SIZE 50 M ,
GROUP 3 SIZE 50 M
DATAFILE
'/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0qobw_.dbf',
'/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0qwkp_.dbf',
'/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_system_htb0r0og_.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for clone tempfile 1 to new;
set newname for clone tempfile 2 to new;
set newname for clone tempfile 3 to new;
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qrg6_.dbf",
"/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_undotbs1_htb0qvhj_.dbf",
"/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qxml_.dbf",
"/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0r1q6_.dbf",
"/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_example_htb0r4s1_.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 2 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_temp_%u_.tmp in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qrg6_.dbf RECID=1 STAMP=1055732560
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_undotbs1_htb0qvhj_.dbf RECID=2 STAMP=1055732560
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qxml_.dbf RECID=3 STAMP=1055732560
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0r1q6_.dbf RECID=4 STAMP=1055732560
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_example_htb0r4s1_.dbf RECID=5 STAMP=1055732560
datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=1055732560 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qrg6_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=1055732560 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_undotbs1_htb0qvhj_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=3 STAMP=1055732560 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0qxml_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=4 STAMP=1055732560 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_sysaux_htb0r1q6_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=5 STAMP=1055732560 file name=/u01/app/oracle/oradata/cdb2/CDB2/datafile/o1_mf_example_htb0r4s1_.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
contents of Memory Script:
{
sql clone "alter pluggable database all open";
}
executing Memory Script
sql statement: alter pluggable database all open
Dropping offline and skipped tablespaces
Executing: alter database default tablespace system
Executing: drop tablespace "USERS" including contents cascade constraints
Executing: alter database default tablespace system
Executing: drop tablespace "USERS" including contents cascade constraints
Finished Duplicate Db at 06-NOV-20
三、登录目标库验证
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
SQL> select tablespace_name,con_id from cdb_tablespaces;
TABLESPACE_NAME CON_ID
------------------------------ ----------
SYSTEM 1
SYSAUX 1
UNDOTBS1 1
TEMP 1
SYSTEM 3
SYSAUX 3
TEMP 3
EXAMPLE 3
确实只将PDB1中的EXAMPLE表空间复制过来了,
而SYSTEM、SYSAUX、TEMP是强制要复制过来的。
|