Step-by-step RAC Cloning with ASM

Assumtion: Source Server: svloradb1, DB: SVLDB, SID: SVLDB1, SVLDB2, port: 1521

Target Server: svloradb2, DB: SVLSTDBY, SID: SVLSTDBY1, SVLSTDBY2, port: 1521

1) Ensure that you have latest backup taken at the source database

export ORACLE_SID=SVLDB1
export NLS_LANG=american
export NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'
Make a note of the finish time. This time required later.
Finished backup Aug 15 2011 23:00:32 (make sure to capture archivelog finish time)


RMAN> run {
 allocate channel ch1 type disk;
 backup database format '/home/oracle/rman_bkup/full_hot_bkup_%t_%s_%d';
 backup current controlfile format '/home/oracle/rman_bkup/ctrl_bkup_%t_%s_%d';
 sql 'alter system archive log current';
 backup archivelog all format '/home/oracle/rman_bkup/arch_bkup_%s_%t_%d';
 release channel ch1;
 }

Above backup shuld be available at the target server at the same location as source.

2)Make sure you create a backup directory on both source and target for rman

/home/oracle/rman_bkup

3) Create and copy tnsnames entry of target to the source

the following is the tnsnames.ora entry of target that i am copying it to the source.

SVLSTANDBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = svloradb2-vip.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = SVLSTDBY)
      (INSTANCE_NAME = SVLSTDBY1)
    )
  )

4) Create Listener on the target server

LISTENER_SVLORADB2 =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = svloradb2-vip.localdomain)(PORT = 1522)(IP = FIRST))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.75)(PORT = 1522)(IP = FIRST))
    )
  )

SID_LIST_LISTENER_SVLORADB2 =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = SVLSTDBY)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = SVLSTDBY1)
    )
  )
5) Start Listener on the target server

LSNRCTL START LISTENER_SVLORADB2

7) Create pfile on Source server and copy it over to target

sqlplus "/as sysdba"
SQL> create pfile='/tmp/initSVLSTDBY.ora' from spfile;
File created.
scp /tmp/initSVLSTANDBY.ora 192.168.1.75:$ORACLE_HOME/dbs

Go to target server and perform following:
a) Change the db name for target server (SVLDB to SVLSTANDBY in my case)
simply vi to initSVLSTDBY file and
:%s///g

b) Remove/uncomment RAC specific parameters i.e.
*.cluster_database_instances=1
*.cluster_database=true
#SVLSTDBY.instance_number=1
#SVLSTDBY.thread=1
#SVLSTDBY.undo_tablespace='UNDOTBS1'
#*.remote_listener='LISTENERS_SVLSTDBY'

sample initSVLSTDBY.ora file
----------------------------------
SVLSTDBY1.__db_cache_size=180355072
SVLSTDBY1.__java_pool_size=4194304
SVLSTDBY1.__large_pool_size=4194304
SVLSTDBY1.__shared_pool_size=92274688
SVLSTDBY1.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/SVLSTDBY/adump'
*.background_dump_dest='/u01/app/oracle/admin/SVLSTDBY/bdump'
#*.cluster_database_instances=1
#*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='+DATA/SVLSTDBY/controlfile/current.256.758671835','+DATA/SVLSTDBY/controlfile/current.257.758671837'
*.core_dump_dest='/u01/app/oracle/admin/SVLSTANDBY/cdump'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain='STANDBY'
*.db_file_multiblock_read_count=16
*.db_name='SVLSTDBY'
*.db_recovery_file_dest='+DATA'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=SVLSTDBYXDB)'
*.db_file_name_convert='+DATA/SVLDB/', '+DATA/SVLSTDBY/'
*.log_file_name_convert='+DATA/SVLDB/','+DATA/SVLSTDBY/'
#SVLSTDBY.instance_number=1
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
#*.remote_listener='LISTENERS_SVLSTDBY'
*.remote_login_passwordfile='exclusive'
*.sga_target=285212672
#SVLDB1.thread=1
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
#SVLSTDBY.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/SVLSTDBY/udump'

c) Create following directory
/u01/app/oracle/admin/SVLSTDBY/adump
/u01/app/oracle/admin/SVLSTDBY/bdump
/u01/app/oracle/admin/SVLSTDBY/cdump
/u01/app/oracle/admin/SVLSTDBY/udump

[oracle]$ export ORACLE_SID=+ASM1
[oracle]$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
[oracle]$ asmcmd
ASMCMD> lsdg
State    Type    Rebal  Unbal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Name
MOUNTED  EXTERN  N      N         512   4096  1048576    823953   430321                0          430321              0  DATA/
MOUNTED  EXTERN  N      N         512   4096  1048576    394342   112542                0          112542              0  FLASH/

ASMCMD> cd data
ASMCMD> mkdir SVLSTDBY
ASMCMD> cd SVLSTDBY
ASMCMD> mkdir PARAMETERFILE
ASMCMD> mkdir DATAFILE
ASMCMD> mkdir TEMPFILE
ASMCMD> mkdir ARCHIVELOG
ASMCMD> mkdir CONTROLFILE
ASMCMD> mkdir ONLINELOG
ASMCMD> mkdir STANDBYLOG
ASMCMD> mkdir dgbroker
ASMCMD> pwd
+data/SVLSTDBY
ASMCMD> ls
PARAMETERFILE/
DATAFILE/
TEMPFILE/
ARCHIVELOG/
CONTROLFILE/
ONLINELOG/
STANDBYLOG/
dgbroker/

Create the Same Directories under the FLASH diskgroup.


d) Changing ASM Disk Group:
Since I am moving from DATA/FRA diskgroup to DATA/FRA diskgroup I don't have to use covert file_name parameters.

e) Edit /etc/oratab file, add database entry

SVLSTDBY:/u01/app/oracle/product/10.2.0/db_1:N

f) Copy password file from source to target.
scp oracle@source_server:/u01/app/oracle/product/10.2.0/db_1/orapwSOURCEDB /u01/app/oracle/product/10.2.0/db_1/orapwTARGETDB

8) Start the target database in nomount mode
sqlplus  / as sysdba

create spfile from pfile;

startup nomount

exit
9) Start listener at the target server
lsnrctl start LISTENER_SVLORADB2

10) Check the connection from source to target

From source server test the connection to the target database using the command:

sqlplus sys/password@TARGETDB_CLONE as sysdba

11) Duplicate Database now

