Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
78
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

316  Chapter 8  n  Performing Oracle Advanced Recovery

F i g u r e 8 .1   Example​ of an Oracle incarnation

D

Generate redo for new incarnation

 

C

B

Restore database

Restore

to 25000 and then

database

open resetlogs

SCN 20000

SCN 10000

SCN 40000

SCN 30000

A Database crashes

SCN

SCN

SCN

SCN

SCN

10000

20000

25000

30000

40000

Overview of RMAN Database Duplication

One frequent use of RMAN is to duplicate an existing database. Database duplication can be used for a number of different purposes, such as creating development and test databases from production databases or creating a database to test upgrades. In the following sections, we will discuss RMAN duplication basics. Then we will cover how to use the RMAN duplicate database command to duplicate a database. We will fist look at how to prepare to duplicate the database. We will then walk you through actually duplicating the database, and finally we will discuss things to do after.

RMAN Database Duplication Basics

The host from which the database is being duplicated is the source host. The host to which the database is being duplicated is called the destination host. The source host and destination host can be the same computer or a different computer, depending on your needs. One requirement is that the source and destination host must be on the same platform. The target or source database is the database that you will be duplicating from. You will be duplicating to a database instance that will be associated with the new database. This instance is called the auxiliary instance.

Overview of RMAN Database Duplication 

317

Two types of database duplication exist:

Active database duplication  ​  Active​ database duplication duplicates the live target database to the auxiliary instance over the network. As a result, no backup of the target database is required and the destination host need not have access to the RMAN backup set pieces.

Backup-based database duplication  ​  ​Backup-based database duplication requires that a backup of the database being duplicated be available. This backup can be an RMAN backup set or image copy. The target host must have access to these backup sets in order to complete the database duplication.

Database duplication takes place over what is called the auxiliary channel. This channel is created during the duplication process and is a server process associated with the auxiliary instance.

When you connect to RMAN to start a database duplication, you will connect to both the target database and the auxiliary instance. This implies that network connectivity to the auxiliary instance is available, and as you will see, getting the auxiliary instance up and running is one prerequisite to starting a database-duplication operation.

Performing an RMAN Database Duplication

Duplicating a database is an operation that many DBAs find themselves doing. RMAN provides the duplicate database command to help ease the database-duplication process.

Preparing to Duplicate Your Database

Preparing to duplicate your database requires a few steps:

1.Backing up the target database (backup-based database duplication only)

2.Making backup images available to the destination host (backup-based database duplication only)

3.Deciding where to put the duplicate-database-related files

4.Preparing the auxiliary instance for the duplication

Let’s look at each of these steps in more detail next.

Backing up the target database is not required if you are using active database duplication. If you are doing backup-based duplication, you will need a complete backup of the target database. Follow the steps outlined in Chapter 3 to perform an RMAN backup of your database. The database can be in NOARCHIVELOG or ARCHIVELOG mode.

Making backup images available to the destination host is not required if you are using active database duplication. If you are doing backup-based duplication, you will need to make the backup set pieces associated with the backup of the target database, and all associated archived redo logs, available to the destination host. This is so they can be read by RMAN during the duplication process. You can make everything available to the destination host by

318  Chapter 8  n  Performing Oracle Advanced Recovery

putting the backup set pieces on shared devices (such as Network File System, or NFS) or some other shared disk environment. You could also manually copy the needed files to the destination host via Secure File Transfer Protocol (SFTP) or some equivalent file-copy protocol.

You will need to decide where you want to put the database files that will be associated with the newly duplicated database. Files like the control files, the online redo logs, and the database datafiles need a home, and you have to know where that will be before you start the duplication process. In the next step, you will use this information to configure the auxiliary instance for duplication.

Before you can begin the duplication process, you must configure the auxiliary instance so that it will start. To do so, follow these steps:

