OCA/OCP Oracle 数据库12c考试指南读书笔记:第27章: Duplicating a Database

可传输表空间可将表空间从一个数据库拷贝到另一数据库,而无需耗时的export/import。
可传输数据库是可传输表空间的扩展,可创建新数据库,并将非系统表空间拷贝到新数据库。
还可以复制整个数据库,源数据库可以不停机,无需RMAN中间文件,因此可节省时间和空间。

描述和使用可传输表空间和可传输数据库

数据在数据库间的传递可使用Database Link,Data Pump和可传输表空间。数据量大时,可传输表空间是最快的。
简单来说,是利用Data Pump导出元数据,然后拷贝数据文件到目标端,然后在目标数据库中导入元数据。源和目标数据库的硬件平台可以不同,但字符集必须相同。

配置可传输表空间

源和目标平台必须Oracle支持。

确认兼容性需求

Oracle数据库兼容性受COMPATIBLE参数控制,已启用或禁用某些数据库特性。
例如从11g升级到12c时,可以暂时将兼容性设置为11g,这样如果升级后遇到问题,可以回退到11g而无需做数据库恢复。
从11g开始,可以将表空间迁移到相同或更高兼容性级别的硬件平台。

确认字节序(Endian)要求

字节序分为Little Endian和Big Endian,例如2,如果存为0x0002,则称为Big Endian,如果存为0x0200,则称为Little Endian。
如果两个平台的字节序不同,则需要做转换。
以下为支持平台的字节序:

SQL> select platform_id, platform_name, endian_format from v$transportable_platform;

PLATFORM_ID PLATFORM_NAME                        ENDIAN_FORMAT
----------- ------------------------------------ --------------
          1 Solaris[tm] OE (32-bit)              Big
          2 Solaris[tm] OE (64-bit)              Big
          7 Microsoft Windows IA (32-bit)        Little
         10 Linux IA (32-bit)                    Little
          6 AIX-Based Systems (64-bit)           Big
          3 HP-UX (64-bit)                       Big
          5 HP Tru64 UNIX                        Little
          4 HP-UX IA (64-bit)                    Big
         11 Linux IA (64-bit)                    Little
         15 HP Open VMS                          Little
          8 Microsoft Windows IA (64-bit)        Little
          9 IBM zSeries Based Linux              Big
         13 Linux x86 64-bit                     Little
         16 Apple Mac OS                         Big
         12 Microsoft Windows x86 64-bit         Little
         17 Solaris Operating System (x86)       Little
         18 IBM Power Based Linux                Big
         19 HP IA Open VMS                       Little
         20 Solaris Operating System (x86-64)    Little
         21 Apple Mac OS (x86-64)                Little
         22 Linux OS (S64)                       Big

21 rows selected.

当前平台的字节序:

SQL> select platform_name, endian_format from v$transportable_platform join v$database using(platform_name);

PLATFORM_NAME                        ENDIAN_FORMAT
------------------------------------ --------------
Linux x86 64-bit                     Little

如果两个平台的字节序不同,则必须在源或目标端利用RMAN来将数据文件转为目标平台支持的格式,例如:

RMAN> convert datafile 'path_to_file' to platform 'AIX-Based Systems (64-bit)' format 'path_to_file';

文件可直接或通过DBMS_FILE_TRANSFER拷贝到目标平台。

传输的表空间必须是自包含的

表空间中包含的对象必须是完整的,若一个对象引用零一对象,则它们必须都包含在内。DBMS_TTS可以测试自包含性。
例如一个表包含多个分区,每个分区在不同的表空间。

可传输表空间

大致过程如下:

  1. 将源表空间设为只读
  2. 在源端,使用DataPump导出表空间的元数据
  3. 如果与目标端的字节序不同,则转换数据文件(可以在源或目标端做)
  4. 将表空间相关的数据文件和元数据拷贝到目标端(可使用DBMS_FILE_TRANSFER完成)
  5. 使用Data Pump导入元数据
  6. 将源和目标数据库设为读写

示例:

-- 连接到PDB
connect sys/Welcome1@orclpdb1 as sysdba
create tablespace trans datafile '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/trans.dbf' size 10m;
create table transtab tablespace trans as select * from all_users;
-- 检测耗时会长些
exec dbms_tts.transport_set_check('trans');
select * from transport_set_violations;
alter tablespace trans read only;

