Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

DBA2 - Backup-Based Duplicate Database

Back


Backup-Based Duplicate Database Overview


Creating an Initialization Parameter File for the Auxiliary Instance


Specifying New Names for Your Destination


Using the SET NEWNAME Clauses

RUN {
    SET NEWNAME FOR DATABASE TO '/uOl/app/oracle/oradata/dupldb/%b';
    DUPLICATE TARGET DATABASE TO dupldb
    LOGFILE
    GROUP 1 ('/u0l/app/oracle/oradata/dupldb/redo0Ola.log', '/u0l/app/oracle/oradata/dupldb/redo0lb.log') SIZE 50M REUSE,
    GROUP 2 ('/u0l/app/oracle/oradata/dupldb/redo02a.log', '/u0l/app/oracle/oradata/dupldb/redo02b.log') SIZE 50M REUSE,
    GROUP 3 ('/u0l/app/oracle/oradata/dupldb/redo03a.log"', '/u0l/app/oracle/oradata/dupldb/redo03b.log') SIZE 50M REUSE;
}

Substitution Variables for SET NEWNAME

Syntax Element Description
%b Specifies the file name without the directory path *NEW*
%f Specifies the absolute file number of the data file for which the new name is generated
%I Specifies the DBID
%N Specifies the tablespace name
%U Specifies a system-generated file name of the format: data-D-%d_id-%I_TS-%N_FNO-%f
-- The example shows the SET NEWNAME FOR TABLESPACE command to set default names with a substitution variable, together with explicit SET NEWNAME clauses.
RUN
{
    SET NEWNAME FOR DATAFILE 1 TO '/oradatal/system0l.dbf';
    SET NEWNAME FOR DATAFILE 2 TO '/oradata2/sysaux0l.dbf';
    SET NEWNAME FOR DATAFILE 3 TO '/oradata3/undotbs0l.dbf';
    SET NEWNAME FOR DATAFILE 4 TO '/oradatad/usersOl.dbf';
    SET NEWNAME FOR TABLESPACE example TO '/oradata5/%b'; --

    DUPLICATE TARGET DATABASE TO dupldb;
  }

Specifying Parameters for File Naming

CONTROL_FILES='/u0l/app/oracle/oradata/aux/control0l.ctl"', '/u0l/app/oracle/oradata/aux/control02.ctl', '/u0l/app/oracle/oradata/aux/control03.ctl'

DB_FILE NAME CONVERT='/u0l/app/oracle/oradata/orcl','/u0l/app/oracle/oradata/aux'

LOG_FILE_NAME CONVERT='/u0l/app/oracle/oradata/orcl','/u0l/app/oracle/oradata/aux'

Starting the Instance in NOMOUNT Mode

-- start up nomount
startup nomount pfile='$HOME/auxinstance/initAUX.ora'

create spfile from pfile='$HOME/auxinstance/initAUX.ora';

Ensuring That Backups and Archived Redo Log Files Are Available


Allocating Auxiliary Channels

rman target sys@trgt auxiliary sys@auxdb
RUN
{
    -- multiple channel
    ALLOCATE AUXILIARY CHANNEL auxl DEVICE TYPE DISK;
    ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK;
    DUPLICATE TARGET DATABASE to auxdb;
    -- ...
}

RMAN Duplication Operation


Specifying Options for the DUPLICATE Command

Option Purpose
SKIP READONLY Excludes read-only tablespaces
SKIP TABLESPACE Excludes named tablespaces
TABLESPACE Includes named tablespaces
NOFILENAMECHECK Prevents checking of file names
OPEN RESTRICTED Enables RESTRICTED SESSION automatically
NOOPEN Leaves duplicate database in MOUNT mode
NOREDO Signals RMAN that the application of redo logs should be suppressed during recovery
UNDO TABLESPACE Must be specified when target database is not open and there is no recovery catalog connection

Duplicating Selected PDBs in a CDB

-- duplicate a single PDB
DUPLICATE DATABASE TO cdbl
PLUGGABLE DATABASE pdbl;

-- duplicate a set of PDBs
DUPLICATE DATABASE TO cdbl
PLUGGABLE DATABASE pdbl, pdb3;

-- duplicate all the databases in the CDB, except a PDB
DUPLICATE DATABASE TO cdbl
SKIP PLUGGABLE DATABASE pdb3;

-- duplicate a PDB and tablespaces of other PDBs
DUPLICATE DATABASE TO cdbl
PLUGGABLE DATABASE pdbl TABLESPACE pdb2:users;

Cloning an Active PDB into an Existing CDB


Example: Duplicating PDB1 from CDB1 to CDB2 as PDB1

example_backup_dup

  1. Set the REMOTE_RECOVERY_FILE_DEST initialization parameter in CDB2.
ALTER SYSTEM
SET REMOTE_RECOVERY_FILE_DEST='/dir_to_restore_archive log files';
  1. Connect to the source (TARGET for DUPLICATE command): CDB1
CONNECT TARGET "sys@cdbl AS SYSDBA"
  1. Connect to the existing CDB2 that acts as the auxiliary instance
    • CDB2 needs to be opened in read/write mode.
CONNECT AUXILIARY "sys@cdb2 AS SYSDBA"
  1. Start the duplication.
    • the source PDB1 is opened.
DUPLICATE PLUGGABLE DATABASE pdbl TO cdb2 FROM ACTIVE DATABASE;

Example: Duplicating PDB1 from CDB1 to CDB2 as PDB2

  1. Set the REMOTE_RECOVERY_FILE_DEST initialization parameter in CDB2.