Step 1: Configure any OS-specific requirements.  ​  ​Different operating systems require that certain prerequisites be completed before you can start a database instance. For example, in Windows you must create the Windows service, and in most Unix flavors you will need to configure shared memory. You will need to make sure that these preconfiguration steps are complete before you can start the auxiliary instance and begin the duplication process.

Step 2: Configure the database password file for the auxiliary instance.  ​  The​ auxiliary instance will require a password file. Use the orapwd command (see Chapter 3 for more on orapwd) to create the password file. If you prefer, you can instruct Oracle to copy the password file from the target database to the duplicated database when you issue the duplication command.

Step 3: Configure Oracle networking for the auxiliary instance.  ​  ​If you will be executing the duplicate command from a host other than the destination host, or if you are going to use active database duplication, you will have to configure Oracle networking so that you can connect to the auxiliary instance via Oracle Net. You can use the Oracle Net Configuration Assistant to configure both the database listener and the tnsnames.ora file for naming resolution.

Step 4: Configure the database parameter file for the auxiliary instance.  ​  Configuring​ the database parameter file correctly can make for successful database duplication. Incorrectly configuring the parameter file can make for a frustrating exercise in futility. The parameter file must be configured to be able to start the auxiliary instance. The parameters listed in Table 8.1 are available for use during the database-duplication process. You may not need to use all of the parameters listed in Table 8.1 when duplicating databases. In some cases these parameters can also be defined on the RMAN command line as parameters of the duplication command.

Step 5: Start the auxiliary instance.  ​  ​The auxiliary instance should be ready to start at this time. To start it, simply connect to the auxiliary instance from SQL*Plus and issue the startup nomount command. Once you have been able to get the auxiliary instance started, you are ready to duplicate to it.

Overview of RMAN Database Duplication 

319

Ta b l e 8 .1   Auxiliary​ Database Parameters Related to Database Duplication

Parameter Name

Purpose

 

 

DB_NAME

The name of the duplicated database. This same name

 

will be used in the RMAN duplicate command. This name

 

should be unique for databases on a given host. This param-

 

eter is a required parameter for any database duplication.

CONTROL_FILES

Identifies the location of the control files for the auxiliary

 

instance. This parameter is required unless you are using OMF.

DB_BLOCK_SIZE

Block size of the database to be created. This parameter

 

is required if the same parameter has been defined on the

 

source database.

DB_FILE_NAME_CONVERT

Contains pairs of strings that indicate the conversion path

 

for database files from the source database to the target

 

database. For example, if the parameter were set to ’/ora01/

 

oracle/oradata’,’/ora02/oracle/oradata’, all files con-

 

tained in /ora01/oracle/oradata would be re-created on the

 

duplicate database in /ora02/oracle/oradata.

 

This parameter can also be defined as part of the call to the

 

RMAN duplicate command.

LOG_FILE_NAME_CONVERT

Contains pairs of strings that indicate the conversion path for

 

database redo-log files from the source database to the target

 

database. For example, if the parameter were set to ’/ora01/

 

oracle/oradata’,’/ora02/oracle/oradata’, all online redo-

 

log files contained in /ora01/oracle/oradata would be re-

 

created on the duplicate database in /ora02/oracle/oradata.

This parameter can also be defined as part of the call to the RMAN duplicate command.

Duplicating Your Database

As mentioned previously, there are two different modes of database duplication. They are active database duplication and backup-based database duplication. Both duplication methods are achieved via the use of the duplicate database command. Let’s look at the duplicate database command in more detail. Following that we will look at both database-duplication modes in more detail.

Connecting to RMAN for a Database Duplication

Before starting database duplication, you will need to start RMAN and connect to the correct databases. When starting RMAN, you will need to connect to the following:

NN

The target database

NN

The auxiliary database

320  Chapter 8  n  Performing Oracle Advanced Recovery