export ORACLE_SID=SVLSTDBY1
export NLS_LANG=american
export NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'

rman target sys@ catalog rman/password@ auxiliary sys@
rman target sys@SVLDB catalog rman/rman@RMN1 auxiliary sys@SVLSTDBY

[oracle@svloradb2 rman_bkup]$ rman target sys@SVLDB catalog rman/rman@RMN1 auxiliary sys@SVLSTANDBY

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Aug 15 00:50:55 2011

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

target database Password:
connected to target database: SVLDB (DBID=2180978007)
connected to recovery catalog database
auxiliary database Password:
connected to auxiliary database: SVLSTDBY (not mounted)

RMAN>



run {
allocate auxiliary channel ch1 type disk;
allocate auxiliary channel ch2 type disk;
SET UNTIL TIME 'Aug 15 2011 23:00:32';
duplicate target database to SVLSTDBY;
}



Issue while running RMAN duplicate:
RMAN-06136: ORACLE error from auxiliary database: ORA-01503: CREATE CONTROLFILE failed
ORA-01276: Cannot add file +DATA/svldb/controlfile/current.256.758671835.  File has an Oracle Managed Files file name.

solution-1
--------------
ORA-01276: Cannot add file string. File has an Oracle Managed Files file name.
Cause: An attempt was made to add to the database a datafile, log file, control file, snapshot control file, backup control file, datafile copy, control file copy or backuppiece with an Oracle Managed Files file name.
Action: Retry the operation with a new file name.

The second one is the root error. The problem here is that when you try to create a tablespace by means of an ASM instance which is 
managed by OMF you cannot give a name to the datafiles, it is a paradox, you cannot manage a file that is oracle managed, but you want 
to recreate it using the definition provided by the export file.

The workaround here is to manually create it, letting asm to give a name to it.

solution-2
-------------------
LOG_FILE_NAME_CONVERT=(‘SOURCE_DB_STORAGE’,'CLONE_DB_STORAGE’)
DB_FILE_NAME_CONVERT=(‘SOURCE_DB_STORAGE’,'CLONE_DB_STORAGE’)

LOG_FILE_NAME_CONVERT=('+DATA/svldb','+DATA/svlstdby')
DB_FILE_NAME_CONVERT=('+DATA/svldb','+DATA/svlstdby')

Issue was resolved by trying out the following:
a)db_file and log_file convert method.
b) changing controlfile name
 
Register the clone database and the database instances with the Oracle Cluster Registry (OCR)
============================================================================================
 
$ srvctl add database -d SVLSTDBY -o /u01/app/oracle/product/10.2.0/db_1
$ srvctl add instance -d SVLSTDBY -i SVLSTDBY1 -n svloradb2
 
Register the ASM instance with the OCR:
$ srvctl add asm -n svloradb2 -i +ASM1 -o /u01/app/oracle/product/10.2.0/db_1 -p /u01/app/oracle/product/10.2.0/db_1/dbs/spfile+ASM1.ora
# $ srvctl add asm -n standby_host2 -i +ASM2 -o /u01/app/oracle/product/10.2.0/db_1 –p /u01/app/oracle/product/10.2.0/db_1/dbs/spfile+ASM2.ora

Establish the dependency between the database instance and the ASM instance.
$ srvctl modify instance -d SVLSTDBY -i SVLSTDBY1 -s +ASM1
#$ srvctl modify instance –d SVLSTDBY –i SVLSTDBY2 –s +ASM2
$ srvctl enable asm -n svloradb2 -i +ASM1
#$ srvctl enable asm -n standby_host2 -i +ASM2

Start ASM
$ srvctl start asm -n svloradb2
Start Database:

srvctl start database -d SVLSTDBY

[oracle@svloradb2 dbs]$ /u01/crs/oracle/product/10.2.0/crs/bin/crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora....Y1.inst application    ONLINE    ONLINE    svloradb2
ora....TDBY.db application    ONLINE    ONLINE    svloradb2
ora....SM1.asm application    ONLINE    ONLINE    svloradb2
ora....B2.lsnr application    ONLINE    ONLINE    svloradb2
ora....db2.gsd application    ONLINE    ONLINE    svloradb2
ora....db2.ons application    ONLINE    ONLINE    svloradb2
ora....db2.vip application    ONLINE    ONLINE    svloradb2

Success cloning/duplicate log:
=========================================
[oracle@svloradb2 dbs]$ rman target sys@SVLDB catalog rman/rman@RMN1 auxiliary sys@SVLSTDBY

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Aug 15 23:13:41 2011

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

target database Password:
connected to target database: SVLDB (DBID=2180978007)
connected to recovery catalog database
auxiliary database Password:
connected to auxiliary database: SVLSTDBY (not mounted)

RMAN> run {
allocate auxiliary channel ch1 type disk;
allocate auxiliary channel ch2 type disk;
SET UNTIL TIME 'Aug 15 2011 23:00:32';
duplicate target database to SVLSTDBY;
}2> 3> 4> 5> 6>

allocated channel: ch1
channel ch1: sid=153 devtype=DISK

allocated channel: ch2
channel ch2: sid=152 devtype=DISK

executing command: SET until clause

Starting Duplicate Db at Aug 15 2011 23:14:08