ALTER SYSTEM SET REMOTE_RECOVERY_ FILE DEST='/dir_to_restore_archive log files';
  1. Connect to the source (TARGET for DUPLICATE command): CDB1
CONNECT TARGET "sys@cdb1 AS SYSDBA"
  1. Connect to the existing CDR2 that acts as the auxiliary instance:
    • CDB2 needs to be opened in read/write mode.
CONNECT AUXILIARY "sys@cdb2 AS SYSDBA"
  1. Start the duplication.
    • the source PDB1 is opened.
DUPLICATE PLUGGABLE DATABASE pdbl AS pdb2 TO cdb2 FROM ACTIVE DATABASE;

Lab: Duplicating a Database


Configuration for Duplicated Database

-- create dir for df of dbtest database
mkdir -p /u01/app/oracle/oradata/dbtest

-- create dir for fra of dbtest database
mkdir -p /u01/app/oracle/dbtest_fra

-- create dir for cdb in dbtest'fra
mkdir -p /u01/app/oracle/dbtest_fra/orclcdb
# Launch the Oracle Net Manager utility.
netmgr

lab_duplicate_db lab_duplicate_db lab_duplicate_db lab_duplicate_db

lab_duplicate_db

cat $ORACLE_HOME/network/admin/tnsnames.ora
# reload listener
lsnrctl reload

# check listener status
lsnrctl status

. oraenv

# ORACLE_SID = [orclcdb] ? dbtest
# ORACLE HOME = [/home/oracle] ? /u01/app/oracle/product/19.0.0/dbhome_1
orapwd file=$ORACLE_HOME/dbs/orapwdbtest entries=15
# welcome!23

ls $ORACLE_HOME/dbs/*pwdbtest*
-- create spfile
vi $ORACLE_HOME/dbs/initdbtest.ora
# db_name=dbtest
# remote_login_passwordfile=exclusive

-- confirm
cat $ORACLE_HOME/dbs/initdbtest.ora

sqlplus / as sysdba

startup NOMOUNT pfile='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initdbtest.ora'

exit

-- confirm: show how many instance is running by smon
pgrep -lfa smon

. oraenv
-- ORACLE_SID = [dbtest] ? orcl

sqlplus / as sysdba

-- confirm compatible
show parameter compatible

-- Confirm your backup location and size.
show parameter db_recover

-- confirm archive log mode
ARCHIVE LOG LIST
rman target sys@orcl auxiliary sys@dbtest
DUPLICATE TARGET DATABASE TO dbtest FROM ACTIVE DATABASE
SPFILE PARAMETER_VALUE_CONVERT
'/u01/app/oracle/oradata/ORCL', '/u01/app/oracle/oradata/dbtest',
'/u01/app/oracle/fast_recovery_area','/u01/app/oracle/dbtest_fra',
'ORCL', 'DBTEST'
SET DB_RECOVERY_FILE_DEST_SIZE='10G'
SET DB_FILE_NAME_CONVERT='ORCL', 'DBTEST';

. oraenv

# ORACLE_SID = [orclcdb] ? dbtest
# ORACLE HOME = [/home/oracle] ? /u01/app/oracle/product/19.0.0/dbhome_1

sqlplus / as sysdba

-- get cdb
SELECT NAME, CDB, CON_ID FROM V$DATABASE;

-- get db and mode
select dbid, name, created, open_mode from v$database;

-- list pdb
show pdbs

Lab: Duplicating a PDB into an Existing CDB

. oraenv
-- ORACLE_SID = [dbtest] ? orcl
sqlplus hr@ORCLPDB

SELECT * FROM regions;

exit
# Create dir to Set the initialization parameter `REMOTE_RECOVERY_FILE_DEST` to restore foreign archive logs.
mkdir -p /home/oracle/labs/fra

# Create the directory for the new PDB data files.
mkdir -p /u01/app/oracle/oradata/DBTEST/dbtestpdb1
. oraenv
-- ORACLE_SID = [dbtest] ? dbtest
-- ORACLE HOME = [/home/oracle] ? /u01/app/oracle/product/19.0.0/dbhome_1

sqlplus / AS SYSDBA

ALTER SYSTEM SET
REMOTE_RECOVERY_FILE_DEST='/home/oracle/labs/fra'
SCOPE=BOTH;

EXIT
rman

-- connect target
CONNECT TARGET sys@ORCL

-- Connect to the auxiliary instance DBTEST into which you will duplicate ORCLPDE1 as DBTESTPDBI.
CONNECT AUXILIARY sys@DBTEST

-- duplicate a pdb
DUPLICATE PLUGGABLE DATABASE orclpdb AS dbtestpdb1
FROM ACTIVE DATABASE
DB_FILE_NAME_CONVERT
('/u01/app/oracle/oradata/ORCL/orclpdb/', '/u01/app/oracle/oradata/DBTEST/dbtestpdb1/');

exit
sqlplus / AS SYSDBA

SHOW PDBS

ALTER SESSION SET CONTAINER=DBTESTPDB1;
SELECT * FROM hr.regions;

EXIT

Clean up

rman TARGET "'sys@dbtest AS sysdba'"

STARTUP FORCE MOUNT
ALTER SYSTEM ENABLE RESTRICTED SESSION;
DROP DATABASE INCLUDING BACKUPS NOPROMPT;
vi /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora

vi /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/tnsnames.ora

lsnrctl reload
lsnrctl status
rm -rf /home/oracle/labs/fra
rm -rf /u01/app/oracle/oradata/dbtest
rm -rf /u01/app/oracle/dbtest_fra

TOP