You can use RMAN to create a duplicate database on the same server by using RMAN backups.
For my example, the target database is STATTAR, and the duplicate is STATDUP.
The OS is linux x86_64 and the oracle version is 11.2.0.1.
1. Ensure that STATTAR is in archivelog mode, otherwise convert it.
2. Enable the logging mode
3. do a complete backup of STATTAR
export ORACLE_SID=STATTAR
rman target /
RMAN> backup database plus archivelog;
4. tnsnames
STATDUP =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = STATDUP)
)
)
5. listner
(SID_DESC =
(GLOBAL_DBNAME = STATDUP)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = STATDUP)
)
6. create the directories for data, controlfile and redo log files
mkdir -p /u01/app/oracle/admin/STATDUP/adump
mkdir -p /u01/app/oracle/admin/STATDUP/dpdump
mkdir -p /u01/app/oracle/admin/STATDUP/pfile
mkdir -p /u01/app/oracle/admin/STATDUP/scripts
mkdir -p /u02/oracle/oradata/STATDUP/controlfile/
mkdir -p /u03/oracle/oradata/STATDUP/controlfile/
mkdir -p /u04/oracle/oradata/STATDUP/controlfile/
mkdir -p /u02/oracle/oradata/STATDUP/data_system
mkdir -p /u02/oracle/oradata/STATTAR/data
mkdir -p /u02/oracle/oradata/STATDUP/data
mkdir -p /u03/oracle/oradata/STATDUP/data
mkdir -p /u04/oracle/oradata/STATDUP/data
mkdir -p /u02/oracle/oradata/STATDUP/redo
mkdir -p /u03/oracle/oradata/STATDUP/redo
mkdir -p /u04/oracle/oradata/STATDUP/redo
7. create pfile
db_name=STATDUP
db_block_size=8192
compatible='11.2.0.0.0'
remote_login_passwordfile=exclusive
control_files = ('/u02/oracle/oradata/STATDUP/controlfile/control01.ctl',
'/u03/oracle/oradata/STATDUP/controlfile/control01.ctl',
'/u04/oracle/oradata/STATDUP/controlfile/control01.ctl')
db_file_name_convert = ('/u02/oracle/oradata/STATTAR/data_system',
'/u02/oracle/oradata/STATDUP/data_system',
'/u02/oracle/oradata/STATTAR/data',
'/u02/oracle/oradata/STATDUP/data',
'/u03/oracle/oradata/STATTAR/data',
'/u03/oracle/oradata/STATDUP/data',
'/u04/oracle/oradata/STATTAR/data',
'/u04/oracle/oradata/STATDUP/data'
)
log_file_name_convert = ('/u02/oracle/oradata/STATTAR/redo',
'/u02/oracle/oradata/STATDUP/redo',
'/u03/oracle/oradata/STATTAR/redo',
'/u03/oracle/oradata/STATDUP/redo',
'/u04/oracle/oradata/STATTAR/redo',
'/u04/oracle/oradata/STATDUP/redo'
)
8. create pwdfile : the same as the target DB
orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwSTATDUP password=<syspwd>
9. startup STATDUP in nomount mode
export ORACLE_SID=STATDUP
sqlplus / as sysdba
SQL> startup nomount pfile='/u01/app/oracle/admin/STATDUP/pfile/STATDUP_init.ora';
10. duplicate the target DB
export ORACLE_SID=STATDUP
rman target sys/<syspwd>@STATTAR auxiliary/
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 6 10:46:38 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: STATTAR (DBID=2026*****)
connected to auxiliary database: STATDUP (not mounted)
RMAN > duplicate target database to STATDUP;
Starting Duplicate Db at 06-MAR-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=57 device type=DISK
contents of Memory Script:
{
sql clone "create spfile from memory";
}
executing Memory Script
sql statement: create spfile from memory
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 233861120 bytes
Fixed Size 2212088 bytes
Variable Size 159387400 bytes
Database Buffers 67108864 bytes
Redo Buffers 5152768 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''STATTAR'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''STATDUP'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''STATTAR'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''STATDUP'' comment= ''Modified by RMAN duplicate'' scope=spfile
.....
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 06-MAR-12
exit;
For my example, the target database is STATTAR, and the duplicate is STATDUP.
The OS is linux x86_64 and the oracle version is 11.2.0.1.
1. Ensure that STATTAR is in archivelog mode, otherwise convert it.
2. Enable the logging mode
SQL> ALTER DATABASE FORCE LOGGING;
3. do a complete backup of STATTAR
export ORACLE_SID=STATTAR
rman target /
RMAN> backup database plus archivelog;
4. tnsnames
STATDUP =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = STATDUP)
)
)
5. listner
(SID_DESC =
(GLOBAL_DBNAME = STATDUP)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = STATDUP)
)
6. create the directories for data, controlfile and redo log files
mkdir -p /u01/app/oracle/admin/STATDUP/adump
mkdir -p /u01/app/oracle/admin/STATDUP/dpdump
mkdir -p /u01/app/oracle/admin/STATDUP/pfile
mkdir -p /u01/app/oracle/admin/STATDUP/scripts
mkdir -p /u02/oracle/oradata/STATDUP/controlfile/
mkdir -p /u03/oracle/oradata/STATDUP/controlfile/
mkdir -p /u04/oracle/oradata/STATDUP/controlfile/
mkdir -p /u02/oracle/oradata/STATDUP/data_system
mkdir -p /u02/oracle/oradata/STATTAR/data
mkdir -p /u02/oracle/oradata/STATDUP/data
mkdir -p /u03/oracle/oradata/STATDUP/data
mkdir -p /u04/oracle/oradata/STATDUP/data
mkdir -p /u02/oracle/oradata/STATDUP/redo
mkdir -p /u03/oracle/oradata/STATDUP/redo
mkdir -p /u04/oracle/oradata/STATDUP/redo
7. create pfile
db_name=STATDUP
db_block_size=8192
compatible='11.2.0.0.0'
remote_login_passwordfile=exclusive
control_files = ('/u02/oracle/oradata/STATDUP/controlfile/control01.ctl',
'/u03/oracle/oradata/STATDUP/controlfile/control01.ctl',
'/u04/oracle/oradata/STATDUP/controlfile/control01.ctl')
db_file_name_convert = ('/u02/oracle/oradata/STATTAR/data_system',
'/u02/oracle/oradata/STATDUP/data_system',
'/u02/oracle/oradata/STATTAR/data',
'/u02/oracle/oradata/STATDUP/data',
'/u03/oracle/oradata/STATTAR/data',
'/u03/oracle/oradata/STATDUP/data',
'/u04/oracle/oradata/STATTAR/data',
'/u04/oracle/oradata/STATDUP/data'
)
log_file_name_convert = ('/u02/oracle/oradata/STATTAR/redo',
'/u02/oracle/oradata/STATDUP/redo',
'/u03/oracle/oradata/STATTAR/redo',
'/u03/oracle/oradata/STATDUP/redo',
'/u04/oracle/oradata/STATTAR/redo',
'/u04/oracle/oradata/STATDUP/redo'
)
8. create pwdfile : the same as the target DB
orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwSTATDUP password=<syspwd>
9. startup STATDUP in nomount mode
export ORACLE_SID=STATDUP
sqlplus / as sysdba
SQL> startup nomount pfile='/u01/app/oracle/admin/STATDUP/pfile/STATDUP_init.ora';
10. duplicate the target DB
export ORACLE_SID=STATDUP
rman target sys/<syspwd>@STATTAR auxiliary/
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 6 10:46:38 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: STATTAR (DBID=2026*****)
connected to auxiliary database: STATDUP (not mounted)
RMAN > duplicate target database to STATDUP;
Starting Duplicate Db at 06-MAR-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=57 device type=DISK
contents of Memory Script:
{
sql clone "create spfile from memory";
}
executing Memory Script
sql statement: create spfile from memory
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 233861120 bytes
Fixed Size 2212088 bytes
Variable Size 159387400 bytes
Database Buffers 67108864 bytes
Redo Buffers 5152768 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''STATTAR'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''STATDUP'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile;
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''STATTAR'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''STATDUP'' comment= ''Modified by RMAN duplicate'' scope=spfile
.....
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 06-MAR-12
exit;
Excellent details...Thanks so much!
RépondreSupprimer