contents of Memory Script:
{
   set until scn  881005;
   set newname for datafile  1 to
 "+DATA/svlstdby/datafile/system.264.758671851";
   set newname for datafile  2 to
 "+DATA/svlstdby/datafile/undotbs1.265.758671869";
   set newname for datafile  3 to
 "+DATA/svlstdby/datafile/sysaux.266.758671873";
   set newname for datafile  4 to
 "+DATA/svlstdby/datafile/users.268.758671889";
   restore
   check readonly
   clone database
   ;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at Aug 15 2011 23:14:09

channel ch1: starting datafile backupset restore
channel ch1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to +DATA/svlstdby/datafile/system.264.758671851
restoring datafile 00002 to +DATA/svlstdby/datafile/undotbs1.265.758671869
restoring datafile 00003 to +DATA/svlstdby/datafile/sysaux.266.758671873
restoring datafile 00004 to +DATA/svlstdby/datafile/users.268.758671889
channel ch1: reading from backup piece /home/oracle/rman_bkup/full_hot_bkup_759279484_16_SVLDB
channel ch1: restored backup piece 1
piece handle=/home/oracle/rman_bkup/full_hot_bkup_759279484_16_SVLDB tag=TAG20110815T225803
channel ch1: restore complete, elapsed time: 00:01:27
Finished restore at Aug 15 2011 23:15:39
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SVLSTDBY" RESETLOGS ARCHIVELOG
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DATA/svlstdby/onlinelog/group_1.258.758671839', '+DATA/svlstdby/onlinelog/group_1.259.758671839' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DATA/svlstdby/onlinelog/group_2.260.758671841', '+DATA/svlstdby/onlinelog/group_2.261.758671845' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DATA/svlstdby/onlinelog/group_3.262.758671845', '+DATA/svlstdby/onlinelog/group_3.263.758671847' ) SIZE 50 M  REUSE
 DATAFILE
  '+DATA/svlstdby/datafile/system.261.759280455'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=759280542 filename=+DATA/svlstdby/datafile/undotbs1.259.759280455
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=759280542 filename=+DATA/svlstdby/datafile/sysaux.260.759280455
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=759280542 filename=+DATA/svlstdby/datafile/users.258.759280455

contents of Memory Script:
{
   set until time  "Aug 15 2011 23:00:32";
   recover
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at Aug 15 2011 23:15:42

starting media recovery

channel ch1: starting archive log restore to default destination
channel ch1: restoring archive log
archive log thread=1 sequence=40
channel ch1: reading from backup piece /home/oracle/rman_bkup/arch_bkup_19_759279636_SVLDB
channel ch1: restored backup piece 1
piece handle=/home/oracle/rman_bkup/arch_bkup_19_759279636_SVLDB tag=TAG20110815T230035
channel ch1: restore complete, elapsed time: 00:00:02
archive log filename=+DATA/svlstdby/archivelog/2011_08_15/thread_1_seq_40.262.759280547 thread=1 sequence=40
channel clone_default: deleting archive log(s)
archive log filename=+DATA/svlstdby/archivelog/2011_08_15/thread_1_seq_40.262.759280547 recid=1 stamp=759280547
media recovery complete, elapsed time: 00:00:02
Finished recover at Aug 15 2011 23:15:49

contents of Memory Script:
{
   shutdown clone;
   startup clone nomount ;
}
executing Memory Script

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     285212672 bytes

Fixed Size                     1218992 bytes
Variable Size                121636432 bytes
Database Buffers             159383552 bytes
Redo Buffers                   2973696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "SVLSTDBY" RESETLOGS ARCHIVELOG
  MAXLOGFILES    192
  MAXLOGMEMBERS      3
  MAXDATAFILES     1024
  MAXINSTANCES    32
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '+DATA/svlstdby/onlinelog/group_1.258.758671839', '+DATA/svlstdby/onlinelog/group_1.259.758671839' ) SIZE 50 M  REUSE,
  GROUP  2 ( '+DATA/svlstdby/onlinelog/group_2.260.758671841', '+DATA/svlstdby/onlinelog/group_2.261.758671845' ) SIZE 50 M  REUSE,
  GROUP  3 ( '+DATA/svlstdby/onlinelog/group_3.262.758671845', '+DATA/svlstdby/onlinelog/group_3.263.758671847' ) SIZE 50 M  REUSE
 DATAFILE
  '+DATA/svlstdby/datafile/system.261.759280455'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to
 "+DATA/svlstdby/tempfile/temp.267.758671881";
   switch clone tempfile all;
   catalog clone datafilecopy  "+DATA/svlstdby/datafile/undotbs1.259.759280455";
   catalog clone datafilecopy  "+DATA/svlstdby/datafile/sysaux.260.759280455";
   catalog clone datafilecopy  "+DATA/svlstdby/datafile/users.258.759280455";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to +DATA/svlstdby/tempfile/temp.267.758671881 in control file

cataloged datafile copy
datafile copy filename=+DATA/svlstdby/datafile/undotbs1.259.759280455 recid=1 stamp=759280571

cataloged datafile copy
datafile copy filename=+DATA/svlstdby/datafile/sysaux.260.759280455 recid=2 stamp=759280571

cataloged datafile copy
datafile copy filename=+DATA/svlstdby/datafile/users.258.759280455 recid=3 stamp=759280571

datafile 2 switched to datafile copy
input datafile copy recid=1 stamp=759280571 filename=+DATA/svlstdby/datafile/undotbs1.259.759280455
datafile 3 switched to datafile copy
input datafile copy recid=2 stamp=759280571 filename=+DATA/svlstdby/datafile/sysaux.260.759280455
datafile 4 switched to datafile copy
input datafile copy recid=3 stamp=759280571 filename=+DATA/svlstdby/datafile/users.258.759280455

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at Aug 15 2011 23:17:15

RMAN>


INSTANCE_NAME    HOST_NAME                                                        STARTUP_TIME         STATUS
---------------- ---------------------------------------------------------------- -------------------- ------------
SVLSTDBY1        svloradb2.localdomain                                            Aug 15 2011 23:16:02 OPEN

uncomment RAC Specific parameters and and start the database:

*.cluster_database_instances=1
*.cluster_database=true
#SVLSTDBY.instance_number=1
#SVLSTDBY.thread=1
#SVLSTDBY.undo_tablespace='UNDOTBS1'
#*.remote_listener='LISTENERS_SVLSTDBY'

END of cloning RAC Database with ASM option step_by_step method.

Logical Volume Manager

# Using the whole secondary-slave IDE hard disk for existing LVM volume group (called vg0 in my case) by creating the physical volume (PV):
# pvcreate /dev/sdb1 /dev/sdc1

A similar message of this will be shown upon successful execution of pvcreate command:
pvcreate — physical volume “/dev/hdd” successfully created

Creating volume group !
# vgcreate vg1 /dev/sdb1 /dev/sdc1 
 
Create the new logical volume (LV) at 400MB (not fully utilize the whole IDE hard disk) to host the new EXT3 file system in question:
# lvcreate -L 10G -n my_log_vol01 vg1
# lvcreate -L 10G -n my_log_vol02 vg1
lvcreate completed successfully, this similar message will be seen:

lvcreate — doing automatic backup of “vg1″
lvcreate — logical volume “/dev/vg0/lvol1″ successfully created
 
Now, create the new EXT3 file system on the new logical volume (LV) with 1% file system reserved block count:
# mkfs -t ext3 -m 1 -v /dev/vg1/my_log_vol01
# mkfs -t ext3 -m 1 -v /dev/vg1/my_log_vol02


Once the new EXT3 file system creation completed, you can examine the file system by executing

tune2fs -l /dev/vg1/my_log_vol02
 
# Create a mount point directory for the new EXT3 file system:
mkdir -p /opt/oracle
 
It’s now ready to mount the new EXT3 file system:
# mount -t ext3 /dev/vg1/my_log_vol01 /opt/oracle

To confirm that the new EXT3 file system has been mounted successful, type df -h

Register disk with fdisk command
# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
#

Step-by-step Cold Backup

STEP 1: while source db is online do the following:
 -create backup of controlfile to trace
 “alter database backup controlfile to trace”. 
 -create pfile from spfile
 SQL>create pfile from spfile
and push above two to target destination i.e. at $ORACLE_HOME/dbs directory.

STEP 2: Shutdown the source database


STEP 3: Copy all data files into the new directories on the new server. 
You may change the file names if you want, but you must edit the controlfile to reflect the new data files 
names on the new server.

    scp /u01/oradata/trgtdb/* newhost:/u01/oradata/dupdb
    scp /u01/oradata/trgtdb/* newhost:/u01/oradata/dupdb
    scp /u03/oradata/trgtdb/* newhost:/u03/oradata/dupdb
    scp /u04/oradata/trgtdb/* newhost:/u04/oradata/dupdb


STEP 4: start the source db:
STEP 5: Copy and Edit the Control file – Using the output syntax from STEP 1, modify the controlfile 
creation script by changing the following:
This will put the create database syntax in the trace file directory. 
The trace keyword tells oracle to generate a script containing a create controlfile command and 
store it in the trace directory identified in the user_dump_dest parameter of the init.ora file. 
It will look something like this:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "PROD" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/PROD/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/PROD/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/PROD/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/PROD/system01.dbf',
  '/u01/app/oracle/oradata/PROD/undotbs01.dbf',
  '/u01/app/oracle/oradata/PROD/sysaux01.dbf',
  '/u01/app/oracle/oradata/PROD/users01.dbf',
  '/u01/app/oracle/oradata/PROD/example01.dbf',
  '/u01/app/oracle/oradata/PROD/testtbs.dbf',
  '/u01/app/oracle/oradata/PROD/test02.dbf'
CHARACTER SET AL32UTF8
;


Old:

    CREATE CONTROLFILE REUSE DATABASE "PROD" NORESETLOGS

New:

    CREATE CONTROLFILE SET DATABASE "DUPDB" RESETLOGS


     

STEP 6: Re-names of the data files names that have changed.



CREATE CONTROLFILE SET DATABASE "DUPDB" RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/DUPDB/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/DUPDB/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/DUPDB/redo03.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/oradata/DUPDB/system01.dbf',
  '/u01/app/oracle/oradata/DUPDB/undotbs01.dbf',
  '/u01/app/oracle/oradata/DUPDB/sysaux01.dbf',
  '/u01/app/oracle/oradata/DUPDB/users01.dbf',
  '/u01/app/oracle/oradata/DUPDB/example01.dbf',
  '/u01/app/oracle/oradata/DUPDB/testtbs.dbf',
  '/u01/app/oracle/oradata/DUPDB/test02.dbf'
CHARACTER SET AL32UTF8
;

Save as db_create_controlfile.sql.

STEP 7: Create the bdump, udump and cdump directories

    cd $ORACLE_BASE/admin
    mkdir newlsq
    cd newlsq
    mkdir bdump
    mkdir udump
    mkdir cdump
    mkdir $ORACLE_BASE/oradata/dupdb
    


STEP 8: Copy-over the old init.ora file
 from the source db
 SQL>create pfile from spfile;

    scp $ORACLE_HOME/dbs/pfile newhost:$ORACLE_HOME/dbs/pfile
SETP 9: Edit init.ora file to reflect the duplicate database
 -controlfile path
 -dump file path
 -db_name

STEP 10: Start the target database with nomount option
 SQL>startup nomount pfile=' ';

     SQL>@db_create_controlfile.sql

STEP 11: Place the new database in archivelog mode.
STEP 12: Open the database with restlogs.

Useful GoldenGate Commands

How to start goldenGate:
$ cd $GGATE
$ ./ggsci
GGSCI (goldengate2.localdomain) 4> dblogin userid ggate
Password:
Successfully logged into database.
---------display information---------
gg>info all
gg>START MANAGER


How to view current log
GGSCI (goldengate2.localdomain) 20>view ggsevt
GGSCI (goldengate2.localdomain) 20>view report ext1


See information of EXTRACT and REPLICAT
GGSCI (goldengate2.localdomain) 20>info extract ext1
GGSCI (goldengate2.localdomain) 20>info replicat rep1

Deleting Extract group
--------------------------------------
$ ./ggsci
>dblogin userid ggate
>ggate

delete extract ext1
delete replicat rep1

View Stats:
GGSCI (goldengate1.localdomain) 4> stats EXT1
GGSCI (goldengate *** Total statistics since 2010-10-06 16:14:53 ***
        Total inserts                                1.00
        Total updates                              0.00
        Total deletes                                0.00
        Total discards                              0.00
        Total operations                          1.00 



Editing parameters:

edit param EXT1

RMAN

Step-by-step creating rman catalog database
Step-by-step creating recovery catalog
Step-by-step RMAN Duplicate Database
Step-by-step RMAN Cloning with ASM

Step-by-step RMAN Duplicate Database !

How Recovery Manager Duplicates a Database
To prepare for database duplication, first create an auxiliary instance as described in "Preparing the RMAN DUPLICATE Auxiliary Instance: Basic Steps". For the duplication to work, you must connect RMAN to both the target (primary) database and an auxiliary instance started in NOMOUNT mode.
Allocate at least one auxiliary channel on the auxiliary instance. The principal work of the duplication is performed by the auxiliary channel, which starts a server session on the duplicate host. This channel then restores the necessary backups of the primary database, uses them to create the duplicate database, and initiates recovery.
So long as RMAN is able to connect to the primary and auxiliary instances, the RMAN client can run on any host. All backups and archived redo logs used for creating and recovering the duplicate database, however, must be accessible by the server session on the duplicate host. If the duplicate host is not the same as the target host, then you must make backups on disk on the target host available to the duplicate host with the same full path name as in the primary database
Use NFS or shared disks and make sure that the same path is accessible in the remote host. For example, the NFS mount point for both hosts could be /home/file_server.

As part of the duplicating operation, RMAN automates the following steps:
• Creates a control file for the duplicate database.
• Restores the target datafiles to the duplicate database and performs incomplete recovery by using all available incremental backups and archived redo logs.
• Shuts down and starts the auxiliary instance.
• Opens the duplicate database with the RESETLOGS option after incomplete recovery to create the online redo logs.
• Generates a new, unique DBID for the duplicate database.


RMAN DUPLICATE DATABASE: Options
When duplicating a database, you have the following options:
• You can run the DUPLICATE command with or without a recovery catalog.
• You can skip read-only tablespaces with the SKIP READONLY clause. Read-only tablespaces are included by default. If you omit them, then you can add them later.
• You can exclude tablespaces from the duplicate database with the SKIP TABLESPACE clause. You can exclude any tablespace except the SYSTEM tablespace or tablespaces containing rollback or undo segments.
• You can create the duplicate database in a new host. If the directory structure is the same on the new host, then you can specify the NOFILENAMECHECK option and reuse the target datafile filenames for the duplicate datafiles.
• By default, the DUPLICATE command creates the duplicate database from the most recent backups of the target database and then performs recovery to the most recent consistent point contained in the archived redo logs. 
• In some cases, you can set the duplicate database DB_NAME differently from the target database DB_NAME.

Renaming Database Files/Controlfiles/Redo logs/Temp files in RMAN Duplicate Database

• Renaming Control Files in RMAN DUPLICATE DATABASE
When choosing names for the duplicate control files, make sure you set the parameters in the initialization parameter file of the auxiliary database correctly; otherwise, you could overwrite the control files of the target database.
• Renaming Online Logs in RMAN DUPLICATE DATABASE
RMAN needs new names for the online redo log files of the duplicate database. Either you can specify the names explicitly in the DUPLICATE command, or you can let RMAN generate them according to the rules listed below:
Order Method Result
1 Specify the LOGFILE clause of DUPLICATE command. Creates online redo logs as specified.
2 Set LOG_FILE_NAME_CONVERT initialization parameter. Transforms target filenames, for example, from log_* to duplog_*. Note that you can specify multiple conversion pairs.

3 Set one of the Oracle Managed Files initialization parameters DB_CREATE_FILE_DEST, DB_CREATE_ONLINE_DEST_n, or DB_RECOVERY_FILE_DEST. Transforms target filenames based on the parameters set. The rules of precedence among these parameters are the same used by the SQL statement ALTER DATABASE ADD LOGFILE.
4 Do none of the preceding steps. Makes the duplicate filenames the same as the filenames from the target. You must specify the NOFILENAMECHECK option when using this method, and the duplicate database should be in a different host so that the online logs of the duplicate do not conflict with the originals.

• Renaming Datafiles in RMAN DUPLICATE DATABASE
There are several means of specifying new names to be used for the datafiles of your duplicate database. Listed in order of precedence, they are:
• Use the RMAN command SET NEWNAME FOR DATAFILE within a RUN block that encloses both the SET NEWNAME commands and the DUPLICATE command.
• Specify the DB_FILE_NAME_CONVERT parameter on the DUPLICATE command to specify a rule for converting filenames for any datafiles not renamed with SET NEWNAME or CONFIGURE AUXNAME.
Note:
The DB_FILE_NAME_CONVERT clause of the DUPLICATE command cannot be used to control generation of new names for files at the duplicate instance which are Oracle Managed Files (OMF) at the target instance. 

• Set the DB_CREATE_FILE_DEST initialization parameter to create Oracle Managed Files datafiles at the specified location.

If you do not use any of the preceding options, then the duplicate database reuses the original datafile locations from the target database.
It is possible for SET NEWNAME, or DB_FILE_NAME_CONVERT to generate a name that is already in use in the target database. In this case, specify NOFILENAMECHECK on the DUPLICATE command to avoid an error message.

Renaming Tempfiles in RMAN DUPLICATE DATABASE
RMAN re-creates datafiles for temporary tablespaces as part of the process of duplicating a database. There are several means of specifying locations for duplicate database tempfiles. Listed in order of precedence, they are:
• Use the SET NEWNAME FOR TEMPFILE command within a RUN block that encloses both the SET NEWNAME commands and the DUPLICATE command.

Preparing the RMAN DUPLICATE Auxiliary Instance: Basic Steps
To prepare the auxiliary instance used in RMAN DUPLICATE DATABASE, carry out the following tasks:
Task 1: Create an Oracle Password File for the Auxiliary Instance
orapwd file=orapwDUPDB password=oracle entries=5 force=yes
Task 2: Establish Oracle Net Connectivity to the Auxiliary Instance
The auxiliary instance must be accessible through Oracle Net. Before proceeding, start SQL*Plus to ensure that you can establish a connection to the auxiliary instance. Note that you must connect to the auxiliary instance with SYSDBA privileges, so a password file must exist.
Listener file:



# listener.ora Network Configuration File:
/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.
ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = GGATE1)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = GGATE1)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = DUPDB)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = DUPDB)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521))
    )
  )


Tnsnames file:

PRODDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.140)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODDB)
    )
  )

DUPDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DUPDB)
    )
  )
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

Task 3: Create an Initialization Parameter File for the Auxiliary Instance Create pfile from the source db and send it to Auxiliary location such as $ORACLE_HOME/dbs Make sure to change DB_NAME to reflect axiliary DB_NAME Change controlfile directory structure to reflect axiliary location and create directory at axiliary location. Change adump,bdump,cdump,udump directory structure to reflect axiliary directory and also create directory at axiliary location. Set other initialization parameters, including the parameters that allow you to connect as SYSDBA through Oracle Net, as needed. i.e *.remote_login_passwordfile='EXCLUSIVE' If you mention following parameter, then you don’t need to specify set newname when creating duplicate database. DB_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/PROD/,/u01/app/oracle/oradata/DUPDB/) LOG_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/PROD/redo, /u01/app/oracle/oradata/DUPDB/redo) After you create the client-side initialization parameter file, you can run the CREATE SPFILE command from SQL*Plus to create a server-side initialization parameter file at the Axiliary instance. SQL>CONNECT SYS/oracle@DUPDB AS SYSDBA SQL>startup NOMOUNT; SQL>CREATE SPFILE FROM PFILE='$ORACLE_HOME/dbs/initDUPDB.ora'; SQL>shutdown immediate; A server-side parameter file in the default location is an advantage when duplicating a database because you do not need to specify the PFILE parameter on the DUPLICATE command Task 4: Start the Auxiliary Instance Before beginning RMAN duplication, use SQL*Plus to connect to the auxiliary instance and start it in NOMOUNT mode (specifying a client-side parameter file if necessary). In this example, oracle is the password for the user with SYSDBA authority and DUPDB is the net service name for the auxiliary instance: Add a new entry to oratab, and source the environment Edit the /etc/oratab (or /opt/oracle/oratab) and add an entry for the new database. Source the new environment with '. oraenv' and verify that it has worked by issuing the following command: Echo $ORACLE_SID CONNECT SYS/oracle@DUPE AS SYSDBA -- start instance with the server parameter file SQL>STARTUP FORCE NOMOUNT; Because the auxiliary instance does not yet have a control file, you can only start the instance in NOMOUNT mode. Do not create a control file or try to mount or open the auxiliary instance. RMAN shuts down and restarts the auxiliary instance as part of the duplication. Hence, it is a good idea to create a server-side initialization parameter file for the auxiliary instance in the default location. If you do not have a server-side initialization parameter file for the auxiliary instance in the default location, then you must specify the client-side initialization parameter file with the PFILE parameter on the DUPLICATE command. The client-side parameter file for the auxiliary instance must reside on the same host as the RMAN client used to perform the duplication. Task 5: Mount or Open the Target Database Before beginning RMAN duplication, connect SQL*Plus to the target database and mount or open it if it is not already mounted or open. For example, enter: -- connect to target database SQL> CONNECT SYS/oracle@PROD AS SYSDBA; -- mount or open target database STARTUP MOUNT; Task 6: Make Sure You Have the Necessary Backups and Archived Redo Logs Make sure backups of all target datafiles and archived redo logs are accessible on the duplicate host. If you do not have backups of everything, then the duplicate operation fails. The database backup does not have to be a whole database backup: you can use a mix of full and incremental backups of individual datafiles. If you run rman from duplicate host, copy backup of datafile and archived log files to exactly same path to duplicate location i.e. if the backups are in /dsk1/bkp on the target host, then you might transfer them to /dsk1/bkp on the duplicate host. The new path—in this example, /dsk2/dup—must be accessible from both the target and duplicate hosts. Run the CATALOG command to add these copies to the RMAN repository at the duplicate host. Task 7: Allocate Auxiliary Channels if Automatic Channels Are Not Configured Start RMAN with a connection to the target database, the auxiliary instance, and, if applicable, the recovery catalog database. You can start the RMAN client on any host so long as it can connect to all the instances. In this example, a connection is established to three instances, all through the use of net service names: $ rman TARGET SYS/oracle@trgt CATALOG rman/cat@catdb AUXILIARY SYS/oracle@aux If you do not have automatic channels configured, then before issuing the DUPLICATE command, manually allocate at least one auxiliary channel within the same RUN command. The channel type (DISK or sbt) must match the media where the backups of the target database are located. If the backups reside on disk, then the more channels you allocate, the faster the duplication will be. For tape backups, limit the number of channels to the number of devices available. RUN { # SET NEWNAME If log_file_name_convert and \ db_file_name_convert is not already specified in init parameter SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/dupdb/system01.dbf'; # to manually allocate a channel of type sbt issue: ALLOCATE AUXILIARY CHANNEL ch1 DEVICE TYPE sbt; # to manually allocate three auxiliary channels for disk ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK; DUPLICATE TARGET DATABASE TO DUPDB LOGFILE '/u01/app/oracle/oradata/ggate1/redo01.log' SIZE 50M, '/u01/app/oracle/oradata/ggate1/redo02.log' SIZE 50M, '/u01/app/oracle/oradata/ggate1/redo03.log' SIZE 50M; SKIP TABLESPACE tools; }

run {
SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/dupdb/system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata/dupdb/undotbs01.dbf';
SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata/dupdb/sysaux01.dbf';
SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata/dupdb/users01.dbf';
SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata/dupdb/example01.dbf';
SET NEWNAME FOR DATAFILE 6 TO '/u01/app/oracle/oradata/dupdb/testtbs.dbf';
SET NEWNAME FOR TEMPFILE 1 TO '/u01/app/oracle/oradata/dupdb/temp01.dbf';
ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK;
DUPLICATE TARGET DATABASE TO DUPDB
LOGFILE
'/u01/app/oracle/oradata/dupdb/redo01.log' SIZE 50M,
'/u01/app/oracle/oradata/dupdb/redo02.log' SIZE 50M,
'/u01/app/oracle/oradata/dupdb/redo03.log' SIZE 50M;
}


Quiz-1

create a script that displays the time and date, lists all logged-in users, and gives the system uptime and then saves this information to a logfile.

1. Creating a script to clean up the log files in /var/log

#!/bin/bash
# Script Name: logfile1.sh
# Run as oracle user.
LOGFILE=/home/oracle/admin/log/testlog1.log
echo "Today is: `date` " >> $LOGFILE
echo "List of user: `finger` " >> $LOGFILE
echo `uptime` >> $LOGFILE

exit 0

uptime: Shows how long the system has been running, along with associated statistics. A load average of 1 or less indicates that the system handles processes immediately. A load average greater than 1 means that processes are being queued. When the load average gets above 3, then system performance is significantly degraded.

A script to clean up the log files in /var/log

System administrators often write scripts to automate common tasks. Bash has become a de facto standard for shell scripting on most flavors of UNIX. Most of the principles this Tutorial covers apply equally well to scripting with other shells, such as the Korn Shell, from which Bash derives some of its features.

Creating a script to clean up the log files in /var/log

#!/bin/bash
# Script Name: cleanup.sh
# Run as root user.
LOG_DIR=/var/log
cd $LOG_DIR
ls -ltr 
cat /dev/null > messages
ls -ltr # 
-rw-------  1 root  root       0 Feb 14 10:20 messages
exit 0

1. Special Characters

# This number sign indicates that anything followed by # sign is commented and 
# will not be executed
if [ -x "$filename" ]; then # Note the space after the semicolon.
echo "The # here does not begin a comment."
echo 'The # here does not begin a comment.'
echo The \# here does not begin a comment.
echo The # here begins a comment.
echo ${PATH#*:} # Parameter substitution, not a comment.
echo $(( 2#101011 )) # Base conversion, not a comment.
Command separator [semicolon]
# Command separator [semicolon]. Permits putting two or more commands on the same line
Example:

if [ -x "$filename" ]; then # Note the space after the semicolon.
 echo "File $filename exists."; cp $filename $filename.bak
else
echo "File $filename not found."; touch $filename
fi; echo "File test complete."
Terminator in a case option [ Double semicolon]

case "$variable" in
abc) echo "\$variable = abc" ;;
xyz) echo "\$variable = xyz" ;;
esac

A signle dot and two dots
When considering directory names, a single dot represents the current working directory, and two dots denote the parent directory.

bash$ pwd
/home/oracle/app
bash$ cd .
bash$ pwd
/home/oracle/app
bash$ cd ..
bash$ pwd
/home/oracle/

partial quoting [double quote]
"STRRING"

full quoting [single quote].
'STRING'. This is astronger form of quoting than "STRING" comma operator.
Comma operator links together arithmetic operations. All evaluated but only the last one is returned.

for file in /{,usr/}bin/*sum
# Find all executable files ending in "sum"
#+ in /bin and /usr/bin directories.
do
if [ -x "$file" ]
then
echo $file
fi
done

"\" escape [backslash].A quoting mechanism for single characters. \M 'M' char will be scaped.

"/" This forward slas is used for file path separator i.e. /home/oracle/app.

"`" command substitution. The `command` substitution makes available the output of command for assignment to a variable. This is also known as backquotes or backticks.

":" colon or null command which is shell equivalent of a NOP (no op, do-no-operation). The ":" command is itself a Bash builtin, and its exit status is true (0). :
echo $? # 0

 while true
  do
  ...
 done
or
################################
if condition
then : # Do nothing and branch ahead
else # Or else ...
take-some-action
fi
################################
: > test.log # File "test.log" now empty.
# Same effect as cat /dev/null > test.log
# However, this does not fork a new process, since ":" is a builtin.
#########################################################################
"!" is what we call "bang" operator. The ! operator inverts the exit status of
the command to which it is applied. This also refer to NOT EQUAL as in "!="
"*" wild card [asterisk]. The * character serves as a "wild card" for filename expansion in globbing. By
itself, it matches every filename in a given directory.
The * also represents any number (or zero) characters in a regular expression.In the context of
 arithmetic operations, the * denotes multiplication
ls -ltr|grep control.*
"?" test operator.
===================
Within certain expressions, the ? indicates a test for a condition.
In a parameter substitution expression, the ? tests whether a variable has been set. 
wild card. The ? character used as a single-character search "wild card" for filename expansion in
globbing.

"$" Dollar sign (variable substitution).
=========================================
It is used to substitute variable as in the following example:

var1=7
var2="hello"
echo $var1 
7
echo $var2 
hello
A $ prefixing a variable name indicates the value the variable holds.
In a regular expression, a "$" addresses the end-of-line of text.

${} Parameter substitution
==============================
$*, $@ Posistional Parameter
===============================
$? Exit status variable.
=========================
The "$?" variable holds the exit status of a command, 
a function, or of the script itself.
$$ Process ID variable.
========================
The "$$" variable holds the process ID of the script in which it appears.
() Parenthesis
===================
It is used in Command Group i.e. (x=hello; echo $x)
It can be used for an array initialization i.e.
Array=(ele1 ele2 ele3)

{} Brace Expansion or curly braket
==================================
 {file1,file2,file3,...}
# Concatenates the files file1, file2, and file3 into combined_file_name.
cat {file1,file2,file3} > combined_file_name

# Copies "file.txt" to "file22.backup"
cp file22.{txt,backup}

# Can be used as extended Braces expansion such as:
$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

# Used in the block of code such as creating an anonymous function

$ { local a;
a=123; }

{} \; pathname. 
==================
Used in find construct. The ";" ends the -exec option of a find command sequence. It needs to be escaped to
protect it from interpretation by the shell.

[ ] test.
================
Test expression between [ ]. Note that [ is part of the shell builtin test (and a synonym for it), not a
link to the external command /usr/bin/test.

[[ ]] test expression.
==============================
Test expression between [[ ]]. More flexible than the single-bracket [ ] test, this is a shell keyword.

[ ] An Array Element.
=========================
In the context of an array, brackets set off the numbering of each element of that array.
$ Array[1]=patern_1
[oracle@db01 ~]$ echo ${Array[1]}
patern_1

[ ] range of character.
=============================
This as part of a regular expression, brackets delineate a range of characters to match.

$((..)) integer expansion.
================================
It evaluates integer expression between $((..))
x=8
y=7
echo $(($x+$y))
15

> &> >& >> < <> Redirection.
===============================
'scriptname >filename' redirects the output of scriptname to file filename.
cat file1 > test_file.txt

'command &>filename' redirects both the stdout and the stderr of command to filename.
$ type bogus_command &>/dev/null
[oracle@db01 ~]$ echo $?
1
 and
$ type ls &>/dev/null # ls is valid command here hence dispalys 0
[oracle@db01 ~]$ echo $?
0

'command >&2' redirects stdout of command to stderr.

'scriptname >>filename' appends the output of scriptname to file filename. If
filename does not already exist, it is created.

2. Variables and Parameters

Find objects that are performing unrecoverable/nologgging option?



Using the steps below one can find the object that is unrecoverable from UNRECOVERABLE_CHANGE# in the v$datafile, one would use this to find the object that is unrecoverable since the last backup.

In this scenario datafile# 5 had unrecoverable/nologging as when we query v$datafile it shows and UNRECOVERABLE_TIME was greater than when the last backup was done.

SQL> column UNRECOVERABLE_CHANGE# format 99999999999999

SQL> select file#, UNRECOVERABLE_CHANGE# from v$datafile where file# = 5;

FILE# UNRECOVERABLE_CHANGE#
———- ———————
5 37640948153

– find the archive log that contains the sequence#
SQL> select sequence#, name from v$archived_log where 37640948153 >= first_change# and 37640948153 < next_change#;

SEQUENCE# NAME
———- ——————————————————————————–
2108 /u01/TESTDB/arch/arch_1_2108.arc

– This will create file in user_dump
SQL> alter system dump logfile '/u01/TESTDB/arch/arch_1_2108.arc' layer 19;

In 8i the object id is not included but in the 10g trace file the object id is included in the trace file
/u01/admin/TESTDB/udump $ grep DBA ora_168168_testdb.trc

…
CHANGE #1 INVLD AFN:5 DBA:0x01401e0a BLKS:0×0020 SCN:0×0008.c39349b9 SEQ: 1 OP:19.2
…

# to find the file# and block
SET SERVEROUTPUT ON
DECLARE
l_dba NUMBER := TO_NUMBER (’01401e0a’,'XXXXXXXX’);
l_file NUMBER := DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE (l_dba);
l_block NUMBER := DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK (l_dba);
BEGIN
DBMS_OUTPUT.PUT_LINE (‘File : ‘||l_file);
DBMS_OUTPUT.PUT_LINE (‘Block : ‘||l_block);
END;
/

Output:
File : 5
Block : 7690

SQL> SELECT owner, segment_name FROM dba_extents where file_id = 5 and block_id = 7690;

OWNER SEGMENT_NAME
—————————— —————-
SCOTT TEST_TABLE

Creating RMAN database to manage recovery catalog.

RMAN DBname: RMN1
tablespace name: rman_tbs
datafile name: rman01.dbf (size 100M)

on the prompt:
$ dbca &

step-1:
pick singel instance database on the Database Configuration Assistant: Welcome Screen.
step-2:
Pick Create a Database option
step-3:
Pick Custom Database on the database template. This is because you don't want any 
sample schemas in you RMAN database.
step-4:
Type "RMN1" rman database global name
Step-5:
Disselect "Configure the Database with Enterprise Manager" option, this is due to the 
fact that you're creating rman database to manage your recovery catalog and you don't
want to overload this small database with stuff unneccesary.
step-6:
Type password for sys/system login and save it in the safe place as we will require this
login credentials later to manage catalog database.
step-7:
Select "File System" option from Storage Mechanishm
step-8:
select "Use Database File Locations from template" option to choose for datafile 
storage or you can choose Oracle-Managed Files option.
step-9:
Make sure you Specify Flash Recovery Area
Step-10:
Choose appropriate memory for the rman database depending upon your need.
i go with about 300MB SGA size and 120MB for PGA.
Step-11:
Confirm the summary of parameters and other items and click Finish to start database creation.
Verify database creation:
$ export ORACLE_SID=RMN1
$ sqlplus rman/password@RMN1
Now you are ready to create rman recovery catalog database and register target database.
Go to the following link:
Creating a Rman Recovery Catalog

Creating a Recovery Catalog in RAC Environment

It is highly recommended that you create rman database in seperate server than having in the 
same server where RAC databases is intalled and are running. This would cause not only
performance issues but also if server crashes and data is not recoverable, you are going to
loose literally everything costing millions of dollors and hashles.

Create a RMAN database (RMN1)
=============================================================


Create a tablespace in the new database (RMN1)
============================================

$ sqlplus /nolog

CONNECT SYS/passwd@RMN1 AS SYSDBA;

CREATE TABLESPACE rman_tbs
DATAFILE '/u01/app/oracle/oradata/RMAN/rman01.dbf' size 100m;


Create the Recovery Catalog Owner in the new database (RMN1)
==============================================================

CREATE USER rman IDENTIFIED BY rman
DEFAULT TABLESPACE rman_tbs
QUOTA UNLIMITED ON rman_tbs;

Grant the necessary privileges to the schema owner(rman)
=============================================================

SQL> GRANT connect, resource, recovery_catalog_owner TO rman;

"RECOVERY_CATALOG_OWNER" role provides the user with all privileges required to maintain and query the recovery catalog

Creating the Recovery Catalog
==============================================================

Connect to the RMN1 database which will contain the recovery catalog. For example:

$ rman catalog rman/passwd@RMN1

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Apr 10 18:22:00 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to recovery catalog database
RMAN>

Run the CREATE CATALOG command to create the catalog
======================================================

RMAN> CREATE CATALOG;

recovery catalog created

Registering a Database in the Recovery Catalog
=======================================================

Connect to the target database (ORCL) and recovery catalog database (RMN1).

$ export ORACLE_SID=ORCL; 

$ rman target / catalog rman/passwd@RMN1;

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Apr 10 18:44:10 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1679521370)
connected to recovery catalog database

RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

Make sure that the registration was successful by running REPORT SCHEMA:

RMAN> REPORT SCHEMA;

Now in RAC environment regardless of what node you are working on, you can use the same
networked rman database and rman user to take backup and manage other jobs.
if you have multiple databases installed then you must register each target database in
the recovery catalog to manage and maintain RMAN backups and other rman tasks. Here is how
you will register cluster databases:
$ export ORACLE_SID=DEV
$ rman target / catalog rman/passwd@RMN1;

RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

Make sure that the registration was successful by running REPORT SCHEMA:

RMAN> REPORT SCHEMA;

CRS-0184: Cannot communicate with CRS daemon.

Solution:
 a) check permission in raw devices
   # ls -lrt /dev/raw/raw*
 Permission should be for oracle user NOT for root. execute the following as 
 a root user.
chown oracle:oinstall /dev/raw/raw1
chown oracle:oinstall /dev/raw/raw2
chown oracle:oinstall /dev/raw/raw3
chown oracle:oinstall /dev/raw/raw4
chown oracle:oinstall /dev/raw/raw5
chmod 600 /dev/raw/raw1
chmod 600 /dev/raw/raw2
chmod 600 /dev/raw/raw3
chmod 600 /dev/raw/raw4
chmod 600 /dev/raw/raw5
Creating RMAN Recovery Catalog
Creating RMAN Database

How to Find DB Size in Oracle?

SELECT name, bytes 
from v$datafile;

OR

SELECT SUBSTR (df.NAME, 1, 40) file_name, df.bytes / 1024 / 1024 allocated_mb,
((df.bytes / 1024 / 1024) - NVL (SUM (dfs.bytes) / 1024 / 1024, 0))
used_mb,
NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb
FROM v$datafile df, dba_free_space dfs
WHERE df.file# = dfs.file_id(+)
GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes
ORDER BY file_name;

OTN Discussion Forums: Message List - Database - General

Ask Tom HOT ARTICLES

 
© Copyright 2008 - 2011. All rights reserved to dba-sansar.blogspot.com.
All other blogs, posts and entries are the property of their respective authors.
Please email us for your comments and suggessions Click Here