Typically you will connect to the target database locally and connect to the auxiliary database via Oracle Net, but this is not a requirement. Here is an example of connecting to RMAN to perform a database duplication. In this example, we are connecting to a local target database called orcl. We use the auxiliary command-line parameter to indicate that we are connecting to an auxiliary database. In this case, it is the database pointed to by the net service name of mydb.

set oracle_sid=orcl

rman target=/ auxiliary=sys/password@mydb

You could also use these variations to connect with RMAN for a database duplication:

rman target=sys/robert auxiliary=sys/password@mydb rman target=sys/robert@orcl auxiliary=sys/password@mydb

You might have noticed that we don’t use SYSDBA when connecting to RMAN. That is because all connections from RMAN to any database are always with SYSDBA privileges.

The RMAN duplicate database Command

The RMAN duplicate database command is used when performing either mode of database duplication. The command comes with a number of different options that give you ability to complete the following operations:

NN

Copy the source spfile to the auxiliary instance.

 

NN

Change specific parameters when copying a source spfile to the auxiliary instance.

NNIndicate the location that the duplicated files should be copied to using the database filename conversion options DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT.

NN

Create a stand-by database environment on the auxiliary instance.

 

NN

Open the duplicated database in a restricted session.

NNUse the password file from the target database to create the password file on the auxiliary instance (active database duplication only).

NN

Skip read-only tablespaces.

 

NN

Include or exclude specific tablespaces.

NNRestore to a specific restore point or use the until clause to restore to a specific time, SCN, or log sequence number (backup-based database duplication only).

During the duplication process, RMAN will automatically create the needed tempfiles for any temporary tablespaces. Here is an example of the RMAN duplication command:

Duplicate target database to neworcl nofilenamecheck spfile;

Overview of RMAN Database Duplication 

321

The duplicate command comes with a number of options, including the ability to exclude tablespaces, as shown here:

Duplicate target database to neworcl nofilenamecheck spfile skip tablespace users;

You can also define a restore point, as seen in this example:

Duplicate target database to neworcl nofilenamecheck spfile skip tablespace users to restore point ’Test’;

You can have Oracle open the duplicated database in restricted mode by adding the open restricted parameter, as shown here:

Duplicate target database to neworcl nofilenamecheck spfile open restricted;

As with pretty much everything else Oracle, the duplicate command is well documented. We strongly recommend that you review the Oracle Database Backup and Recovery Reference (Oracle part number B28273-02) for more information on all RMAN-related commands.

Active Database Duplication

Active database duplication is started by issuing the RMAN duplicate database command and including the from active database parameter. Active database duplication is not the default.

When you perform active database duplication, Oracle will create the auxiliary channel to the auxiliary database. An additional target-database RMAN channel will also be required. If you have configured automated channels, this should be sufficient. If not, you will need to allocate a channel manually with the allocate channel command.

Finally, the until and to restore point clauses are not valid when doing an active database duplication. Here is an example of the RMAN duplicate command performing an active database duplication:

duplicate target database to neworcl from active database nofilenamecheck spfile set control_files ‘c:\oracle\oradata\neworcl\control01.ctl’, ‘c:\oracle\oradata\neworcl\control02.ctl’

set db_file_name_convert ’c:\oracle\oradata\orcl’,’c:\oracle\oradata\neworcl’ set log_file_name_convert ’c:\oracle\oradata\orcl’,’c:\oracle\oradata\neworcl’;

Backup-Based Database Duplication

Using the duplicate database command without the from active database parameter starts backup-based database duplication. The auxiliary channel will be allocated automatically. No additional channel is required with backup-based database duplication.

322  Chapter 8  n  Performing Oracle Advanced Recovery

When executing a backup-based database duplication, RMAN will determine the last archived redo log available. RMAN will then restore the duplicate database to the point of that last available archived redo log by default. You can use the until or to restore point parameter to change this behavior. Here is an example of the RMAN duplicate command performing a backup-based database duplication:

duplicate target database to neworcl spfile