然后导出元数据,这个命令执行时间较长:

$ expdp "sys/Welcome1@orclpdb1 as sysdba" dumpfile=trans.dmp transport_tablespaces=trans
LRM-00108: invalid positional parameter value 'sysdba'

[oracle@oracle-19c-vagrant ~]$ expdp system/Welcome1@orclpdb1 dumpfile=trans.dmp transport_tablespaces=trans

Export: Release 19.0.0.0.0 - Production on Tue Dec 24 18:28:21 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@orclpdb1 dumpfile=trans.dmp transport_tablespaces=trans
Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
  /opt/oracle/admin/ORCLCDB/dpdump/974B2FC950D006CEE0530100007FB806/trans.dmp
******************************************************************************
Datafiles required for transportable tablespace TRANS:
  /opt/oracle/oradata/ORCLCDB/ORCLPDB1/trans.dbf
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at Tue Dec 24 18:31:58 2019 elapsed 0 00:03:31

# 元数据
$ ll /opt/oracle/admin/ORCLCDB/dpdump/974B2FC950D006CEE0530100007FB806/trans.dmp
-rw-r-----. 1 oracle oinstall 180224 Dec 24 18:31 /opt/oracle/admin/ORCLCDB/dpdump/974B2FC950D006CEE0530100007FB806/trans.dmp

# 数据
$ ll /opt/oracle/oradata/ORCLCDB/ORCLPDB1/trans.dbf
-rw-r-----. 1 oracle oinstall 10493952 Dec 24 18:24 /opt/oracle/oradata/ORCLCDB/ORCLPDB1/trans.dbf

以上导出使用system用户是为了避免转义,也可以用下面的命令:

$ expdp \"sys/Welcome1@orclpdb1 as sysdba\" dumpfile=trans_sys.dmp transport_tablespaces=trans

删除表空间,但保留数据文件:

drop tablespace trans including contents;

为使模拟更真实,将数据文件重命名并移动位置:

$ mv /opt/oracle/oradata/ORCLCDB/ORCLPDB1/trans.dbf /tmp/ts_trans.dbf

导入:

$ impdp system/Welcome1@orclpdb1 directory=data_pump_dir dumpfile=trans.dmp transport_datafiles='/tmp/ts_trans.dbf';

