Archive for April 16, 2013

1. Identify and copy the database files

With the source database started, identify all of the database’s files. The following query will display all datafiles, tempfiles and redo logs:

 

set lines 100 pages 999

col name format a50

select name, bytes

from (select name, bytes

from v$datafile

union all

select name, bytes

from v$tempfile

union all

select lf.member “name”, l.bytes

from v$logfile lf

, v$log l

where lf.group# = l.group#) used

, (select sum(bytes) as poo

from dba_free_space) free

/

 

OR

SQL>Select name from v$datafile;

SQL>Select member from v$logfile;

Make sure that the clone databases file-system is large enough and has all necessary directories.

If the source database has a complex file structure, you might want to consider modifying the

above sql to produce a file copy script.

Stop the source database with:

SQL>shutdown immediate

Copy, scp or ftp the files from the source database/machine to the target.

Do not copy the control files across. Make sure that the files have the correct permissions and ownership.

Start the source database up again

SQL> startup

 

2. Produce a pfile for the new database

This step assumes that you are using a spfile. If you are not, just copy the existing pfile.

 

From sqlplus:

SQL> create pfile=’init<new database sid>.ora’ from spfile;

This will create a new pfile in the $ORACLE_HOME/dbs directory.

Once created, the new pfile will need to be edited. If the cloned database is to have a new name,

this will need to be changed, as will any paths. Review the contents of the file and make

alterations as necessary.

Also think about adjusting memory parameters. If you are cloning a production database onto

a slower development machine you might want to consider reducing some values.

Now open the parameter file in clone database and change the following parameters with the respective current location.

CONTROL FILES

BACKGROUND_DUMP_DEST

USER_DUMP_DEST

CORE_DUMP_DEST

LOG_ARCHIVE_DEST_1

And Place the clone_DB(new DB) pfile on /$ORACLE_HOME/dbs

Note. Pay particular attention to the control locations.

  

3. In original database generate CREATECONTROLFILE statement by typing the following command.

SQL>alter database backup controlfile to trace;

This will create a trace file containing the “CREATE CONTROLFILE” command to recreate the controlfile in text form.

4. Now, go to the USER_DUMP_DEST directory on the original Database server and open the latest trace file.The trace file will have the form “ora_NNNN.trc with NNNN being a number. This file will contain steps and as well as CREATE CONTROLFILE statement. Copy the CREATE CONTROLFILE statement and paste it in a notepad.

Edit the file

FROM: CREATE CONTROLFILE REUSE DATABASE olddbname” RESETLOGS … 

  TO: CREATE CONTROLFILE set DATABASE “newdbname”  RESETLOGS … 

Change the word ‘REUSE’ to ‘set’ and the ‘olddbname’ to ‘newdbname’. Also change the datafiles location parameter to clone database location.

5. Create the necessary directory on the clone database (destination database) server on your desired location.

 

Example :- mkdir udump adump cdump bdump arch

 

udump – user dump destination

bdump – background dump destination

adump – audit dump destination

cdump – core dump destination

arch – Archive log destination

6. Now copy the pfile from the original database server to the clone database server and placed it under the $ORACLE_HOME/dbs location. Now open the parameter file in clone database and change the following parameters with the respective current location.

 

CONTROL FILES
BACKGROUND_DUMP_DEST
USER_DUMP_DEST
CORE_DUMP_DEST
LOG_ARCHIVE_DEST_1

7. In clone database SERVER export ORACLE_SID environment variable and start the instance

$export ORACLE_SID= Clone DB name

$sqlplus

Enter User:/ as sysdba

SQL> startup nomount pfile=’initNEWDB_NAME.ora’;

8. Run create controlfile script to create the controlfile

SQL>@createcontrolfile.sql

9. Trouble shoot:

It is quite common to run into problems at this stage. Here are a couple of common errors and solutions:

  • ORA-01113: file 1 needs media recoveryYou probably forgot to stop the source database before copying the files.

Go back to step 1 and recopy the files.

  • ORA-01503: CREATE CONTROLFILE failed

          ORA-00200: controlfile could not be created

          ORA-00202: controlfile: ‘/u03/oradata/dg9a/control01.ctl’

          ORA-27038: skgfrcre: file exists

Double check the pfile created in step 2. Make sure the control_files setting

is pointing at the correct location. If the control_file setting is ok, make sure that the control

files were not copied with the rest of the database files. If they were, delete or rename them.

 

10. Open the database

SQL>alter database open;

11. Perform a few checks

If the last step went smoothly, the database should be open.

It is advisable to perform a few checks at this point:

Check that the database has opened with:

SQL> select status from v$instance;

The status should be ‘OPEN’

Make sure that the datafiles are all ok:

SQL> select distinct status from v$datafile;

It should return only ONLINE and SYSTEM.

Take a quick look at the alert log too.

 

12. Set the databases global name

The new database will still have the source databases global name. Run the following to reset it:

SQL> alter database rename global_name to <new database sid>

/

13. Create a spfile

From sqlplus:

SQL> create spfile from pfile;

14. Change the database ID

If RMAN is going to be used to back-up the database, the database ID must be changed.

If RMAN isn’t going to be used, there is no harm in changing the ID anyway – and it’s a good practice to do so.

From sqlplus:

SQL> shutdown immediate

SQL> startup mount

exit

From unix:

$ nid target=/

NID will ask if you want to change the ID. Respond with ‘Y’. Once it has finished, start the database up again in sqlplus:

SQL> shutdown immediate

SQL> startup mount

SQL> alter database open resetlogs

/

15. Configure TNS

Add entries for new database in the listener.ora and tnsnames.ora as necessary.

16. Finished

That’s it!

Oracle 10g Enable Read Write On Physical Standby Database.

On Standby

Enable Flashback Database.

SQL> show parameter db_recovery

Code:

NAME TYPE VALUE

———————- ———– ———————————–

db_recovery_file_dest string /u01/app/oracle/flash_recovery_area

db_recovery_file_dest_size big integer 2G

SQL> alter system set db_recovery_file_dest_size=6g;

System altered.

SQL> alter system set db_flashback_retention_target=1440;

System altered.

Retention period is 24 hours.

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
———-
MOUNTED

Prepare standby for read write.

Cancel Redo apply.

SQL> alter database recover managed standby database cancel;

Database altered.

Create a restore point named before_open_standby

SQL> create restore point before_open_standby guarantee
flashback database;

Restore point created.

SQL> select scn,storage_size,time, name from v$restore_point;

Code:

SCN STORAGE_SIZE TIME NAME

—— ———— —————————— ——————-

486759 8192000 19-JAN-12 06.37.39.000000000 AM BEFORE_OPEN_STANDBY
SQL>

On Primary

SQL> alter system archive log current;

System altered.

Stop Remote Archive shipping since we are not going to
use it.

SQL> alter system set log_archive_dest_state_2=defer;

System altered.

SQL> alter system switch logfile;

System altered.

On Standby

SQL> alter database activate standby database;

Database altered.

Skip the next statement. if the standby was not opened read-only
since the instance was last started.

SQL> startup mount force;

Switch to maximum performance mode.

SQL> alter database set standby database to maximize performance;

Database altered.

SQL> alter database open;

Database altered.

Stop remote redo shipping if any on standby.

SQL> alter system set log_archive_dest_state_2 = defer;

System altered.

—————————————————————-

Taking back the Standby Database to its original state.

SQL> startup mount force;
ORACLE instance started.

Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Database mounted.

SQL> flashback database to restore point before_open_standby;

Flashback complete.

SQL> alter database convert to physical standby;

Database altered.

SQL> startup mount force;
ORACLE instance started.

Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 92276304 bytes
Database Buffers 188743680 bytes
Redo Buffers 2973696 bytes
Database mounted.

SQL> drop restore point before_open_standby;

Restore point dropped.

SQL> alter system set log_archive_dest_state_2=enable scope=both;

System altered.

SQL> alter database recover managed standby database disconnect
from session;

Database altered.

All the gaps in the archive logs should be automatically applied
because of the FAL_SERVER and FAL_CLIENT parameters.

If that does not work and your database is too far behind,
then make incremental backup on primary and apply it to standby.

On Primary

SQL> alter system set log_archive_dest_state_2 = enable scope=both;

System altered.