set control_files ‘c:\oracle\oradata\neworcl\control01.ctl’, ‘c:\oracle\oradata\neworcl\control02.ctl’

set db_file_name_convert ’c:\oracle\oradata\orcl’,’c:\oracle\oradata\neworcl’ set log_file_name_convert ’c:\oracle\oradata\orcl’, ’c:\oracle\oradata\neworcl’;

After the Duplication

Once the database duplication is complete, the duplicated database will be opened and operational. You can use the restricted session parameter of the duplicate command to indicate that RMAN should open the database in a restricted session only. You should, of course, consider backing up the newly created database on a regular basis.

In Exercise 8.1, you’ll be duplicating a database using backup-based database duplication.

E x e r c i s e 8 .1

Duplicating a Database Using Backup-Based Duplication

In this exercise, you will use backup-based duplication to create a database on the same system that the target database resides on. For this exercise, your database should be running in ARCHIVELOG mode and all networking to the target database should be already configured.

1.Back up your database as shown in Exercise 4.2.

2.Start RMAN and confirm that you have a valid backup with the list backup of database summary command and with the restore database validate command. Note that your output will likely look very different from ours.

C:\Documents and Settings\Robert>rman target=/ Recovery Manager: Release 11.1.0.6.0 - Production on Sat Oct 4 22:56:10 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1194923408) RMAN> list backup of database summary;

Overview of RMAN Database Duplication 

323

E x e r c i s e 8 .1   ( c o n t i n u e d )

using target database control file instead of recovery catalog

List of Backups

 

 

 

 

 

===============

 

 

 

 

 

Key

TY LV S

Device Type Completion Time #Pieces

#Copies Compressed

------- -- -- -

----------- --------------- -------

------- ----------

Tag

 

 

 

 

 

 

---

 

 

 

 

 

 

2

B F A

DISK

03-OCT-08

1

1

YES

TAG20081003T135426

RMAN> restore database validate; Starting restore at 04-OCT-08 allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=127 device type=DISK

channel ORA_DISK_1: starting validation of datafile backup set

channel ORA_DISK_1: reading from backup piece C:\ORACLE\FLASH_RECOVERY_AREA\ ORCL\BACKUPSET\2008_10_03

\O1_MF_NNNDF_TAG20081003T135426_4GDY3S9H_.BKP

channel ORA_DISK_1: piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORCL\ BACKUPSET\2008_10_03

\O1_MF_NNNDF_TAG20081003T135426_4GDY3S9H_.BKP tag=TAG20081003T135426 channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: validation complete, elapsed time: 00:01:36 Finished restore at 04-OCT-08

C:\Documents and Settings\Robert>set oracle_sid=orcl

3.If you are running in Windows, create the service for the new database with oradim. In this example, you are creating a new database instance called neworcl:

C:\>oradim -new -sid neworcl Instance created.

If there are any other OS-specific operations required to create a database instance, complete them now.

4.Create the password file for the neworcl instance:

C:\>orapwd file=c:\oracle\product\11.1.0\db_1\database\pwdneworcl.ora Enter password for SYS:

324  Chapter 8  n  Performing Oracle Advanced Recovery

E x e r c i s e 8 .1   ( c o n t i n u e d )

5.Create a temporary pfile for the neworcl auxiliary instance using your editor of choice. The pfile should be contained in the ORACLE_HOME\database directory of the auxiliary instance and should be named initneworcl.ora. The pfile should have these parameters in it:

db_name=neworcl memory_target=300m

control_files=’c:\oracle\oradata\neworcl\control01.ctl’, ‘c:\oracle\oradata\neworcl\control02.ctl’

We will do the actual file-location conversions during the duplication.

6.Create the directory c:\oracle\oradata\neworcl: mkdir c:\oracle\oradata\neworcl

7.Start up the auxiliary instance:

C:\oracle\product\11.1.0\db_1\database>set oracle_sid=neworcl C:\oracle\product\11.1.0\db_1\database>sqlplus “/ as sysdba” SQL*Plus: Release 11.1.0.6.0 - Production on Sat Oct 4 23:09:52 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to an idle instance.

 

SQL> startup nomount

 

 

ORACLE instance started.

 

 

Total System Global Area

313860096

bytes

Fixed Size

1332892

bytes

Variable Size

192940388

bytes

Database Buffers

113246208

bytes

Redo Buffers

6340608

bytes

8.Configure service name resolution for your new auxiliary database. The method of this configuration will vary based on your site. In our case, we created an entry in the tnsnames.ora file on our server that looked like this:

NEWORCL = (DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.2)(PORT = 1521)) (CONNECT_DATA =

(SERVER = DEDICATED) (SERVICE_NAME = neworcl)

) )

Overview of RMAN Database Duplication 

325

E x e r c i s e 8 .1   ( c o n t i n u e d )

9.Now you will need to hard-code the instance name into the listener.ora file until the duplication of the database has been completed. You will get network errors if you do not hard-code the auxiliary instance in the listener.ora file. An example of the entry in our listener.ora is as follows:

SID_LIST_LISTENER = (SID_LIST = (SID_DESC =

(ORACLE_HOME=C:\oracle\product\11.1.0\db_1\NETWORK\ADMIN) (SID_NAME=neworcl)

) )

LISTENER = (DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.2)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

) )

10.Test the network connectivity to the auxiliary instance:

C:\>sqlplus sys/robert@neworcl as sysdba

SQL*Plus: Release 11.1.0.6.0 - Production on Sat Oct 4 23:17:50 2008 Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining and

Real Application Testing options

SQL> select instance_name from v$instance; INSTANCE_NAME

----------------

neworcl

If the connection fails, review the network configuration and ensure that the new auxiliary instance is running.

11.Start RMAN, connecting to the target and the auxiliary databases:

C:\oracle\product\11.1.0\db_1\database>Set oracle_sid=orcl

C:\oracle\product\11.1.0\db_1\database>Rman target=/ auxiliary=sys/Robert@ neworcl

326  Chapter 8  n  Performing Oracle Advanced Recovery

E x e r c i s e 8 .1   ( c o n t i n u e d )

Recovery Manager: Release 11.1.0.6.0 - Production on Sat Oct 4 23:19:55 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: ORCL (DBID=1194923408) connected to auxiliary database: NEWORCL (not mounted)

12.You are now ready to start the database duplication. Issue the duplicate database command, as shown here:

duplicate target database to neworcl nofilenamecheck spfile set control_files= ‘c:\oracle\oradata\neworcl\control01.ctl’, ‘c:\oracle\oradata\neworcl\control02.ctl’

set db_file_name_convert ’c:\oracle\oradata\orcl’, ’c:\oracle\oradata\neworcl’

set log_file_name_convert ’c:\oracle\oradata\orcl’, ’c:\oracle\oradata\neworcl’;

This command does the following:

NNIt starts the duplication process.

NNThe spfile parameter will result in the target database spfile being copied over to the duplicate database. The duplicate database will use this spfile.

NNThe set commands (set control_files, set db_file_name_convert, and set log_file_name_convert) modify or add parameters to the spfile being copied to the duplicate database.

This duplicate command will result in a great deal of output, which we have decided not to include here as it seems a great waste of a perfectly good tree. Here is the output that you hopefully will see at the end of the database duplication:

database opened

Finished Duplicate Db at 04-OCT-08

13.Connect to the duplicated database to verify it is open:

C:\oracle\product\11.1.0\db_1\database>set oracle_sid=neworcl C:\oracle\product\11.1.0\db_1\database>sqlplus sys/Robert as sysdba SQL*Plus: Release 11.1.0.6.0 - Production on Sun Oct 5 00:04:02 2008

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]