Import: Release 19.0.0.0.0 - Production on Tue Dec 24 18:47:25 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/********@orclpdb1 directory=data_pump_dir dumpfile=trans.dmp transport_datafiles=/tmp/ts_trans.dbf
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Tue Dec 24 18:47:39 2019 elapsed 0 00:00:11

将表空间置为读写并验证:

SQL> select tablespace_name, status from dba_tablespaces;

TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
DBFS_TS                        ONLINE
OBE_TBS1                       ONLINE
OBE_TBS2                       ONLINE
TRANS                          READ ONLY

9 rows selected.

SQL> alter tablespace trans read write;

Tablespace altered.

SQL> select count(*) from transtab;

  COUNT(*)
----------
        49
SQL> drop tablespace trans including contents and datafiles;

Tablespace dropped.

传输数据库

传输数据库和传输表空间类似,区别在于事先并没有目标数据库。大致过程为:

  1. 只读方式打开源数据库(之前必须正常关闭)
  2. 拷贝数据文件
  3. RMAN将数据文件转为目标平台格式,可以在源或目标端进行
  4. 在目标端启动新数据库实例
  5. 为实例生成控制文件
  6. RESETLOGS方式打开目标数据库
    以上步骤3-5可通过RMAN CONVERT命令实现。

生成数据库传输脚本示例:

-- 将源数据库置为只读
shutdown immediate;
startup mount;
alter database open read only;

生成转换脚本:

$ rlwrap rman target / catalog rcat_owner/Welcome1@rcat

Recovery Manager: Release 19.0.0.0.0 - Production on Tue Dec 24 19:47:36 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2795391422)
connected to recovery catalog database

RMAN> convert database on target platform convert script 'cnvt_linuxdb.sql' transport script 'crdb_linuxdb.sql' new database 'linuxdb' to platform 'Linux x86 64-bit' format '/tmp/%U';

Starting conversion at source at 24-DEC-19
starting full resync of recovery catalog
full resync complete
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=33 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=266 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=34 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=267 device type=DISK

External table SYS.OPATCH_XML_INV found in the database

Directory SYS.SDO_DIR_WORK found in the database
Directory SYS.SDO_DIR_ADMIN found in the database
Directory SYS.XMLDIR found in the database
Directory SYS.XSDDIR found in the database
Directory SYS.OPATCH_INST_DIR found in the database
Directory SYS.ORACLE_OCM_CONFIG_DIR2 found in the database
Directory SYS.ORACLE_BASE found in the database
Directory SYS.ORACLE_HOME found in the database
Directory SYS.ORACLE_OCM_CONFIG_DIR found in the database
Directory SYS.DATA_PUMP_DIR found in the database
Directory SYS.OPATCH_SCRIPT_DIR found in the database
Directory SYS.OPATCH_LOG_DIR found in the database
Directory SYS.JAVA$JOX$CUJS$DIRECTORY$ found in the database

User SYS with SYSDBA and SYSOPER privilege found in password file
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00004 name=/opt/oracle/oradata/ORCLCDB/undotbs01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00006 name=/opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00009 name=/opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00005 name=/opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00012 name=/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00014 name=/opt/oracle/product/19c/dbhome_1/dbs/obe_tbs1.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00015 name=/opt/oracle/product/19c/dbhome_1/dbs/obe_tbs2.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00008 name=/opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00011 name=/opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00007 name=/opt/oracle/oradata/ORCLCDB/users01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_1: starting to check datafiles
input datafile file number=00013 name=/u01/app/oracle/oradata/DB11G/dbfs01.dbf
channel ORA_DISK_1: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_2: starting to check datafiles
input datafile file number=00001 name=/opt/oracle/oradata/ORCLCDB/system01.dbf
channel ORA_DISK_2: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_3: starting to check datafiles
input datafile file number=00003 name=/opt/oracle/oradata/ORCLCDB/sysaux01.dbf
channel ORA_DISK_3: datafile checking complete, elapsed time: 00:00:00
channel ORA_DISK_4: starting to check datafiles
input datafile file number=00010 name=/opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf
channel ORA_DISK_4: datafile checking complete, elapsed time: 00:00:00
Edit init.ora file /tmp/init_00uk8ijq_1_0.ora. This PFILE will be used to create the database on the target platform
Run RMAN script /tmp/cnvt_linuxdb.sql on target platform to convert datafiles
Run SQL script /tmp/crdb_linuxdb.sql on the target platform to create database
To recompile all PL/SQL modules, run utlirp.sql and utlrp.sql on the target platform
To change the internal database identifier, use DBNEWID Utility
Finished conversion at source at 24-DEC-19

查看脚本:

$ cat /tmp/cnvt_linuxdb.sql
STARTUP NOMOUNT PFILE = '/tmp/init_00uk8ijq_1_0.ora';
RUN {
  CONVERT
  FROM PLATFORM 'Linux x86 64-bit'
  PARALLELISM 1
DATAFILE '/opt/oracle/oradata/ORCLCDB/undotbs01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-4_35uk8ijq'
DATAFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-6_36uk8ijq'
DATAFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-9_37uk8ijq'
DATAFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-5_38uk8ijq'
DATAFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-USERS_FNO-12_39uk8ijq'
DATAFILE '/opt/oracle/product/19c/dbhome_1/dbs/obe_tbs1.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-OBE_TBS1_FNO-14_3auk8ijr'
DATAFILE '/opt/oracle/product/19c/dbhome_1/dbs/obe_tbs2.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-OBE_TBS2_FNO-15_3buk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-8_3cuk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-11_3duk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/users01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-USERS_FNO-7_3euk8ijr'
DATAFILE '/u01/app/oracle/oradata/DB11G/dbfs01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-DBFS_TS_FNO-13_3fuk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/system01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-1_3guk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/sysaux01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-3_3huk8ijr'
DATAFILE '/opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf' FORMAT '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-10_3iuk8ijr'
; }

$ cat /tmp/crdb_linuxdb.sql
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT PFILE='/tmp/init_00uk8ijq_1_0.ora'
CREATE CONTROLFILE REUSE SET DATABASE "LINUXDB" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 (
    '/tmp/arch_D-LINUXDB_id-2795391422_S-25_T-1_A-2797767741_03uk8ijq',
    '/tmp/arch_D-LINUXDB_id-2795391422_S-25_T-1_A-2797767741_04uk8ijq'
  ) SIZE 200M BLOCKSIZE 512,
  GROUP 2 (
    '/tmp/arch_D-LINUXDB_id-2795391422_S-26_T-1_A-2797767741_05uk8ijq',
    '/tmp/arch_D-LINUXDB_id-2795391422_S-26_T-1_A-2797767741_06uk8ijq'
  ) SIZE 200M BLOCKSIZE 512,
  GROUP 3 (
    '/tmp/arch_D-LINUXDB_id-2795391422_S-24_T-1_A-2797767741_07uk8ijq',
    '/tmp/arch_D-LINUXDB_id-2795391422_S-24_T-1_A-2797767741_08uk8ijq'
  ) SIZE 200M BLOCKSIZE 512
DATAFILE
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-1_3guk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-3_3huk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-4_35uk8ijq',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-5_38uk8ijq',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-6_36uk8ijq',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-USERS_FNO-7_3euk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-8_3cuk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSTEM_FNO-9_37uk8ijq',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-SYSAUX_FNO-10_3iuk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-UNDOTBS1_FNO-11_3duk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-USERS_FNO-12_39uk8ijq',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-DBFS_TS_FNO-13_3fuk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-OBE_TBS1_FNO-14_3auk8ijr',
  '/tmp/data_D-ORCLCDB_I-2795391422_TS-OBE_TBS2_FNO-15_3buk8ijr'
CHARACTER SET AL32UTF8
;

-- Set Database Guard and/or Supplemental Logging
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS UPGRADE;

-- Open all the PDBs.
ALTER PLUGGABLE DATABASE ALL OPEN;

-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/tmp/data_D-LINUXDB_I-2795391422_TS-TEMP_FNO-1_09uk8ijq'
     SIZE 139460608  AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "PDB$SEED";
ALTER TABLESPACE TEMP ADD TEMPFILE '/tmp/data_D-LINUXDB_I-2795391422_TS-TEMP_FNO-2_0auk8ijq'
     SIZE 37748736  AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
ALTER SESSION SET CONTAINER = "ORCLPDB1";
ALTER TABLESPACE TEMP ADD TEMPFILE '/tmp/data_D-LINUXDB_I-2795391422_TS-TEMP_FNO-3_0buk8ijq' REUSE;
ALTER SESSION SET CONTAINER = "CDB$ROOT";
-- End of tempfile additions.
--

set echo off
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt * Your database has been created successfully!
prompt * There are many things to think about for the new database. Here
prompt * is a checklist to help you stay on track:
prompt * 1. You may want to redefine the location of the directory objects.
prompt * 2. You may want to change the internal database identifier (DBID)
prompt *    or the global database name for this database. Use the
prompt *    NEWDBID Utility (nid).
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SHUTDOWN IMMEDIATE
STARTUP UPGRADE PFILE='/tmp/init_00uk8ijq_1_0.ora'
@@ ?/rdbms/admin/utlirp.sql
SHUTDOWN IMMEDIATE
STARTUP PFILE='/tmp/init_00uk8ijq_1_0.ora'
-- The following step will recompile all PL/SQL modules.
-- It may take serveral hours to complete.
@@ ?/rdbms/admin/utlrp.sql
set feedback 6;

$ cat /tmp/init_00uk8ijq_1_0.ora
# Please change the values of the following parameters:

  control_files            = "/tmp/cf_D-LINUXDB_id-2795391422_01uk8ijq"

  db_recovery_file_dest    = "/tmp/fra"

  db_recovery_file_dest_size= 5368709120

  local_listener           = "LINUXDBLISTENER_ORCLCDB"

  audit_file_dest          = "/tmp/adump"

  db_name                  = "LINUXDB"



# Please review the values of the following parameters:

# __oracle_base            = "/opt/oracle"

  __shared_pool_size       = 503316480

  __large_pool_size        = 16777216

  __java_pool_size         = 0

  __streams_pool_size      = 33554432

  __unified_pga_pool_size  = 0

  __sga_target             = 1207959552

  __db_cache_size          = 570425344

  __shared_io_pool_size    = 67108864

  __data_transfer_cache_size= 0

  __inmemory_ext_rwarea    = 0

  __inmemory_ext_roarea    = 0

  remote_login_passwordfile= "EXCLUSIVE"

  dispatchers              = "(PROTOCOL=TCP) (SERVICE=ORCLCDBXDB)"

  __pga_aggregate_target   = 402653184



# The values of the following parameters are from source database:

  processes                = 300

  nls_language             = "AMERICAN"

  nls_territory            = "AMERICA"

  filesystemio_options     = "setall"

  sga_target               = 1207959552

  control_file_record_keep_time= 30

  db_block_size            = 8192

  compatible               = "19.0.0"

  undo_tablespace          = "UNDOTBS1"

  audit_sys_operations     = FALSE

  commit_wait              = "nowait"

  commit_logging           = "batch"

  audit_trail              = "NONE"

  open_cursors             = 300

  pga_aggregate_target     = 402653184

# diagnostic_dest          = "/opt/oracle"

  enable_pluggable_database= TRUE

缺个实验。

复制数据库

根据目标数据库的OS和字节序,可有多种方法复制数据库。可以依赖数据库备份或在线复制。recovery catalog虽不是必需,但可简化过程。术语上,源数据库称为target,复制数据库称为auxiliary。

使用复制数据库

复制数据库可用于测试备份和恢复,测试数据库升级,应用升级,生成报表。导出在源端不小心删除的表并倒回源数据库。

从活动的数据库复制

不需要备份,RMAN必须连接到target和auxiliary数据库。有push和pull两种方法。
push依赖于image copy,pull方法生成backupset。
通常,push方法需要目标端更多的资源,传输的数据更多。
大致过程如下:

  • 为auxiliary实例生成口令文件
  • 为auxiliary实例生成初始化参数文件
  • NOMOUNT模式启动auxiliary实例
  • 配置target和auxiliary之间的网络连接
  • 运行RMAN DUPLICATE命令

配置Auxiliary实例

Auxiliary实例参数文件通常需要的参数包括:

  • DB_NAME
  • CONTROL_FILES
  • DB_BLOCK_SIZE
  • DB_FILE_NAME_CONVERT
  • LOG_FILE_NAME_CONVERT
  • DB_CREATE_%_DEST
  • DB_RECOVERY_FILE_DEST

建立网络连接

target数据库通常已有监听。auxiliary需要单独的监听。两个数据库都需要TNS解析。

运行RMAN DUPLICATE命令

连接命令示例:

rman target sys/Welcome1@ORCL auxiliary sys/Welcome1@dupdb catalog rman/rman@rcat;
rman target / auxiliary sys/Welcome1@dupdb

复制命令示例:

duplicate target database to dupdb from active database;

以上命令依赖于满足以下条件之一:

  1. 使用OMF(Oracle Managed File)
  2. 设置了*_FILE_NAME_CONVERT参数
  3. 源和目标的目录结构相同

DUPLICATE命令包含的操作为:

  1. 创建controlfile
  2. 将数据文件从运行的target数据库拷贝到auxiliary实例
  3. 使用target数据库的online redo恢复auxiliary数据库
  4. RESETLOGS 模式打开auxiliary数据库
  5. 为auxiliary数据库生成新的DBID

具体还有一些选项,如跳过只读表空间,跳过指定表空间等

使用Backupsets在线复制

是pull方法。命令略。

从备份恢复

也就是不依赖于在线数据库。所有的数据文件和归档必须对auxiliary实例可见。
示例,假设源数据库为ORCLCDB,目标数据库为dupdb,源和目标数据库位于同一服务器:

# 口令文件
$ cp $ORACLE_HOME/dbs/orapwORCLCDB $ORACLE_HOME/dbs/orapwdupdb
# 初始化参数文件,多租户数据库必须将enable_pluggable_database设为true
cat <<-EOF > $ORACLE_HOME/dbs/initdupdb.ora
db_name=dupdb
enable_pluggable_database=true
db_file_name_convert='orclcdb', 'dupdb', 'ORCLCDB', 'DUPDB',  'db11g', 'dupdb', 'DB11G', 'DUPDB', 'dbs',  'db11g', 'DBS', 'DUPDB'
log_file_name_convert='orclcdb', 'dupdb', 'ORCLCDB', 'DUPDB', 'db11g', 'dupdb', 'DB11G', 'DUPDB', 'dbs',  'db11g', 'DBS', 'DUPDB'
EOF

启动auxiliary实例:

export ORACLE_SID=dupdb
sqlplus / as sysdba
create spfile from pfile;
startup nomount

将以下添加到listener.ora:

sid_list_listener=
(sid_list=
	(sid_desc=(sid_name=ORCLCDB))
	(sid_desc=(sid_name=dupdb))
)

将以下添加到tnsnames.ora:

ORCLCDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCLCDB)
    )
  )

dupdb =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dupdb)
    )
  )

测试两个数据库的连通性:

tnsping ORCLCDB
tnsping dupdb

通过RMAN连接到target和auxiliary数据库:

$ rman target sys/Welcome1@ORCLCDB auxiliary sys/Welcome1@dupdb catalog rcat_owner/Welcome1@rcat

Recovery Manager: Release 19.0.0.0.0 - Production on Tue Dec 24 21:21:32 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2795391422)
connected to recovery catalog database
connected to auxiliary database: DUPDB (not mounted)

复制数据库,21:51开始,57结束:

$ rman target sys/Welcome1@ORCLCDB auxiliary sys/Welcome1@dupdb catalog rcat_owner/Welcome1@rcat

Recovery Manager: Release 19.0.0.0.0 - Production on Tue Dec 24 21:51:20 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCLCDB (DBID=2795391422)
connected to recovery catalog database
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to dupdb from active database;

Starting Duplicate Db at 24-DEC-19
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=21 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=181 device type=DISK
allocated channel: ORA_AUX_DISK_3
channel ORA_AUX_DISK_3: SID=22 device type=DISK
allocated channel: ORA_AUX_DISK_4
channel ORA_AUX_DISK_4: SID=182 device type=DISK
current log archived

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCLCDB'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''dupdb'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone from service  'ORCLCDB' primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''ORCLCDB'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''dupdb'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     318767000 bytes

Fixed Size                     9133976 bytes
Variable Size                251658240 bytes
Database Buffers              50331648 bytes
Redo Buffers                   7643136 bytes

Starting restore at 24-DEC-19
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=178 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=20 device type=DISK
allocated channel: ORA_AUX_DISK_3
channel ORA_AUX_DISK_3: SID=179 device type=DISK
allocated channel: ORA_AUX_DISK_4
channel ORA_AUX_DISK_4: SID=21 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/product/19c/dbhome_1/dbs/cntrldupdb.dbf
Finished restore at 24-DEC-19

database mounted

contents of Memory Script:
{
   sql clone 'alter database flashback off';
   set newname for datafile  1 to
 "/opt/oracle/oradata/DUPDB/system01.dbf";
   set newname for datafile  3 to
 "/opt/oracle/oradata/DUPDB/sysaux01.dbf";
   set newname for datafile  4 to
 "/opt/oracle/oradata/DUPDB/undotbs01.dbf";
   set newname for datafile  5 to
 "/opt/oracle/oradata/DUPDB/pdbseed/system01.dbf";
   set newname for datafile  6 to
 "/opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf";
   set newname for datafile  7 to
 "/opt/oracle/oradata/DUPDB/users01.dbf";
   set newname for datafile  8 to
 "/opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf";
   set newname for datafile  9 to
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/system01.dbf";
   set newname for datafile  10 to
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf";
   set newname for datafile  11 to
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf";
   set newname for datafile  12 to
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf";
   set newname for datafile  13 to
 "/u01/app/oracle/oradata/DUPDB/dbfs01.dbf";
   set newname for datafile  14 to
 "/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf";
   set newname for datafile  15 to
 "/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf";
   restore
   from  nonsparse   from service
 'ORCLCDB'   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script

sql statement: alter database flashback off

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

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 24-DEC-19
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /opt/oracle/oradata/DUPDB/system01.dbf
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00003 to /opt/oracle/oradata/DUPDB/sysaux01.dbf
channel ORA_AUX_DISK_3: starting datafile backup set restore
channel ORA_AUX_DISK_3: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_3: restoring datafile 00004 to /opt/oracle/oradata/DUPDB/undotbs01.dbf
channel ORA_AUX_DISK_4: starting datafile backup set restore
channel ORA_AUX_DISK_4: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_4: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_4: restoring datafile 00005 to /opt/oracle/oradata/DUPDB/pdbseed/system01.dbf
channel ORA_AUX_DISK_3: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_3: starting datafile backup set restore
channel ORA_AUX_DISK_3: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_3: restoring datafile 00006 to /opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:44
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/DUPDB/users01.dbf
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:44
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00008 to /opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf
channel ORA_AUX_DISK_4: restore complete, elapsed time: 00:00:45
channel ORA_AUX_DISK_4: starting datafile backup set restore
channel ORA_AUX_DISK_4: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_4: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_4: restoring datafile 00009 to /opt/oracle/oradata/DUPDB/ORCLPDB1/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:38
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00011 to /opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf
channel ORA_AUX_DISK_3: restore complete, elapsed time: 00:01:06
channel ORA_AUX_DISK_3: starting datafile backup set restore
channel ORA_AUX_DISK_3: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_3: restoring datafile 00012 to /opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf
channel ORA_AUX_DISK_4: restore complete, elapsed time: 00:00:39
channel ORA_AUX_DISK_4: starting datafile backup set restore
channel ORA_AUX_DISK_4: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_4: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_4: restoring datafile 00013 to /u01/app/oracle/oradata/DUPDB/dbfs01.dbf
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:10
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00014 to /opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:10
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00015 to /opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf
channel ORA_AUX_DISK_3: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_4: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:34
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:18
Finished restore at 24-DEC-19

sql statement: alter system archive log current
current log archived

contents of Memory Script:
{
   restore clone force from service  'ORCLCDB'
           archivelog from scn  6668433;
   switch clone datafile all;
}
executing Memory Script

Starting restore at 24-DEC-19
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=29
channel ORA_AUX_DISK_2: starting archived log restore to default destination
channel ORA_AUX_DISK_2: using network backup set from service ORCLCDB
channel ORA_AUX_DISK_2: restoring archived log
archived log thread=1 sequence=30
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:00
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:01
Finished restore at 24-DEC-19

datafile 1 switched to datafile copy
input datafile copy RECID=30 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=31 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=32 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=33 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=34 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=35 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=36 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=37 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/system01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=38 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=39 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=40 STAMP=1027893282 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf
datafile 13 switched to datafile copy
input datafile copy RECID=41 STAMP=1027893282 file name=/u01/app/oracle/oradata/DUPDB/dbfs01.dbf
datafile 14 switched to datafile copy
input datafile copy RECID=42 STAMP=1027893282 file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf
datafile 15 switched to datafile copy
input datafile copy RECID=43 STAMP=1027893282 file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf

contents of Memory Script:
{
   set until scn  6668750;
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 24-DEC-19
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

starting media recovery

archived log for thread 1 with sequence 29 is already on disk as file /opt/oracle/product/19c/dbhome_1/dbs/arch1_29_1026687481.dbf
archived log for thread 1 with sequence 30 is already on disk as file /opt/oracle/product/19c/dbhome_1/dbs/arch1_30_1026687481.dbf
archived log file name=/opt/oracle/product/19c/dbhome_1/dbs/arch1_29_1026687481.dbf thread=1 sequence=29
archived log file name=/opt/oracle/product/19c/dbhome_1/dbs/arch1_30_1026687481.dbf thread=1 sequence=30
media recovery complete, elapsed time: 00:00:00
Finished recover at 24-DEC-19

contents of Memory Script:
{
   delete clone force archivelog all;
}
executing Memory Script

released channel: ORA_AUX_DISK_1
released channel: ORA_AUX_DISK_2
released channel: ORA_AUX_DISK_3
released channel: ORA_AUX_DISK_4
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=270 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=48 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=46 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=272 device type=DISK
deleted archived log
archived log file name=/opt/oracle/product/19c/dbhome_1/dbs/arch1_29_1026687481.dbf RECID=1 STAMP=1027893281
deleted archived log
archived log file name=/opt/oracle/product/19c/dbhome_1/dbs/arch1_30_1026687481.dbf RECID=2 STAMP=1027893281
Deleted 2 objects

Oracle instance started

Total System Global Area     318767000 bytes

Fixed Size                     9133976 bytes
Variable Size                251658240 bytes
Database Buffers              50331648 bytes
Redo Buffers                   7643136 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''DUPDB'' 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 =  ''DUPDB'' 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     318767000 bytes

Fixed Size                     9133976 bytes
Variable Size                251658240 bytes
Database Buffers              50331648 bytes
Redo Buffers                   7643136 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP     1 ( '/opt/oracle/oradata/DUPDB/redo01.log', '/opt/oracle/oradata/DUPDB/redo01_2.log' ) SIZE 200 M  REUSE,
  GROUP     2 ( '/opt/oracle/oradata/DUPDB/redo02_2.log', '/opt/oracle/oradata/DUPDB/redo02.log' ) SIZE 200 M  REUSE,
  GROUP     3 ( '/opt/oracle/oradata/DUPDB/redo03_2.log', '/opt/oracle/oradata/DUPDB/redo03.log' ) SIZE 200 M  REUSE
 DATAFILE
  '/opt/oracle/oradata/DUPDB/system01.dbf',
  '/opt/oracle/oradata/DUPDB/pdbseed/system01.dbf',
  '/opt/oracle/oradata/DUPDB/ORCLPDB1/system01.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/opt/oracle/oradata/DUPDB/temp01.dbf";
   set newname for tempfile  2 to
 "/opt/oracle/oradata/DUPDB/pdbseed/temp012019-11-14_16-12-14-765-PM.dbf";
   set newname for tempfile  3 to
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/opt/oracle/oradata/DUPDB/sysaux01.dbf",
 "/opt/oracle/oradata/DUPDB/undotbs01.dbf",
 "/opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf",
 "/opt/oracle/oradata/DUPDB/users01.dbf",
 "/opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf",
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf",
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf",
 "/opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf",
 "/u01/app/oracle/oradata/DUPDB/dbfs01.dbf",
 "/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf",
 "/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /opt/oracle/oradata/DUPDB/temp01.dbf in control file
renamed tempfile 2 to /opt/oracle/oradata/DUPDB/pdbseed/temp012019-11-14_16-12-14-765-PM.dbf in control file
renamed tempfile 3 to /opt/oracle/oradata/DUPDB/ORCLPDB1/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/sysaux01.dbf RECID=1 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/undotbs01.dbf RECID=2 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf RECID=3 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/users01.dbf RECID=4 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf RECID=5 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf RECID=6 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf RECID=7 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf RECID=8 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/DUPDB/dbfs01.dbf RECID=9 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf RECID=10 STAMP=1027893309
cataloged datafile copy
datafile copy file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf RECID=11 STAMP=1027893309

datafile 3 switched to datafile copy
input datafile copy RECID=1 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=2 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/undotbs01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=3 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=4 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=5 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/pdbseed/undotbs01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=6 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=7 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=8 STAMP=1027893309 file name=/opt/oracle/oradata/DUPDB/ORCLPDB1/users01.dbf
datafile 13 switched to datafile copy
input datafile copy RECID=9 STAMP=1027893309 file name=/u01/app/oracle/oradata/DUPDB/dbfs01.dbf
datafile 14 switched to datafile copy
input datafile copy RECID=10 STAMP=1027893309 file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs1.dbf
datafile 15 switched to datafile copy
input datafile copy RECID=11 STAMP=1027893309 file name=/opt/oracle/product/19c/dbhome_1/db11g/obe_tbs2.dbf
Reenabling controlfile options for auxiliary database
Executing: alter database add supplemental log data
Executing: alter database add supplemental log data(PRIMARY KEY) columns

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
Finished Duplicate Db at 24-DEC-19

验证:

$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Dec 24 21:58:40 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB1                       READ WRITE NO
SQL> select name from v$database;

NAME
---------
DUPDB

复制的数据库不会出现在/etc/oratab中。
最后删除复制的数据库,需要在/etc/oratab中手工添加条目才可以删除成功,否则报数据库不存在:

$ dbca -silent -deleteDatabase -sourceDB dupdb -sysPassword Welcome1

平安夜成功完成此测试。

你可能感兴趣的:(OCP,Oracle,12c,OCP,Duplicate,RMAN)