341
11gR2 ASMCMD commands chdg - Changes existing disk group (add disks, drop disks, or rebalance) based on XML configuration file. You can use ALTER DISKGROUP... commands for same too, but here we are learning ASMCMD commands extensions in 11gr2. The chdg command add disks, delete disks or set rebalance power level on an existing disk group. Syntax : chdg {config_file.xml | 'contents_of_xml_file'} XML configuration template <chdg> update disk clause (add/delete disks/failure groups) name disk group to change power power to perform rebalance <add> items to add are placed here </add> <drop> items to drop are placed here </drop> <fg> failure group name failure group name </fg> <dsk> diskname disk name path disk path size size of the disk to add </dsk> </chdg> Example: We will add disk /dev/disk/disk61 to existing disk group DISK and set rebalance power level to 4. find existing disk in a disk group DATA SQL> select name,path from v$asm_disk where group_number=1; NAME PATH --------------- -----------------

11gR2 ASMCMD Commands

Embed Size (px)

Citation preview

Page 1: 11gR2 ASMCMD Commands

11gR2 ASMCMD commands

chdg - Changes existing disk group (add disks, drop disks, or rebalance) based on XML configuration file. You can use ALTER DISKGROUP... commands for same too, but here we are learning ASMCMD commands extensions in 11gr2. The chdg command add disks, delete disks or set rebalance power level on an existing disk group.

          Syntax : chdg {config_file.xml | 'contents_of_xml_file'}

XML configuration template

<chdg> update disk clause (add/delete disks/failure groups)      name disk group to change      power power to perform rebalance

<add> items to add are placed here</add><drop> items to drop are placed here</drop><fg> failure groupname failure group name</fg><dsk> diskname disk namepath disk pathsize size of the disk to add</dsk></chdg> Example:We will add disk /dev/disk/disk61 to existing disk group DISK and set rebalance power level to 4.find existing disk in a disk group DATA

SQL> select name,path from v$asm_disk where group_number=1;NAME          PATH--------------- -----------------DATA_0000 /dev/rdisk/disk50DATA_0001 /dev/rdisk/disk51DATA_0002 /dev/rdisk/disk60

Create following XML configuration file and save it as adddsk.xml

<chdg name="data" power="4"><add><dsk string="/dev/rdisk/disk61"/>

Page 2: 11gR2 ASMCMD Commands

</add></chdg>

and execute following

$asmcmdASMCMD>chdg adddsk.xmlASMCMD>

Now check again to see disks in DATA disk group

SQL> select name,path from v$asm_disk where group_number=1;NAME          PATH--------------- -----------------DATA_0000 /dev/rdisk/disk50DATA_0001 /dev/rdisk/disk51DATA_0002 /dev/rdisk/disk60DATA_0003 /dev/rdisk/disk61 <--- New disk added

Lets drop this disk with chdg command. You can use ALTER DISKGROUP DATA DROP DISK command too.

Create a XML file

<chdg name="data" power="4"><drop><dsk name="DATA_0003"/></drop></chdg>

and save it as dropdsk.xml and execute following.

$asmcmdASMCMD>chdg adddsk.xmlASMCMD>

Now check again to see disks in DATA disk group

SQL> select name,path from v$asm_disk where group_number=1;NAME          PATH--------------- -----------------DATA_0000 /dev/rdisk/disk50DATA_0001 /dev/rdisk/disk51DATA_0002 /dev/rdisk/disk60 DATA_003 disk name no longer exits!!!

Page 3: 11gR2 ASMCMD Commands

chkdg - Checks or repairs a disk group.

The 11gR2 ASM CHECK command checks for

The disks consistency The alias directory is linked correctly All metadata directories and internal consistency of ASM disk group metadata.

It writes findings in alert logs and display them on database control page too.In 11gR2 the default is norepair

       Syntax : chkdg [--repair] <<diskgroupname>>

Example:

ASMCMD> chkdg dataASMCMD>

The following are the contents from ASM alert log file ......SQL> /* ASMCMD */ALTER DISKGROUP data CHECK NOREPAIRNOTE: starting check of diskgroup DATAkfdp_checkDsk(): 6kfdp_checkDsk(): 7kfdp_checkDsk(): 8SUCCESS: check of diskgroup DATA found no errorsSUCCESS: /* ASMCMD */ALTER DISKGROUP data CHECK NOREPAIR...... mkdg -Creates a disk group based on XML configuration file      Syntax : mkdg {config_file.xml | 'contents_of_xml_file'}

XML configuration template

<dg> disk group name disk group name  redundancy normal, external, high

<fg> failure group name failure group name</fg><dsk> disk name disk namepath disk path

Page 4: 11gR2 ASMCMD Commands

size size of the disk to add</dsk><a> attributename attribute namevalue attribute value</a></dg>

Example: Create new disk group DATA2

First, create a XML configuration file with external redundancy and save it as mkdg.xml <dg name="data2" redundancy="external"><dsk string="/dev/rdisk/disk61"/><a name="compatible.rdbms" value="10.2"/></dg>

$ls -l mkdg.xml-rw-r--r-- 1 oracle oinstall 86 Nov 20 10:59 mkdg.xml

$asmcmdASMCMD>mkdg mkdg.xmlASMCMD>ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/ lsdsk - Lists Oracle ASM Disks. It runs in connected mode first and pulls information from v$ASM_DISK_STAT and v$ASM_DISK dynamic views otherwise it runs in disconnected mode and pulls information from disk header. The -I option forces non-connected mode.

Syntax :  lsdsk {-kptgMHI}{-G diskgroup } { --member|--candidate}   {--discovery}{--statistics}{pattern}

-k:Displays the TOTAL_MB, FREE_MB, OS_MB,NAME, FAILGROUP, LIBRARY, LABEL, UDID, PRODUCT, REDUNDANCY, and PATH columns of the V$ASM_DISK view.

--statistics: Displays the READS, WRITES, READ_ERRS, WRITE_ERRS, READ_TIME, WRITE_TIME, BYTES_READ, BYTES_WRITTEN, and the PATH columns of the V$ASM_DISK view.

Page 5: 11gR2 ASMCMD Commands

-p:Displays the GROUP_NUMBER, DISK_NUMBER, INCARNATION, MOUNT_STATUS, HEADER_STATUS, MODE_STATUS, STATE, and the PATH columns of the V$ASM_DISK view.

-t:Displays the CREATE_DATE, MOUNT_DATE, REPAIR_TIMER, and the PATH columns of the V$ASM_DISK view.

-g:Selects from GV$ASM_DISK_STAT, or from GV$ASM_DISK if the --discovery flag is also specified. GV$ASM_DISK.INST_ID is included in the output.

--discovery:Selects from V$ASM_DISK, or from GV$ASM_DISK if the -g flag is also specified. This option is always enabled if the Oracle ASM instance is version 10.1 or earlier. This flag is disregarded if lsdsk is running in non-connected mode.

-H:Suppresses column headings.

-I:Scans disk headers for information rather than extracting the information from an Oracle ASM instance. This option forces non-connected mode.

-G:Restricts results to only those disks that belong to the group specified by diskgroup.

-M:Displays the disks that are visible to some but not all active instances. These are disks that, if included in a disk group, cause the mount of that disk group to fail on the instances where the disks are not visible.

--candidate: Restricts results to only disks having membership status equal to CANDIDATE.

--member:Restricts results to only disks having membership status equal to MEMBER.

pattern: Returns only information about the specified disks that match the supplied pattern.

Example 1:

$ asmcmdASMCMD> lsdskPath/dev/rdisk/disk50/dev/rdisk/disk51/dev/rdisk/disk60/dev/rdisk/disk61

Page 6: 11gR2 ASMCMD Commands

Example 2: The following command display disk attached to disk group DATA2 and their space information.

ASMCMD> lsdsk -k -G DATA2Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path76800 76750 76800 DATA2_0000 DATA2_0000 System UNKNOWN /dev/rdisk/disk61

Example 3: The following shows io statistics for disks in DATA2 disk group

ASMCMD> lsdsk -t -G DATA2 --statisticsReads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read Bytes_Written Voting_File Create_Date Mount_Date Repair_Timer Path18 447 0 0 .026287 3.841985 77824 1830912 N 20-NOV-10 20-NOV-10 0 /dev/rdisk/disk61

Example 4: The following displays disks attached to DATA2 and DATA disk groups

ASMCMD> lsdsk -G DATA2Path/dev/rdisk/disk61ASMCMD> lsdsk -G DATAPath/dev/rdisk/disk50/dev/rdisk/disk51/dev/rdisk/disk60ASMCMD> dropdg -Drops a disk group. DROP diskgroup command marks the headers of disks belonging to a diskgroup that cannot be mounted by ASM as FORMER. If diskgroup is being used by any other nodes or ASM instance then this dropdg command fails.

The -r (INCLUDING CONTENTS) option of dropdg will drop the diskgroup and files if diskgroup is empty . The -f(Force) with INCLUDING CONTENTS should be used with caution as this will not check if diskgroup is being used by any other ASM instance and it will clear all disks in that diskgroup.

   Syntax:  dropdg { -r -f } { -r } <<diskgroup>>

Page 7: 11gR2 ASMCMD Commands

Example:

ASMCMD> dropdg data2ORA-15039: diskgroup not droppedORA-15053: diskgroup "DATA2" contains existing files (DBD ERROR: OCIStmtExecute)ASMCMD>dropdg -r data2ASMCMD> iostat -Displays I/O statistics for disks.

lsdg -Displays disk groups and their information.The lsdg command queries V$ASM_DISKGROUP_STAT by default. If the --discovery flag is specified, the V$ASM_DISKGROUP is queried instead.

Example:

ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/

umount -Dismounts a disk group

       Syntax:  umount { -a | [-f] diskgroup }

-a Dismounts all mounted disk groups.

-f Forces the dismount operation.

Example: The following example first checks the disk group with lsdg command and then unmount the data2 diskgroup. You will see data2 is unmounted if you run lsdg command again.

ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/ASMCMD> umount data2ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB

Page 8: 11gR2 ASMCMD Commands

Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/ASMCMD> mount : Mounts a disk group.You can mount ASM diskgroup in restrict mode for mainitance/rebalnace operations and during this mode client cannot access files in that diskgroup. If you are running RAC then MOUNT RESTRICT will mount diskgroup exclusively on that instance and clients cannot access files in that diskgroup until it mounted back in normal mode.

Why in restricted mode?It improve the rebalance operation performace as there are no external connections to the disk group.

Syntax: mount [--restrict] { [-a] | [-f] diskgroup[ diskgroup ...] }

-a Mounts all disk groups.

--restrict Mounts in restricted mode.

-f Forces the mount operation.

Example:In the previous example of unmount command we left DATA2 in unmounted stage. lets mount DATA2 disk group in restrict mode again and then unmount and mount in normal mode.

ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/ASMCMD>

ASMCMD> mount --restrict DATA2 ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/RESTRICTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/The state in above showing output showing RESTRICTED for DATA2 ASMCMD> umount data2ASMCMD> mount data2ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name

Page 9: 11gR2 ASMCMD Commands

MOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/MOUNTED EXTERN N 1024 4096 1048576 76800 76750 0 76750 0 N DATA2/DATA2 is removed from RESTRICTED mode. offline - Offline disks or failure groups that belong to a disk group. You won't be able to take disk offline in a disk group with external redundancy

Syntax: offline -G diskgroup { -F failgroup |-D disk} [-t {minutes | hours}]

-G diskgroup Disk group name.

-F failgroup Failure group name.

-D disk Specifies a single disk name.

-t minutes | hours Specifies the time before the specified disk is dropped as nm or nh, where m specifies minutes and h specifies hours. The default unit is hours.

Example:Lets add a disk to disk group2 with chdg command.

ASMCMD> chdg adddsk.xmlASMCMD> lsdsk -G DATA2Path/dev/rdisk/disk61/dev/rdisk/disk62 <-- New disk addedASMCMD> ASMCMD> lsdsk -k -G data2Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path76800 76774 76800 DATA2_0000 DATA2_0000 System UNKNOWN /dev/rdisk/disk6176800 76774 76800 DATA2_0001 DATA2_0001 System UNKNOWN /dev/rdisk/disk62ASMCMD> offline -G data2 -D data2_0001ORA-15067: command or option incompatible with diskgroup redundancy (DBD ERROR: OCIStmtExecute)ASMCMD>

Page 10: 11gR2 ASMCMD Commands

online - Online all disks, a single disk, or a failure group that belongs to a disk group.  Syntax : online { [-a] -G diskgroup | -F failgroup |-D disk} [-w]

-a Online all offline disks in the disk group.

-G diskgroup Disk group name.

-F failgroup Failure group name.

-D disk Disk name.

-w Wait option. Causes ASMCMD to wait for the disk group to be rebalanced before returning control to the user. The default is not waiting.

rebal - Rebalances a disk group and it's useful if you have added some disks to a diskgroups to load balance I/O.The power level can be set from 0 to 11. A value of 0 disables rebalancing. If the rebalance power is not specified, the value defaults to the setting of the ASM_POWER_LIMIT initialization parameter. You can determine if a rebalance operation is occurring with the ASMCMD lsop command

Syntax: rebal [--power power] [-w] diskgroup

--power power Power setting (0 to 11).

-w Wait option. Causes ASMCMD to wait for the disk group to be rebalanced before returning control to the user. The default is not waiting.

Example:The following example rebalance the data2 disk group power level set to 4 from 0. ASMCMD> lsopGroup_Name Dsk_Num State Power <--- means no rebalance activity is going onASMCMD> lsdgState Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB

Page 11: 11gR2 ASMCMD Commands

Usable_file_MB Offline_disks Voting_files NameMOUNTED EXTERN N 1024 4096 1048576 80896 78196 0 78196 0 N DATA/MOUNTED EXTERN N 1024 4096 1048576 153600 153548 0 153548 0 N DATA2/ASMCMD> ASMCMD> rebal --power 4 data2ASMCMD> lsopGroup_Name Dsk_Num State Power DATA2 REBAL WAIT 4 <--- rebalance is currently running...ASMCMD> lsopGroup_Name Dsk_Num State Power <--- means no rebalance activity completed.

The STATE can be one of the followings:  - Wait : No rebalance is running or wait period is specified by Admins  - Run   : Rebalance is running.  - REAP : Rebalance operation stopped.  - HALT : Halted by Admins.  - ERRORS : Errors during rebalance operations and halted.

md_backup, md_restore: Create backup file on a filesystem for asm disk group metadata information you can restore this backup file by md_restore command of ASMCMD.

Syntax: md_backup -b <<backupfilename>> -G <<diskgroup>> When you restore RMAN backup to a lost diskgroup or to a different server you will get errors something like

ORA-01119: error in creating database file ...ORA-17502: ksfdcre:4 Failed to create file ...ORA-15001: diskgroup "DATA" does not exist or is not mounted

You have two options to restore :

1. Use SET newname for datafile <<fileno#>> to <<new diskgroup>> or db_file_name_convert option to restore these files to new disk group.

2. Recreate ASM diskgroup manually and other user defined directory structures inside that diskgroup.Let try this with this example.

Example: For this example I will create different directories paths and one tablespace ts1 with 2 datafiles on DATA2 disk group. We will take a tablespace backup, DATA2 diskgroup metadata backup. We will restore

Page 12: 11gR2 ASMCMD Commands

DATA2 and it's directory tree with md_restore and tablespace datafiles from the RMAN backup.

ASMCMD> cd DATA2ASMCMD>mkdir mydir1ASMCMD>mkdir mydir2ASMCMD>ls -lType Redund Striped Time Sys Name                                            N mydir2/                                            N mydir1/

ASMCMD> cd mydir1ASMCMD> cd mydir1ASMCMD> ls -lASMCMD>mkdir ts1_dirASMCMD>mkdir ts2_dirASMCMD>ls -lType Redund Striped Time Sys Name                                            N ts1_dir/                                            N ts2_dir/

Create a tablespace and create one table inside it.SQL> create tablespace ts1 datafile '+DATA2/test1.dbf' size 1m;Tablespace created.

SQL> alter tablespace ts1 add datafile '+DATA2/ts2.dbf' size 2m;Tablespace altered

SQL> connect scott/tiger

SQL> create table test tablespace ts1as select * from user_objects;Table created

SQL> select count(1) from test;COUNT(1)----------7

Take the ASM DATA2 diskgroup metadata backup

ASMCMD> md_backup data2asm_backup -G DATA2Disk group metadata to be backed up: DATA2Current alias directory path: mydir1/ts2_dirCurrent alias directory path: mydir1

Page 13: 11gR2 ASMCMD Commands

Current alias directory path: mydir2Current alias directory path: mydir1/ts1_dirCurrent alias directory path: TESTCurrent alias directory path: TEST/DATAFILEST/DATAFILE

ASMCMD> exit

$ ls -lt-rw-r--r-- 1 oracle oinstall 13418 Nov 20 13:03 data2aasm_backup

Take RMAN tablespace ts1 backup with following commands.

RMAN> run {2> allocate channel c1 type disk;3> backup tablespace ts1 format "/backup/test/ts1_%s_%t";4> }using target database control file instead of recovery catalogallocated channel: c1channel c1: sid=51 instance=TEST1 devtype=DISKStarting backup at 20-NOV-10channel c1: starting full datafile backupsetchannel c1: specifying datafile(s) in backupsetinput datafile fno=00007 name=+DATA2/ts2.dbfinput datafile fno=00006 name=+DATA2/ts1.dbfchannel c1: starting piece 1 at 20-NOV-10channel c1: finished piece 1 at 20-NOV-10piece handle=/backup/test/ts1_11_735580273 tag=TAG20101120T155112 comment=NONEchannel c1: backup set complete, elapsed time: 00:00:01Finished backup at 20-NOV-10released channel: c1RMAN> RMAN> RMAN> **end-of-file** SQL> alter tablespace ts1 offline;Tablespace altered. Now drop the DATA2 disk group with force option.

$asmcmdASMCMD> dropdg data2ORA-15039: diskgroup not droppedORA-15053: diskgroup "DATA2" contains existing files (DBD ERROR: OCIStmtExecute)

Page 14: 11gR2 ASMCMD Commands

ASMCMD>dropdg -r data2ASMCMD> SQL>connect scott/tiger SQL> select * from test;select * from test*ERROR at line 1:ORA-00376: file 6 cannot be read at this timeORA-01110: data file 6: '+DATA2/ts1.dbf'

It's time to restore ts1 tablespace files from RMAN backup.

RMAN> run {2> allocate channel c1 type disk format '/backup/test/ts1_%s_%t' ;3> restore tablespace ts1 ;4> } Lets use ASM md_restore command to create DATA2 diskgroup from backup. This will restore all the metadata information and create directory structure. $ asmcmdASMCMD> md_restore disk2asm_backupCurrent Diskgroup metadata being restored: DATA2Diskgroup DATA2 created!System template ONLINELOG modified!System template AUTOBACKUP modified!System template ASMPARAMETERFILE modified!System template OCRFILE modified!System template ASM_STALE modified!System template OCRBACKUP modified!System template PARAMETERFILE modified!System template ASMPARAMETERBAKFILE modified!System template FLASHFILE modified!System template XTRANSPORT modified!System template DATAGUARDCONFIG modified!System template TEMPFILE modified!System template ARCHIVELOG modified!System template CONTROLFILE modified!System template DUMPSET modified!System template BACKUPSET modified!System template FLASHBACK modified!System template DATAFILE modified!System template CHANGETRACKING modified!Directory +DATA2/mydir1 re-created!

Page 15: 11gR2 ASMCMD Commands

Directory +DATA2/TEST re-created!Directory +DATA2/mydir2 re-created!Directory +DATA2/mydir1/ts2_dir re-created!Directory +DATA2/mydir1/ts1_dir re-created!Directory +DATA2/TEST/DATAFILE re-created!

ASMCMD> Restore tablespace ts1 datafiles from RMAN backups

RMAN> run {2> allocate channel c1 type disk format '/backup/test/ts1_%s_%t' ;3> restore tablespace ts1 ;4> }

SQL> alter tablespace ts1 online;alter tablespace ts1 online*ERROR at line 1:ORA-01113: file 6 needs media recoveryORA-01110: data file 6: '+DATA2/ts1.dbf' SQL> recover tablespace ts1;Media recovery complete.SQL> alter tablespace ts1 online;Tablespace altered.SQL> alter tablespace ts1 online;Tablespace altered.SQL> connect scott/tigerConnected.SQL> select count(1) from test;COUNT(1)----------7 cp - It's going to make your life so easy when moving database across different servers. It allows you to copy files between ASM diskgroup and OS filesystem. In eairler release you have to use either RMAN command or setup FTP to move files between.

10g Example:

In 10gR2 this is how you need to setup FTP with Oracle XMLDB

- Connect to Oracle instance as sys and execute

@ORACLE_HOME/rdbms/admin/catxdbdbca 7777 8080

Page 16: 11gR2 ASMCMD Commands

This will enable ftp on port 7777 and http service on port 8080- use ftp to move files between ASM and filesystem

FTP> open <<hostname>> 7777

331 pass required for SYSTEMPassword:230 SYSTEM logged inftp>Relax! in 11g you can move files just by using cp command11gR2 example 11gR2 Example:

$ ls -l-rw-r----- 1 oracle oinstall 212992 Nov 20 15:51 ts1_11_735580273

$ asmcmdASMCMD> cp /backup/test/ts1_11_735580273 +DATA/copying /backup/test/ts1_11_735580273 -> +DATA/ts1_11_735580273ASMCMD> cd +DATAASMCMD> ls -lType Redund Striped Time Sys NameY ASM/Y TEST/N archlogs/Y test-mvip/N ts1_11_735580273 => +DATA/ASM/BACKUPSET/ts1_11_735580273.304.735585509ASMCMD>

Duplicating a controlfile into ASM

Duplicating a controlfile into ASM when original controlfile is stored on a file system

On the database instance:

1. Identify the location of the current controlfile:    SQL> select name from v$controfile;

NAME--------------------------------------------------------------------------------/oradata2/102b/oradata/P10R2/control01.ctl' 

Page 17: 11gR2 ASMCMD Commands

2. Shutdown the database and start the instance:    SQL> shutdown normal    SQL> startup nomount

3. Use RMAN to duplicate the controlfile:    $ rman nocatalog    RMAN>connect target    RMAN>restore controlfile to '' from '';

RMAN> restore controlfile to '+DG1' from '/oradata2/102b/oradata/P10R2/control01.ctl';

Starting restore at 23-DEC-05allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: copied control file copyFinished restore at 23-DEC-05

We are only specifying the name of the diskgroup, so Oracle will create an OMF (Oracle Managed File).  Use ASMCMD or sqlplus to identify the name assigned to the controlfile

4. On the ASM instance, identify the name of the controlfile:

Using ASMCMD:$ asmcmdASMCMD> cd ASMCMD> find -t controlfile . *

Changing the current directory to the diskgroup where the controlfile was created will speed the search.

Output:

ASMCMD> find -t controlfile . *+DG1/P10R2/CONTROLFILE/backup.308.577785757ASMCMD>

Page 18: 11gR2 ASMCMD Commands

Note the name assigned to the controlfile. Although the name starts with the backup word, that does not indicate is a backup of the file.  This just the name assigned for the identical copy of the current controlfile.

5. On the database side:

                      Modify init.ora or spfile, adding the new path to parameter control_files.

                      if using init.ora, just modify the control_files parameter and restart the database.

                      If using spfile,

1) startup nomount the database instance2) alter system set control_files='+DG1/P10R2/CONTROLFILE/backup.308.577785757','/oradata2/102b/oradata/P10R2/control01.ctl' scope=spfile;

For RAC instance:

alter system set control_files='+DG1/P10R2/CONTROLFILE/backup.308.577785757','/oradata2/102b/oradata/P10R2/control01.ctl' scope=spfile sid='*';

3) shutdown immediate

                      start the instance.

Verify that new control file has been recognized. If the new controlfile was not used, the complete procedure needs to be repeated.

Duplicating a controlfile into ASM   using a specific name

It is also possible to duplicate the controlfile using a specific name for the new controlfile.  In the following example, the controlfile is duplicated into a new diskgroup where   controlfiles have not been created before.

Page 19: 11gR2 ASMCMD Commands

On the ASM instance:

A. Create the directory  to store the new controlfile. 

     SQL> alter diskgroup add directory '+//CONTROLFILE';

    Note that ASM uses directories to store the files and those are created automatically when using OMF files. (just specifying the diskgroup name).  Asumming that other OMF files were created on the diskgroup, the first directory (DB_NAME) already exist, so it is only required to create the directory for the controlfile.

     

SQL> alter diskgroup DG1 add directory '+DG1/P10R2/CONTROLFILE';

      ASMCMD can also be used

ASMCMD>cd dg1ASMCMD>mkdir controlfile

On the database instance:

B. Edit init.ora or spifile and modify parameter control_file:     control_files='+DG1/P10R2/CONTROLFILE/control02.ctl','/oradata2/102b/oradata/P10R2/control01.ctl'

C. Identify the location of the current controlfile:   

SQL> select name from v$controfile;          NAME          --------------------------------------------------------------------------------/oradata2/102b/oradata/P10R2/control01.ctl'

D. Shutdown the database and start the instance:    SQL> shutdown normal    SQL> startup nomount

E. Use RMAN to duplicate the controlfile:    $ rman nocatalog    RMAN>connect target    RMAN>restore controlfile to '' from '';

Page 20: 11gR2 ASMCMD Commands

RMAN> restore controlfile to '+DG1/PROD/controlfile/control02.ctl' from '/oradata2/102b/oradata/P10R2/control01.ctl';

Starting restore at 23-DEC-05allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: copied control file copyFinished restore at 23-DEC-05

F. Start the database:    SQL> alter database mount;    SQL> alter database open;

Now, using ASMCMD to search for information for the controlfiles,  the find -t contrlfile command will return two records.  That does not indicate there were created two controlfiles.  The name specified is an alias name and is only an entry in the ASM metadata (V$ASM_ALIAS). Oracle will create the alias and the OMF entry when user specifies the file name.

Duplicating a controlfile into ASM when original controlfile is stored on ASM

If using spfile to start the instance:

1. Modify the spfile specifically the parameter control_files. In this example, a second controlfileis going to be created on same diskgroup DATA1.

sql> alter system set control_files='+DATA1/v102/controlfile/current.261.637923577','+DATA1'scope=spfile sid='*';

2. Start the instance in NOMOUNT mode.

3. From rman, duplicate the controlfile

$ rman nocatalogRMAN>connect targetRMAN> restore controlfile from '+DATA1/v102/controlfile/current.261.637923577';

Page 21: 11gR2 ASMCMD Commands

The output for the execution is like:

Starting restore at 08-NOV-07allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=147 instance=V1021 devtype=DISK

channel ORA_DISK_1: copied control file copyoutput filename=+DATA1/v102/controlfile/current.261.637923577output filename=+DATA1/v102/controlfile/current.269.638120375Finished restore at 08-NOV-07

Note that the command prints the name of the new created file: +DATA1/v102/controlfile/current.269.638120375

4. Mount and Open the database

RMAN> sql 'alter database mount';RMAN> sql 'alter database open;

5. Validate both controlfiles are present

SQL> select name from v$controlfile;

NAME--------------------------------------------------------------------------------+DATA1/v102/controlfile/current.261.637923577+DATA1/v102/controlfile/current.269.638120375

6. Modify the control_file parameter with the complete path of the new file:

sql> alter system set control_files='+DATA1/v102/controlfile/current.261.637923577','+DATA1/v102/controlfile/current.269.638120375'scope=spfile sid='*';

Next time instance are restarted, will pick both files.

When using init.ora file:

Page 22: 11gR2 ASMCMD Commands

1) Edit init.ora and add new disk group name or same disk group name for mirroring controlfiles.

Example:

control_files=('+GROUP1','+GROUP2')

(2) Start the instance in NOMOUNT mode.

(3)  Execute restore command, to duplicate the controlfile using the original location. Presuming, your current controlfile location DISK path is '+data/V10G/controlfile/Current.260.605208993' , execute:

RMAN> restore controlfile from '+data/V10G/controlfile/Current.260.605208993';

Starting restore at 29-APR-05allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=317 devtype=DISK

channel ORA_DISK_1: copied controlfile copyoutput filename=+GROUP2/v10g/controlfile/backup.268.7output filename=+GROUP2/v10g/controlfile/backup.260.5Finished restore at 29-APR-05

(4) Mount and open the database:

RMAN> alter database mount;

database mountedreleased channel: ORA_DISK_1

RMAN> alter database open;

database opened

RMAN> exit

(5) Verify new mirrored controlfiles via sqlplus

Page 23: 11gR2 ASMCMD Commands

SQL> show parameter control_files

NAME TYPE VALUE------------------------------------ ----------- ------------------------------control_files string +GROUP2/v10g/controlfile/backup.268.7, +GROUP2/v10g/controlfile/backup.260.5

 

ASM Filenames

1. Fully Qualified ASM Filename: +group/dbname/file_type/file_type_tag.file.incarnation

Page 24: 11gR2 ASMCMD Commands

Example:+dgroup2/sample/controlfile/Current.256.541956473

2. Numeric ASM Filename: +group.file.incarnation

Example:+dgroup2.257.541956473

3. Alias ASM Filenames: +group/dir_1/…/dir_n/filename

Example:+dgroup1/myfiles/control_file1+dgroup2/mydir/second.dbf

4. Alias ASM Filename with Template: +group(template_name)/alias

Example:+dgroup1(my_template)/config1

5. Incomplete ASM Filename:+group

Example:+dgroup1

6. Incomplete ASM Filename with Template: +group(template_name)

Example:+dgroup1(my_template)

ASMCMD

ASMCMD is a command-line utility that you can use to easily view and manipulate files and directories within Automatic Storage Management (ASM) disk groups. It can list the contents of disk groups, perform searches, create and remove directories and aliases, display space utilization, and more.

To run ASMCMD in interactive mode:1. At the operating system command prompt, enter:asmcmdAn ASMCMD command prompt is displayed.ASMCMD>2. Enter an ASMCMD command and press the Enter key.The command runs and displays its output, if any, and then ASMCMD prompts for the next command.

Page 25: 11gR2 ASMCMD Commands

3. Continue entering ASMCMD commands. Enter the command exit to exit ASMCMD.Commands:

cd: Changes the current directory to the specified directory. du: Displays the total disk space occupied by ASM files in the specified ASM directory

and all its subdirectories, recursively.

exit: Exits ASMCMD. find: Lists the paths of all occurrences of the specified name (with wildcards) under the

specified directory. help: Displays the syntax and description of ASMCMD commands. ls: Lists the contents of an ASM directory, the attributes of the specified file, or the

names and attributes of all disk groups. lsct: Lists information about current ASM clients. lsdg: Lists all disk groups and their attributes. mkalias: Creates an alias for a system-generated filename. mkdir: Creates ASM directories. pwd:Displays the path of the current ASM directory. rm: Deletes the specified ASM files or directories. rmalias: Deletes the specified alias, retaining the file that the alias points to

asm_alias.sql

-- PURPOSE  : Provide a summary report of all alias definitions contained within all ASM disk groups.                                     

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name        FORMAT a16         HEAD 'Disk Group Name'COLUMN alias_name             FORMAT a30         HEAD 'Alias Name'COLUMN file_number                               HEAD 'File|Number'COLUMN file_incarnation                          HEAD 'File|Incarnation'COLUMN alias_index                               HEAD 'Alias|Index'COLUMN alias_incarnation                         HEAD 'Alias|Incarnation'COLUMN parent_index                              HEAD 'Parent|Index'COLUMN reference_index                           HEAD 'Reference|Index'COLUMN alias_directory        FORMAT a10         HEAD 'Alias|Directory?'COLUMN system_created         FORMAT a8          HEAD 'System|Created?'

break on report on disk_group_name skip 1

Page 26: 11gR2 ASMCMD Commands

SELECT    g.name               disk_group_name  , a.name               alias_name  , a.file_number        file_number  , a.file_incarnation   file_incarnation  , a.alias_index        alias_index  , a.alias_incarnation  alias_incarnation  , a.parent_index       parent_index  , a.reference_index    reference_index  , a.alias_directory    alias_directory  , a.system_created     system_createdFROM    v$asm_alias a JOIN v$asm_diskgroup g USING (group_number)ORDER BY    g.name  , a.file_number/

asm_clients.sql

                             --  PURPOSE  : Provide a summary report of all clients making use of this ASM instance.                                                       

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name        FORMAT a15           HEAD 'Disk Group Name'COLUMN instance_name          FORMAT a20           HEAD 'Instance Name'COLUMN db_name                FORMAT a9            HEAD 'Database Name'COLUMN status                 FORMAT a12           HEAD 'Status'

break on report on disk_group_name skip 1

SELECT    a.name              disk_group_name  , c.instance_name     instance_name

Page 27: 11gR2 ASMCMD Commands

  , c.db_name           db_name  , c.status            statusFROM    v$asm_diskgroup a JOIN v$asm_client c USING (group_number)ORDER BY    a.name/

asm_disks_perf.sql

--  PURPOSE  : Provide a summary report of all disks contained within all ASM disk groups along with their performance metrics.                

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name    FORMAT a15               HEAD 'Disk Group Name'COLUMN disk_path          FORMAT a20               HEAD 'Disk Path'COLUMN reads              FORMAT 999,999,999       HEAD 'Reads'COLUMN writes             FORMAT 999,999,999       HEAD 'Writes'COLUMN read_errs          FORMAT 999,999           HEAD 'Read|Errors'COLUMN write_errs         FORMAT 999,999           HEAD 'Write|Errors'COLUMN read_time          FORMAT 999,999,999       HEAD 'Read|Time'COLUMN write_time         FORMAT 999,999,999       HEAD 'Write|Time'COLUMN bytes_read         FORMAT 999,999,999,999   HEAD 'Bytes|Read'COLUMN bytes_written      FORMAT 999,999,999,999   HEAD 'Bytes|Written'

break on report on disk_group_name skip 2

compute sum label ""              of reads writes read_errs write_errs read_time write_time bytes_read bytes_written on disk_group_namecompute sum label "Grand Total: " of reads writes read_errs write_errs read_time write_time bytes_read bytes_written on report

SELECT    a.name                disk_group_name  , b.path                disk_path  , b.reads               reads  , b.writes              writes

Page 28: 11gR2 ASMCMD Commands

  , b.read_errs           read_errs   , b.write_errs          write_errs  , b.read_time           read_time  , b.write_time          write_time  , b.bytes_read          bytes_read  , b.bytes_written       bytes_writtenFROM    v$asm_diskgroup a JOIN v$asm_disk b USING (group_number)ORDER BY    a.name/

asm_diskgroups.sql

-- PURPOSE  : Provide a summary report of all disk groups.                    

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN group_name             FORMAT a16           HEAD 'Disk Group|Name'COLUMN sector_size            FORMAT 99,999        HEAD 'Sector|Size'COLUMN block_size             FORMAT 99,999        HEAD 'Block|Size'COLUMN allocation_unit_size   FORMAT 999,999,999   HEAD 'Allocation|Unit Size'COLUMN state                  FORMAT a11           HEAD 'State'COLUMN type                   FORMAT a6            HEAD 'Type'COLUMN total_mb               FORMAT 999,999,999   HEAD 'Total Size (MB)'COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'

break on report on disk_group_name skip 1

compute sum label "Grand Total: " of total_mb used_mb on report

SELECT    name                                     group_name  , sector_size                              sector_size  , block_size                               block_size  , allocation_unit_size                     allocation_unit_size

Page 29: 11gR2 ASMCMD Commands

  , state                                    state  , type                                     type  , total_mb                                 total_mb  , (total_mb - free_mb)                     used_mb  , ROUND((1- (free_mb / total_mb))*100, 2)  pct_usedFROM    v$asm_diskgroupORDER BY    name/

asm_disks.sql

--  PURPOSE  : Provide a summary report of all disks contained within all disk --             groups. This script is also responsible for queriing all        --             candidate disks - those that are not assigned to any disk       --             group.                                                          

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name        FORMAT a20           HEAD 'Disk Group Name'COLUMN disk_file_path         FORMAT a17           HEAD 'Path'COLUMN disk_file_name         FORMAT a20           HEAD 'File Name'COLUMN disk_file_fail_group   FORMAT a20           HEAD 'Fail Group'COLUMN total_mb               FORMAT 999,999,999   HEAD 'File Size (MB)'COLUMN used_mb                FORMAT 999,999,999   HEAD 'Used Size (MB)'COLUMN pct_used               FORMAT 999.99        HEAD 'Pct. Used'

break on report on disk_group_name skip 1

compute sum label ""              of total_mb used_mb on disk_group_namecompute sum label "Grand Total: " of total_mb used_mb on report

SELECT    NVL(a.name, '[CANDIDATE]')                       disk_group_name  , b.path                                           disk_file_path  , b.name                                           disk_file_name  , b.failgroup                                      disk_file_fail_group  , b.total_mb                                       total_mb

Page 30: 11gR2 ASMCMD Commands

  , (b.total_mb - b.free_mb)                         used_mb  , ROUND((1- (b.free_mb / b.total_mb))*100, 2)      pct_usedFROM    v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)ORDER BY    a.name/

asm_files.sql

--  PURPOSE  : Provide a summary report of all files (and file metadata) information for all ASM disk groups.                            

SET LINESIZE  150SET PAGESIZE  9999SET VERIFY    off

COLUMN full_alias_path        FORMAT a63                  HEAD 'File Name'COLUMN system_created         FORMAT a8                   HEAD 'System|Created?'COLUMN bytes                  FORMAT 9,999,999,999,999    HEAD 'Bytes'COLUMN space                  FORMAT 9,999,999,999,999    HEAD 'Space'COLUMN type                   FORMAT a18                  HEAD 'File Type'COLUMN redundancy             FORMAT a12                  HEAD 'Redundancy'COLUMN striped                FORMAT a8                   HEAD 'Striped'COLUMN creation_date          FORMAT a20                  HEAD 'Creation Date'COLUMN disk_group_name        noprint

BREAK ON report ON disk_group_name SKIP 1

compute sum label ""              of bytes space on disk_group_namecompute sum label "Grand Total: " of bytes space on report

SELECT    CONCAT('+' || disk_group_name, SYS_CONNECT_BY_PATH(alias_name, '/')) full_alias_path  , bytes  , space  , NVL(LPAD(type, 18), '<DIRECTORY>')  type  , creation_date  , disk_group_name  , LPAD(system_created, 4) system_createdFROM

Page 31: 11gR2 ASMCMD Commands

    ( SELECT          g.name               disk_group_name        , a.parent_index       pindex        , a.name               alias_name        , a.reference_index    rindex        , a.system_created     system_created        , f.bytes              bytes        , f.space              space        , f.type               type        , TO_CHAR(f.creation_date, 'DD-MON-YYYY HH24:MI:SS')  creation_date      FROM          v$asm_file f RIGHT OUTER JOIN v$asm_alias     a USING (group_number, file_number)                                   JOIN v$asm_diskgroup g USING (group_number)    )WHERE type IS NOT NULLSTART WITH (MOD(pindex, POWER(2, 24))) = 0    CONNECT BY PRIOR rindex = pindex/

asm_files2.sql

--  PURPOSE  : Provide a summary report of all files (and file metadata)       --             information for all ASM disk groups.                            

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name        FORMAT a16                  HEAD 'Disk Group Name'COLUMN file_name              FORMAT a30                  HEAD 'File Name'COLUMN bytes                  FORMAT 9,999,999,999,999    HEAD 'Bytes'COLUMN space                  FORMAT 9,999,999,999,999    HEAD 'Space'COLUMN type                   FORMAT a18                  HEAD 'File Type'COLUMN redundancy             FORMAT a12                  HEAD 'Redundancy'COLUMN striped                FORMAT a8                   HEAD 'Striped'COLUMN creation_date          FORMAT a20                  HEAD 'Creation Date'

break on report on disk_group_name skip 1compute sum label ""              of bytes space on disk_group_namecompute sum label "Grand Total: " of bytes space on report

Page 32: 11gR2 ASMCMD Commands

SELECT    g.name               disk_group_name  , a.name               file_name  , f.bytes              bytes  , f.space              space  , f.type               type  , TO_CHAR(f.creation_date, 'DD-MON-YYYY HH24:MI:SS')  creation_dateFROM    v$asm_file f JOIN v$asm_alias     a USING (group_number, file_number)                 JOIN v$asm_diskgroup g USING (group_number)WHERE    system_created = 'Y'ORDER BY    g.name  , file_number/

asm_templates.sql

-- | PURPOSE  : Provide a summary report of all template information for all  ASM disk groups.                                                

SET LINESIZE  145SET PAGESIZE  9999SET VERIFY    off

COLUMN disk_group_name        FORMAT a16           HEAD 'Disk Group Name'COLUMN entry_number           FORMAT 999           HEAD 'Entry Number'COLUMN redundancy             FORMAT a12           HEAD 'Redundancy'COLUMN stripe                 FORMAT a8            HEAD 'Stripe'COLUMN system                 FORMAT a6            HEAD 'System'COLUMN template_name          FORMAT a30           HEAD 'Template Name'

break on report on disk_group_name skip 1

SELECT    b.name                                           disk_group_name  , a.entry_number                                   entry_number  , a.redundancy                                     redundancy  , a.stripe                                         stripe

Page 33: 11gR2 ASMCMD Commands

  , a.system                                         system  , a.name                                           template_nameFROM    v$asm_template a JOIN v$asm_diskgroup b USING (group_number)ORDER BY    b.name  , a.entry_number/

Data Guard Quick Reference

Page 34: 11gR2 ASMCMD Commands

Managing a Physical Standby Database

1. Starting Up a Physical Standby Database

1.1 STARTUP:

Starts the database, mounts the database as a physical standby database, and opens the database for read-only access.

1.2 STARTUP MOUNT:

Starts and mounts the database as a physical standby database, but does not open the database.

SQL> STARTUP MOUNT;

1.3 Start log apply services after mounting DB:

To start Redo Apply, issue the following statement:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

To start real-time apply, issue the following statement:

SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;

2. Shutting Down a Physical Standby Database

2.1 Find out if the standby database is performing Redo Apply or real-time apply.

If the MRP0 or MRP process exists, then the standby database is applying redo.

SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;

2.2 If log apply services are running, cancel them as shown in the following example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

2.3 Shut down the standby database.

SQL> SHUTDOWN;

Page 35: 11gR2 ASMCMD Commands

3.Opening a Physical Standby Database for Read-Only Access

3.1 Open a standby database for read-only access when it is currently shut down:

SQL> STARTUP;

3.2 Open a standby database for read-only access when it is currently performing Redo Apply or real-time apply:

Cancel Redo Apply or real-time apply:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Open the database for read-only access:

SQL> ALTER DATABASE OPEN;

4. To change the standby database from being open for read-only access to performing Redo Apply:

4.1 Terminate all active user sessions on the standby database.

4.2 Restart Redo Apply or real-time apply.

To start Redo Apply, issue the following statement:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

To start real-time apply, issue the following statement:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE;

Data Pump

Data Pump

Home >> Reference >> General Reference >> Data Pump

Introduction

Page 36: 11gR2 ASMCMD Commands

Data Pump Components:

Direct Path API (DPAPI): Oracle Database 10g supports a direct path API interface that minimizes data conversion and parsing at both unload and load time. 

External Table Services: Data Pump uses the new ORACLE_DATAPUMP access driver that provides external tables write and read access to files containing binary streams. 

The DBMS_METADATA package is used by worker processes for all metadata unloading and loading. Database object definitions are stored using XML rather than SQL. 

The DBMS_DATAPUMP package embodies the API for high-speed export and import utilities for bulk data and metadata movement. 

The SQL*Loader client has been integrated with external tables, thereby providing automatic migration of loader control files to external table access parameters. 

The expdp and impdp clients are thin layers that make calls to the DBMS_DATAPUMP package to initiate and monitor Data Pump operations. 

Master Table

During the operation, a master table is maintained in the schema of the user who initiated the Data Pump export. The master table has the same name as the name of the Data Pump job. This table maintains one row per object with status information. In the event of a failure, Data Pump uses the information in this table to restart the job. The master table is the heart of every Data Pump operation; it maintains all the information about the job. Data Pump uses the mastertable to restart a failed or suspended job. The master table is dropped (by default) when the Data Pump job finishes successfully. 

The master table is written to the dump file set as the last step of the export dump operation and is removed from the user’s schema. For the import dump operation, the master table is loaded from the dump file set to the user’s schema as the first step and is used to sequence the objects being imported.

Data Pump Processes

All Data Pump work is done though jobs. Data Pump jobs, unlike DBMS jobs, are merely server processes that process the data on behalf of the main process. The main process, known as a master control process, coordinates this effort via Advanced Queuing; it does so through a special table created at runtime known as a master table.

Page 37: 11gR2 ASMCMD Commands

Client process: This process is initiated by the client utility: expdp,impdp, or other clients to make calls to the Data Pump API. Since the Data Pump is completely integrated to the database, once the Data Pump job is initiated, this process is not necessary for the progress of the job. 

Shadow process: When a client logs into the Oracle database, a foreground process is created (a standard feature of Oracle). This shadow process services the client data dump API requests. This process creates the master table and creates Advanced Queuing (AQ) queues used for communication. Once the client process is ended, the shadow process also goes away. 

Master control process (MCP): Master control process controls the execution of the Data Pump job; there is one MCP per job. MCP divides the Data Pump job into various metadata and data load or unload jobs and hands them over to the worker processes. The MCP has a process name of the format ORACLE_SID_DMnn_PROCESS_ID. It maintains the job state, job description, restart, and file information in the master table. 

Worker process: The MCP creates the worker processes based on the value of the PARALLEL parameter. The worker process performs the tasks requested by MCP, mainly loading or unloading data and metadata. The worker processes have the format ORACLE_SID_DWnn_PROCESS_ID. The worker processes maintain the current status in the master table that can beused to restart a failed job. 

Parallel Query (PQ) processes: The worker processes can initiate parallel query processes if external table is used as the data access method for loading or unloading. These are standardparallel query slaves of the parallel execution architecture.

 Data Pump Benefits

Data access methods:– Direct path– External tables 

Detachment from and reattachment to long-running jobs  Restarting of Data Pump jobs  Fine-grained object and data selection  Explicit database version specification  Parallel execution  Estimation of export job space consumption  Network mode in a distributed environment: the data pump operations can be performed from one 

database to another without writing to a dump file, using the network method.  Remapping capabilities during import  Data sampling and metadata compression

 Create Data Pump Directory

Since the Data Pump is server based, directory objects must be created in the database where theData Pump files will be stored. 

The user executing Data Pump must have been granted permissions on the directory. READ permission is required to perform import, and WRITE permission is required to perform export and to create log files or SQL files. 

The user (who owns the software installation and database files) must have READ and WRITE operating system privileges on the directory. BUT the database user does NOT need any operating system privileges on the directory for Data Pump to succeed.

SQL> SELECT * FROM dba_directories;

SQL> CREATE OR REPLACE DIRECTORY data_pump_dir AS 'c:\temp';-- Set up default directory data_pump_dir (The name of the default directory must be DATA_PUMP_DIR)

Page 38: 11gR2 ASMCMD Commands

SQL> CREATE OR REPLACE DIRECTORY dpdata AS '';

SQL> GRANT READ, WRITE ON DIRECTORY dpdataTO scott;

Export Modes

1. Full

expdp \'/ as sysdba\'  DIRECTORY=dpdata DUMPFILE=exp%U.dmp FULL=y LOGFILE=exp.log JOB_NAME=expdp PARALLEL=30

2. User (Owner)

expdp \'/ as sysdba\'  DIRECTORY=dpdata DUMPFILE=scott.dmp SCHEMAS=scott LOGFILE=exp.log JOB_NAME=expdp

3. Table

expdp \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=scott.dmp TABLES=scott.emp,blake.dept LOGFILE=exp.log JOB_NAME=expdp

4. Tablespace

expdp \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=exp.dmp TABLESPACES=users, tools TRANSPORT_FULL_CHECK=y LOGFILE=exp.log JOB_NAME=expdp

5. Transportable Tablespace Export

ALTER TABLESPACE users READ ONLY;ALTER TABLESPACE example READ ONLY;

expdp \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=exp_tbs.dmpTRANSPORT_TABLESPACES=users,example TRANSPORT_FULL_CHECK=y LOGFILE=exp_tbs.log

ALTER TABLESPACE users READ WRITE;ALTER TABLESPACE example READ WRITE;

6. Export metadata

expdp \'/ as sysdba\' SCHEMAS=scott DIRECTORY=dpdata DUMPFILE=meta.dmp CONTENT=metadata_only

Page 39: 11gR2 ASMCMD Commands

 

Import Modes

1. Full

impdp  \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=exp.dmp FULL=y LOGFILE=imp.log JOB_NAME=impdpimpdp \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=exp%U.dmp FULL=y LOGFILE=imp.log JOB_NAME=DMFV_impdp PARALLEL=30

2. User (Owner)

impdp  \'/ as sysdba\'  DIRECTORY=dpdata DUMPFILE=scott.dmp SCHEMAS=scott LOGFILE=imp.log JOB_NAME=impdp

3. Table 

impdp \'/ as sysdba\' DIRECTORY=dpdata DUMPFILE=scott.dmp TABLES=scott.emp,blake.dept LOGFILE=imp.log JOB_NAME=impdp

4. Tablespace

5. Transportable Tablespace

 

Other Features

REMAP_DATAFILE

REMAP_SCHEMA

REMAP_TABLESPACE

TRANSFORM

NETWORK_LINK

Data Pump Monitoring

1. Script:

@dpstatus.sql

Page 40: 11gR2 ASMCMD Commands

2. DBA_DATAPUMP_JOBS

how many worker processes (column DEGREE) are working on the job.

3. DBA_DATAPUMP_SESSIONS

when joined with the previous view and V$SESSION gives the SID of the session of the main foreground process.

SQL> select sid, serial# from v$session s, dba_datapump_sessions d where s.saddr = d.saddr;

4. Alert log

When the process starts up, the MCP and the worker processes are shown in the alert log as follows:kupprdp: master process DM00 started with pid=23, OS id=20530 to execute -   SYS.KUPM$MCP.MAIN('CASES_EXPORT', 'ANANDA');kupprdp: worker process DW01 started with worker id=1, pid=24, OS id=20532 to execute - SYS.KUPW$WORKER.MAIN('CASES_EXPORT', 'ANANDA');

kupprdp: worker process DW03 started with worker id=2, pid=25, OS id=20534 to execute - SYS.KUPW$WORKER.MAIN('CASES_EXPORT', 'ANANDA');

5. V$SESSION_LONGOPS

predict the time it will take to complete the job.

select sid, serial#, sofar, totalwork from v$session_longops where sofar != totalwork;

Controlling Data Pump Jobs

1. Switching Between Logging and Interactive Client Mode:

expdp system/oracle parfile=c:\rmancmd\longexport.dpectl

1.1 switch this job to interactive client mode by typing CTRL-C1.2 switch from interactive client mode back to logging mode

Export> CONTINUE_CLIENT

2.Viewing Job Status:

From interactive mode

Export> status

Page 41: 11gR2 ASMCMD Commands

3. Closing and Reattaching To A Job

3.1 detach from a client session, but leave a running job still executing

Export> exit_client

3.2 reattach to a running job after closing the client connection, reopen a session by

$ expdp system/oracle attach=longexport

4. Halt the execution of the job:

Export> stop_job

restart the job:

Export> START_JOB

5. End the job

Export> kill_job

Transportable Tablespaces

Limitations

COMPATIBLE parameter set to 10.0.0 or higher on both source and target databases The databases must use the same database character set and national character set. Characterset conversion is not possible in transportable tablespaces.

A limitation exists on the CLOB datatype columns created prior to Oracle 10g (applicableonly if the database was upgraded from an earlier release). RMAN does not convert the CLOBdata; the application must take care of the conversion if any is required.

Steps

1.  Check Endian format

Determine if the platforms use the same Endian format by querying the V$TRANSPORTABLE_PLATFORM in the source and target databases:

Page 42: 11gR2 ASMCMD Commands

SQL> select a.platform_id, a.platform_name, endian_format  from v$transportable_platform a, v$database bwhere a.platform_id = b.platform_id;

PLATFORM_ID PLATFORM_NAME ENDIAN_FOR----------- -------------------------- ----------10 Linux IA (32-bit) Little

2. Check self-contained tablespaces

 Ensure the tablespaces to be transported are self-contained. Use the DBMS_TTS.TRANSPORT_SET_CHECK procedure to determine this. For example:SQL> EXEC DBMS_TTS.TRANSPORT_SET_CHECK( 'SALES_DATA,SALES_INDEX',TRUE);

 

3. Read-only tablespaces in source database

Make the tablespaces to be transported read-only in the source database.SQL> ALTER TABLESPACE SALES_DATA READ ONLY;SQL> ALTER TABLESPACE SALES_INDEX READ ONLY;

 

4. Export metadata

Use the expdp utility to unload the metadata information for the tablespaces to be transported.$ expdp system DUMPFILE=sales_tts.dmp LOGFILE=sales_tts.log DIRECTORY=dumplocation TRANSPORT_FULL_CHECK=Y TRANSPORT_TABLESPACES=SALES_DATA,SALES_INDEX

 

5.  RMAN conversion (optinonal)

In step 1, if we have determined that the Endian formats are same for the platforms, youcan skip this step and proceed to step 6. If the Endian formats are different, the datafilesneed to be converted using RMAN.To convert the datafiles from the little-Endian format (Linux) to the big-Endian format(Sun Solaris), do the following:$ rman target /RMAN> CONVERT TABLESPACE 'sales_data, sales_index'2> TO PLATFORM 'Solaris[tm] OE (64-bit)'3> DB_FILE_NAME_CONVERT =

Page 43: 11gR2 ASMCMD Commands

4> '/oradata/BT10GNF1/sales_data01.dbf',5> '/tmp/sales_data01_sun.dbf',6> '/oradata/BT10GNF1/sales_index01.dbf',7> '/tmp/sales_index01_sun.dbf';If you decide to convert the datafiles at the target platform, you can do so—just replace line2 with FROM_PLATFORM 'Linux IA (32-bit)'.

6. Import metadata

Use operating system utilities to copy the converted datafiles and the metadata dump file tothe target server. Use the impdp utility on the target to import the metadata and plug-in thetablespaces. The target user must already exist in the target database, if not, you can make theobjects owned by an existing user using the REMAP_SCHEMA parameter, as shown here:$impdp system DUMPFILE=sales_tts.dmpLOGFILE=sales_tts_imp.log DIRECTORY=data_dump_dirTRANSPORT_DATAFILES='/oradata/SL10H/sales_data01.dbf','/oradata/SL10H/sales_index01.dbf'

7. Read-write tablespace in target database

 Make the new tablespaces read-write in the target database, like so:SQL> ALTER TABLESPACE SALES_DATA READ WRITE;SQL> ALTER TABLESPACE SALES_INDEX READ WRITE;

Backup Sample Scripts and Examples

Page 44: 11gR2 ASMCMD Commands

RMAN online full backup to disk

1. Backup as backupsets

connect target /set echo onrun {allocate channel channel1 type disk;

backupFILESPERSET 5format '/backup/%d_t%t_s%s_FULL'(database)CURRENT CONTROLFILE SPFILE;

BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/backup/control01.ctl';

SQL "alter system archive log current";

backupformat 'ALO_%d_%s_%t'(archivelog all);

release channel channel1;SQL "ALTER DATABASE BACKUP CONTROLFILE TO TRACE";}

2. Backup as image copy

connect target /set echo onrun {allocate channel channel1 type disk;

backupas copyformat '/backup/%U'(database)CURRENT CONTROLFILE SPFILE;

BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/backup/control01.ctl';

SQL "alter system archive log current";

Page 45: 11gR2 ASMCMD Commands

backup as copyformat '/backup/ALO_%d_%s_%t'(archivelog all);

release channel channel1;SQL "ALTER DATABASE BACKUP CONTROLFILE TO TRACE";}

RMAN offline full backup to disk

1. Backup as backupsets

connect target /run {shutdown immediate;startup force DBA;shutdown immediate;startup mount;allocate channel channel1 type DISK;

backup FILESPERSET 8 format '/backup/%d_t%t_s%s_OFFLINE'(database)CURRENT CONTROLFILE SPFILE;

BACKUP CURRENT CONTROLFILE FORMAT '/backup/cntrlfile.copy';BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/backup/control01.ctl';

release channel channel1;

shutdown immediate;startup;

SQL "ALTER DATABASE BACKUP CONTROLFILE TO TRACE";}

2. Backup as image copy

connect target /run {shutdown immediate;startup force DBA;

Page 46: 11gR2 ASMCMD Commands

shutdown immediate;startup mount;allocate channel channel1 type DISK;

backup as copy format '/backup/%U'(database)CURRENT CONTROLFILE SPFILE;

BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/backup/control01.ctl';

release channel channel1;

shutdown immediate;startup;

SQL "ALTER DATABASE BACKUP CONTROLFILE TO TRACE";}

RMAN backup schell script for RAC (two nodes example)Adapted from Alejandro Vargas's blog

#!/usr/bin/ksh# rman_backup_as_copy_to_FS

export v_inst1=racdbtst1export v_inst2=racdbtst2

# Rman Backup Location variable# -----------------------------export v_rman_loc=/vmasmtest/BACKUP/rman_backups

# Step 1: Administrative tasks, crosscheck and delete obsolete# ------------------------------------------------------------export ORACLE_SID=$v_inst1rman target / nocatalog <<EOFcrosscheck backupset;crosscheck copy;crosscheck archivelog all;delete noprompt expired backup ;delete noprompt obsolete;exitEOF

Page 47: 11gR2 ASMCMD Commands

# This script run from 1st node. We use an external identified DBA user, ops$oracle, to execute# the archive log current. From the same session we connect as ops$oracle into the 2nd instance# You need remote_os_authent=TRUE on both instances to connect remotely without password# Step 2: Archive log current on 1st Instance# Step 3: Archive log current on 2nd Instance# -------------------------------------------sqlplus -s /@$v_inst1 << EOFselect instance_name from v\$instance/alter system archive log current/connect /@$v_inst2;select instance_name from v\$instance/alter system archive log current/exitEOF

# On step 4 we use 4 channels. This needs to be customized according the number of cpu's/IO# channels available. Rman is invoked in nocatalog mode, we need to have configured# ORACLE_HOME, ORACLE_SID and PATH on the environment, as we did in the previous steps.# Step 4: Rman backup as copy to file system including controlfile and archivelogs# --------------------------------------------------------------------------------rman target / nocatalog <<EOFrun {allocate channel backup_disk1 type disk format '$v_rman_loc/%U';allocate channel backup_disk2 type disk format '$v_rman_loc/%U';backup as COPY tag '%TAG' database include current controlfile;release channel backup_disk1;release channel backup_disk2;}exitEOF

# Step 5 and 6: Archive log current on 1st and 2nd Instances# ----------------------------------------------------------sqlplus -s /@$v_inst1 << EOFselect instance_name from v\$instance

Page 48: 11gR2 ASMCMD Commands

/alter system archive log current/connect /@$v_inst2;select instance_name from v\$instance/alter system archive log current/exitEOF

# Step 7: Rman backup as copy archivelogs not backed up and print backupset list to logrman target / nocatalog <<EOFbackup as copy archivelog all format '$v_rman_loc/%d_AL_%T_%u_s%s_p%p' ;list backupset;exitEOF# Redirecting rman output to log will suppress standard output, because of that# running separately.rman target / nocatalog log=$v_rman_loc/backupset_info.log <<EOFlist backup summary;list backupset;list backup of controlfile;exitEOF# eof rman_backup_as_copy_to_FS

Notes:1. Add the similar entries to tnsnames.ora if necessary

upgrade1 =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = upgrade.world)      (INSTANCE_NAME = upgrade1)    )  )

upgrade2 =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521))    (CONNECT_DATA =

Page 49: 11gR2 ASMCMD Commands

      (SERVER = DEDICATED)      (SERVICE_NAME = upgrade.world)      (INSTANCE_NAME = upgrade2)    )  )

2. Change login as following if necessary:sqlplus -s system/<password>@$v_inst1 << EOF

Recovery scripts and examples

RMAN recover database

connect target /RUN {shutdown immediate;startup mount;restore database;recover database;alter database open;}

connect target /RUN {shutdown immediate;startup nomount;set controlfile autobackup format for device type disk to '/db1/orabackup/%F';restore controlfile from autobackup;mount database;restore database;recover database;alter database open;}

RMAN recover tablespace

Page 50: 11gR2 ASMCMD Commands

connect target /RUN {sql "alter tablespace sysaux offline";RESTORE TABLESPACE sysaux;;RECOVER TABLESPACE sysaux;SQL "alter tablespace sysaux online";}

RMAN recover data file

connect target /RUN {sql "alter tablespace sysaux offline";restore datafile 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\NICK\SYSAUX01.DBF'; recover datafile 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\NICK\SYSAUX01.DBF';SQL "alter tablespace sysaux online";}

RMAN Point-In-Time-Recovery database (incomplete recovery)

Until SCN:

connect target /RUN{RESTORE DATABASE;RECOVER DATABASE UNTIL SCN 1000; # recovers through SCN 999 or ALTER DATABASE OPEN RESETLOGS;}

Until Time:

export NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'

connect target /RUN{set until time '28-JUL-05 06:00:00';Restore database;Recover database;sql "alter database open reset logs";}

Page 51: 11gR2 ASMCMD Commands

Until Log Seq:

This example assumes that log sequence 1234 was lost due to a disk failure and the database needs to be recovered by using available archived redo logs.

RUN{  SET UNTIL SEQUENCE 1234 THREAD 1;  RESTORE CONTROLFILE TO '?/oradata/cf.tmp';  RESTORE CONTROLFILE FROM '?/oradata/cf.tmp'; # restores to all CONTROL_FILES locations  ALTER DATABASE MOUNT;  RESTORE DATABASE;  RECOVER DATABASE;  # recovers through log 1233  ALTER DATABASE OPEN RESETLOGS;  # you must add new tempfiles to locally-managed temporary tablespaces after restoring  # a backup control file  SQL "ALTER TABLESPACE temp ADD TEMPFILE ''?/oradata/trgt/temp01.dbf'' REUSE";}

RMAN restore control file

See also here1. Shut down the database and try to start it up. The instance will start and try to mount the database, but when it doesn’t find the control files, the database fails to mount:

RMAN> SHUTDOWN IMMEDIATE;database closeddatabase dismountedOracle instance shut downRMAN> STARTUPOracle instance startedRMAN-00571:RMAN-00569: ERROR MESSAGE STACK FOLLOWSRMAN-00571:RMAN-03002: failure of startup command at 07/11/2005 17:18:05ORA-00205: error in identifying controlfile, check alert log for more info

You can avoid the preceding error messages by using the alternative command STARTUP NOMOUNT:

Page 52: 11gR2 ASMCMD Commands

RMAN> SHUTDOWN IMMEDIATE;RMAN> STARTUP NOMOUNT;

2. Issue the RESTORE CONTROLFILE command so RMAN can copy the control file backups to their default locations specified in the init.ora file:

RMAN> RESTORE CONTROLFILE;

3. After the restore is over, mount the database:

RMAN> ALTER DATABASE MOUNT;

4. Recover the database:

RMAN> RECOVER DATABASE;

5. Because RMAN restores the control files from its backups, you have to open the database with the RESETLOGS option:

RMAN> ALTER DATABASE OPEN RESETLOGS;

RMAN tablespace Point-In-Time-Recovery (TSPITR)

THIS PROCEDURE WILL RECOVER THE TABLESPACE IN AUX INSTANCE FIRST AND TRANSFER DATA TO TARGET IN ONE RMAN STEPDON'T USE THIS PROCEDURE, IF YOU DON'T WANT TO OVERWRITE TARGET TABLESPACE DATA!!!!

Recover the tablespaces from the database (the target database) by first performing the PITR in a temporary instance called the auxiliary database, which is created solely to serve as the staging area for the recovery of the tablespaces.

Here’s how to use RMAN to perform a TSPITR:

1. Create the auxiliary database. Use a skeleton initialization parameter file for the auxiliary instance along the lines of the following:

Page 53: 11gR2 ASMCMD Commands

db_name=help (this is the target database_name)db_file_name_convert=('/oraclehome/oradata/target/', '/tmp/')/* Lets you convert the target database data files to a different name */log_file_name_convert=('/oraclehome/oradata/target/redo', '/tmp/redo')/* Lets you convert the target database redo log files to a different name. */instance_name=auxcontrol_files=/tmp/control1.ctlcompatible=10.0.2db_block_size=8192

2. Start up the auxiliary database in the nomount mode:

$ sqlplus /nologSQL> CONNECT sys/oracle@aux AS sysdbaSQL> STARTUP NOMOUNT PFILE = /tmp/initaux.ora

3. Generate some archived redo logs and back up the target database. You can use the ALTER SYSTEM SWITCH LOGFILE command to produce the archived redo log files.

4. Connect to all three databases—the catalog, target, and auxiliary databases—as follows:

$ rman target sys/sys_passwd@targetdb catalog rman/rman@rmandb auxiliary system/oracle@aux

5. Perform a TSPITR. If you want to recover until a certain time, for example, you can use the following statement (assuming your NLS_DATE format uses the following format mask: Mon DD YYYY HH24:MI:SS):

RMAN> RECOVER TABLESPACE users UNTIL TIME ('JUN 30 2005 12:00:00');

This is a deceptively simple step, but RMAN performs a number of tasks in this step. It restores the data files in the users tablespace to the auxiliary database and recovers them to the time you specified. It then exports the metadata about the objects in the tablespaces from the auxiliary to the target database. RMAN also uses the SWITCH command to point the control file to the newly recovered data files.

6. Once the recovery is complete, bring the user tablespace online:

$ rman target sys/sys_passwd@targetdbRMAN> SQL "alter tablespace users online";

Page 54: 11gR2 ASMCMD Commands

RMAN> Exit;

7. Shut down the auxiliary instance and remove all the control files, redo log files, and data files pertaining to the auxiliary database.

RMAN restore and recover a non-archivelog database from a full (cold) backup

Source: http://www.idevelopment.info/

In this case study, (running in no-archivelog mode), any user error or media failure would require a complete database recovery. You can, however, use the SET UNTIL command to recover to different points in time when incrementals are taken. (Keep in mind that in our example, we did not make use of incremental backups!)

NOTE: Because redo logs are not archived, only full and incremental backups (if you were taking incremental backups) are available for restore and recovery.

It is assumed that you have all the configuration files like:

    * Server parameter file (spfile - equivalent of init.ora in 9i)    * tnsnames.ora    * listener.ora    * sqlnet.ora (optional) 

are all in their appropriate places. It is also assumed that you can startup the Oracle instance in NOMOUNT MODE and connect from RMAN to the target instance.

The steps are:

   1. If not using a recovery catalog, or if the database name is ambiguous in, you need to start RMAN and set the DBID before restoring the controlfile from autobackup.   2. Startup database in NOMOUNT mode. (You should have restored the initialization file for database, and listener files [only if connecting over SQLNET].)   3. Restore controlfile.   4. Mount the database.   5. Restore all database files.   6. Apply all incrementals. (In this example, we are not taking incremental backups, so this step is not required.)   7. Open database with RESETLOGS mode to re-create the online log files.

Page 55: 11gR2 ASMCMD Commands

   8. You will need to manually add any tempfiles back to the database after recovering the database.

set dbid 2528050866;

connect target /;startup nomount;

run {  # -----------------------------------------------------------  # Uncomment the SET UNTIL command to restore database to the  # incremental backup taken two days ago.  # SET UNTIL TIME 'SYSDATE-2';  # -----------------------------------------------------------  set controlfile autobackup format for device type disk to '/orabackup1/rman/TARGDB/%F';  restore controlfile from autobackup;  alter database mount;  restore database;  recover database noredo;  alter database open resetlogs;  sql "alter tablespace temp add tempfile ''/u06/app/oradata/TARGDB/temp01.dbf''       size 500m autoextend on next 500m maxsize 1500m";}

exit

NOTE: Tempfiles are automatically excluded from RMAN backups. This requires them to be re-added at recovery time.

RAC Recovery Scripts and Examples

Page 56: 11gR2 ASMCMD Commands

Restore and recover the database - complete recovery

1. Take the database out of cluster mode

SQL> shutdown abortSQL> startup no mountSQL> alter system set cluster_database=false scope=spfile sid='*';SQL> shutdown abort/immeidate

2. Restore the database via RMAN:

rman target=/RMAN> startup mount;RMAN> restore database;

3. Recover the Database

RMAN> recover database;RMAN> alter database open;

4. Place the database back into cluster mode and startup both instances:

# sqlplus "/ as sysdba"SQL> alter system set cluster_database=true scope=spfile sid='*';SQL> shutdown immediate;# srvctl start database -d em[oracle@rac1 bdump]$ srvctl status database -d emInstance em1 is running on node rac1Instance em2 is running on node rac2

Restore and recover the Database using recovered control file -- incomplete/point in time recovery

1. Take the database out of cluster mode

SQL> shutdown abortSQL> startup nomountSQL> alter system set cluster_database=false scope=spfile sid='*';SQL> shutdown abort/immeidate

2. Check the backup files and take note of the Database ID

rman target / nocatalogRMAN> set dbid=519338572  --find dbid by checking backup log or file name

Page 57: 11gR2 ASMCMD Commands

RMAN> startup nomount;

3.  Restore the controlfile from a time previous to the crash:

RMAN> list backup of controlfile;RMAN> restore controlfile from '/vmasmtest/BACKUP/rman_backups/cf_D-RACDBTST_id-519338572_6ei8vq5p';RMAN> mount database;

4.  Set until which time we want to recover, using the 'set until time' clause, the we do restore and recover, in this example the three commands are passed to Rman within a single block:

RMAN> run { set until time="to_date('01-FEB-07 16:14:28','DD-MON-YY HH24:MI:SS')";2> restore database;3> recover database; }

5. Once recover finish we open using restlogs option:

RMAN> alter database open RESETLOGS;RMAN> exitRecovery Manager complete.

6. Finally we need to establish Cluster Mode and open both instances.

1)Mount instance 1 and set cluster_database=true :

SQL> show parameters cluster_databaseSQL> alter system set cluster_database=true scope=spfile sid='*';SQL> shutdown immediate

2) Restart the database in cluster Mode:

srvctl start database -d racdbtstsrvctl start service -d racdbtstcrs_stat –t

3) Check restore point on test table:

SQL> select * from restable1;

Page 58: 11gR2 ASMCMD Commands

Start Grid Control

Run start_grid.sh

Content of start_grid.sh:

#!/bin/kshexport ORACLE_SID=GRIDexport ORACLE_HOME=/u01/app/oracle/product/10.2.0/oms10gexport PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/opmn/binexport LD_LIBRARY_PATH=$ORACLE_HOME/lib/u01/app/oracle/product/10.2.0/oms10g/bin/emctl start oms/u01/app/oracle/product/10.2.0/oms10g/opmn/bin/opmnctl startall/u01/app/oracle/product/10.2.0/oms10g/bin/emctl start iasconsole export ORACLE_SID=AGENTexport ORACLE_HOME=/u01/app/oracle/product/10.2.0/agent10gexport TNS_ADMIN=/u01/app/oracle/product/10.2.0/agent10g/network/adminexport PATH=$ORACLE_HOME/bin:$PATH/u01/app/oracle/product/10.2.0/agent10g/bin/emctl start agent

Stop Grid Control

Run stop_grid.sh

Content of stop_grid.sh:

#!/bin/kshexport ORACLE_SID=GRIDexport ORACLE_HOME=/u01/app/oracle/product/10.2.0/oms10gexport PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/opmn/binexport LD_LIBRARY_PATH=$ORACLE_HOME/lib/u01/app/oracle/product/10.2.0/oms10g/bin/emctl stop oms/u01/app/oracle/product/10.2.0/oms10g/bin/emctl stop iasconsole/u01/app/oracle/product/10.2.0/oms10g/opmn/bin/opmnctl stopall export ORACLE_SID=AGENTexport ORACLE_HOME=/u01/app/oracle/product/10.2.0/agent10gexport PATH=$ORACLE_HOME/bin:$PATH/u01/app/oracle/product/10.2.0/agent10g/bin/emctl stop agentexit

Page 59: 11gR2 ASMCMD Commands

 

OMS Commands

emctl start omsemctl stop omsemctl status oms

EM Console Commands for Application Server

emctl start ememctl stop ememctl status em

OEM Agent Commands

emctl start agentemctl stop agentemctl status agent

Grid Control and Agent logs

ORACLE_HOME/sysman/log/AGENT_HOME/sysman/log/

DB Control Repository

Create dbconsole repository

/u01/app/oracle/product/10.2.0/db_1/bin/emca -config dbcontrol db -repos create

Drop dbconsole repository

/u01/app/oracle/product/10.2.0/db_1/bin/emca -config dbcontrol db -repos drop

Recreate dbconsole repository

/u01/app/oracle/product/10.2.0/db_1/bin/emca -config dbcontrol db -repos recreate

Reconfigure dbconsole repository

Page 60: 11gR2 ASMCMD Commands

Problem: Clone and rename the db to another host and dbconsole won't start with error $ emctl start dbconsoleOC4J Configuration issue. /u01/app/oracle/product/10.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_<hostname>_<dbnname> not found.

Option 1

try <ORACLE_HOME>/bin/emca -deconfig dbcontrol db -repos recreate. If fails go to option 2.

Option 2

Step1. Login to SQLPLUS as user SYS or SYSTEM, and drop the sysman account & mangement objects: 

* Clean up the Db Console repository SQL> drop user sysman cascade; SQL> drop role MGMT_USER;SQL> drop user MGMT_VIEW cascade; SQL> drop public synonym MGMT_TARGET_BLACKOUTS; SQL> drop public synonym SETEMVIEWUSERCONTEXT;* issue a "commit;"

Step2. Export the correct values for the ORACLE_HOME and ORACLE_SID environment variables

Step3. Change directories to the $ORACLE_HOME/bin directory 

Step4. Cleanup the External DB Console Configuration files by issuing: 

emca -deconfig dbcontrol db -repos drop OR To delete the configurartion files:- remove the following directories from your filesystem:<ORACLE_HOME>/<hostname_sid> <ORACLE_HOME>/oc4j/j2ee/OC4J_DBConsole_<hostname>_<sid>

Step5. Recreate the DB Console Repository & external Configuration files by issuing: emca -config dbcontrol db -repos create 

Partition Methods

o Range Partitioningo List Partitioningo Hash Partitioningo Composite Partitioningo Invterval Partitioning

Page 61: 11gR2 ASMCMD Commands

o Reference Partitioningo Virtual column-based Partitioning (11g)

Partitioned Indexes

o Local Partitioned Indexeso Global Partitioned Indexes

Global Range Partitioned Indexes Global Hash Partitioned Indexes

o Global Nonpartitioned Indexes

Global Indexes vs Local Indexes

Just like partitioned tables, partitioned indexes improve manageability, availability, performance, and scalability. They can either be partitioned independently (global indexes) or automatically linked to a table's partitioning method (local indexes). In general, you should use global indexes for OLTP applications and local indexes for data warehousing or DSS applications. Also, whenever possible, you should try to use local indexes because they are easier to manage. When deciding what kind of partitioned index to use, you should consider the following guidelines in order:

1. If the table partitioning column is a subset of the index keys, use a local index. If this is the case, you are finished. If this is not the case, continue to guideline 2.

2. If the index is unique, use a global index. If this is the case, you are finished. If this is not the case, continue to guideline 3.

3. If your priority is manageability, use a local index. If this is the case, you are finished. If this is not the case, continue to guideline 4.

4. If the application is an OLTP one and users need quick response times, use a global index. If the application is a DSS one and users are more interested in throughput, use a local index.

5. RAC Commands Cheatsheet

6. Home >> Reference >> Oracle RAC >> RAC Commands Cheatsheet 7. http://www.dbaexpert.com/blog/2007/07/rac-cheatsheet/

8.  cluvfy

9. myrac1> cluvfy -h 10. USAGE: 11. cluvfy [ -help ] 12. cluvfy stage { -list | -help } 13. cluvfy stage {-pre|-post} <stage-name> <stage-specific options> [-verbose] 14. cluvfy comp { -list | -help } 15. cluvfy comp <component-name> <component-specific options> [-verbose] 16.  

Page 62: 11gR2 ASMCMD Commands

17. oifcfg

18. myrac1> oifcfg -help 19.  20. Name: 21. oifcfg - Oracle Interface Configuration Tool. 22.  23. Usage: oifcfg iflist [-p [-n]] 24. oifcfg setif {-node <nodename> | -global} {<if_name>/<subnet>:<if_type>}… 25. oifcfg getif [-node <nodename> | -global] [ -if <if_name>[/<subnet>] [-type <if_type>] ] 26. oifcfg delif [-node <nodename> | -global] [<if_name>[/<subnet>]] 27. oifcfg [-help] 28.  29. <nodename> - name of the host, as known to a communications network 30. <if_name> - name by which the interface is configured in the system 31. <subnet> - subnet address of the interface 32. <if_type> - type of the interface { cluster_interconnect | public | storage } 33.  

34. ocrconfig

35. myrac1> ocrconfig -help 36. Name: 37. ocrconfig - Configuration tool for Oracle Cluster Registry. 38. Synopsis: 39. ocrconfig [option] 40. option: 41. -export <filename> [-s online] 42. - Export cluster register contents to a file 43. -import <filename> - Import cluster registry contents from a file 44. -upgrade [<user> [<group>]] 45. - Upgrade cluster registry from previous version 46. -downgrade [-version <version string>] 47. - Downgrade cluster registry to the specified version 48. -backuploc <dirname> - Configure periodic backup location 49. -showbackup - Show backup information 50. -restore <filename> - Restore from physical backup 51. -replace ocr|ocrmirror [<filename>] - Add/replace/remove a OCR device/file 52. -overwrite - Overwrite OCR configuration on disk 53. -repair ocr|ocrmirror <filename> - Repair local OCR configuration 54. -help - Print out this help information 55.  

56. crs_stat

57. myrac1> crs_stat -h 58. Usage: crs_stat [resource_name [...]] [-v] [-l] [-q] [-c cluster_member]

Page 63: 11gR2 ASMCMD Commands

59. crs_stat [resource_name [...]] -t [-v] [-q] [-c cluster_member] 60. crs_stat -p [resource_name [...]] [-q] 61. crs_stat [-a] application -g 62. crs_stat [-a] application -r [-c cluster_member] 63. crs_stat -f [resource_name [...]] [-q] [-c cluster_member] 64. crs_stat -ls [resource_name [...]] [-q] 65.  

66. crs_register –u resname

67. crs_profile

68. crs_relocate

69. crs_start

70. crs_stop

71. crs_unregister

72.  

73. clscfg

74. myrac1> clscfg -h 75. clscfg: EXISTING configuration version 3 detected. 76. clscfg: version 3 is 10G Release 2. 77. clscfg — Oracle cluster configuration tool 78.  79. This tool is typically invoked as part of the Oracle Cluster Ready 80. Services install process. It configures cluster topology and other 81. settings. Use -help for information on any of these modes. 82. Use one of the following modes of operation. 83. -install - creates a new configuration 84. -upgrade - upgrades an existing configuration 85. -downgrade - downgrades an existing configuration 86. -add - adds a node to the configuration 87. -delete - deletes a node from the configuration 88. -local - creates a special single-node configuration for ASM 89. -concepts - brief listing of terminology used in the other modes 90.  91. -trace - may be used in conjunction with any mode above for tracing 92. WARNING: Using this tool may corrupt your cluster configuration. Do not 93. use unless you positively know what you are doing. 94.  

Page 64: 11gR2 ASMCMD Commands

95. crsctl

96. myrac1 > crsctl 97. Usage: crsctl check crs - checks the viability of the CRS stack 98. crsctl check cssd - checks the viability of CSS 99. crsctl check crsd - checks the viability of CRS 100. crsctl check evmd - checks the viability of EVM 101. crsctl set css <parameter> <value> - sets a parameter override 102. crsctl get css <parameter> - gets the value of a CSS parameter 103. crsctl unset css <parameter> - sets CSS parameter to its default 104. crsctl query css votedisk - lists the voting disks used by CSS 105. crsctl add css votedisk <path> - adds a new voting disk 106. crsctl delete css votedisk <path> - removes a voting disk 107. crsctl enable crs - enables startup for all CRS daemons 108. crsctl disable crs - disables startup for all CRS daemons 109. crsctl start resources - starts CRS resources. (start this first in 10g2)110. crsctl stop resources - stops CRS resources. 111. crsctl start crs - starts all CRS daemons. 112. crsctl stop crs - stops all CRS daemons. Stops CRS resources in case of

cluster. 113. crsctl debug statedump evm - dumps state info for evm objects 114. crsctl debug statedump crs - dumps state info for crs objects 115. crsctl debug statedump css - dumps state info for css objects 116. crsctl debug log css [module:level]{,module:level} … 117. - Turns on debugging for CSS 118. crsctl debug trace css - dumps CSS in-memory tracing cache 119. crsctl debug log crs [module:level]{,module:level} … 120. - Turns on debugging for CRS 121. crsctl debug trace crs - dumps CRS in-memory tracing cache 122. crsctl debug log evm [module:level]{,module:level} … 123. - Turns on debugging for EVM 124. crsctl debug trace evm - dumps EVM in-memory tracing cache 125. crsctl debug log res <resname:level> turns on debugging for resources 126. crsctl query crs softwareversion [<nodename>] - lists the version of CRS software

installed 127. crsctl query crs activeversion - lists the CRS software operating version 128. crsctl lsmodules css - lists the CSS modules that can be used for debugging 129. crsctl lsmodules crs - lists the CRS modules that can be used for debugging 130. crsctl lsmodules evm - lists the EVM modules that can be used for debugging 131.  132. If necesary any of these commands can be run with additional tracing by 133. adding a “trace” argument at the very front. 134. Example: crsctl trace check css

135. Clusterware check

136.  log files in $ORA_CRS_HOME/nodename

Page 65: 11gR2 ASMCMD Commands

137. Crsctl check crs 138. Crsctl check cssd 139. Crsctl check crsd 140. Crsctl check evmd 141. Crsctl query crs softwareversion 142. Crsctl query crs softwareversion node2 143. Crsctl start crs 144. Crsctl stop crs 145. Crsctl debug log res “resname:level” 146.  

147. Interconnect check:

148. Oifcfg getif 149. olsnodes

150. disable auto reboot of aix nodes /etc/init*

151. myrac1> ls -lrt /etc/init* 152. lrwxrwxrwx 1 root system 14 Feb 20 11:18 /etc/init -> /usr/sbin/init 153. -rw-r–r– 1 root system 2914 Feb 22 16:19 /etc/inittab.orig 154. -r-xr-xr-x 1 root system 3194 Feb 22 16:19 /etc/init.evmd 155. -r-xr-xr-x 1 root system 36807 Feb 22 16:19 /etc/init.cssd 156. -r-xr-xr-x 1 root system 4854 Feb 22 16:19 /etc/init.crsd 157. -r-xr-xr-x 1 root system 2226 Feb 22 16:19 /etc/init.crs 158. -rw-r–r– 1 root system 3093 Feb 22 21:58 /etc/inittab 159.  

160. OCR check:

161. Ocrcheck 162. Ocrconfig –export /tmp/dba/exp_ocr.dmp –s online 163. Ocrconfig –showbackup 164. ocrdump 165.  

166. VIP:

167. Ifconfig –a 168. Ifconfig en8 delete host1-vip 169. Ifconfig en8 delete host2-vip 170.   Command = /apps/oracle/product/10.2.0/CRS/bin/racgons add_config

ictcdb621:6200 ictcdb622:6200 171.   Command = /apps/oracle/product/10.2.0/CRS/bin/oifcfg setif -global

en8/10.249.199.0:public en9/172.16.32.0:cluster_interconnect 172.  

Page 66: 11gR2 ASMCMD Commands

173. srvctl

174. Set the SRVM_TRACE environment variable to debug srvctl: 175. $ export SRVM_TRACE=true

176.177. myrac1> srvctl -h 178. Usage: srvctl [-V] 179. Usage: srvctl add database -d <name> -o <oracle_home> [-m <domain_name>] [-

p <spfile>] [-A <name|ip>/netmask] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY}] [-s <start_options>] [-n <db_name>] [-y {AUTOMATIC | MANUAL}]

180. Usage: srvctl add instance -d <name> -i <inst_name> -n <node_name> 181. Usage: srvctl add service -d <name> -s <service_name> -r “<preferred_list>” [-a

"<available_list>"] [-P <TAF_policy>] 182. Usage: srvctl add service -d <name> -s <service_name> -u {-r “<new_pref_inst>”

| -a “<new_avail_inst>”} 183. Usage: srvctl add nodeapps -n <node_name> -o <oracle_home> -A

<name|ip>/netmask[/if1[|if2|...]] 184. Usage: srvctl add asm -n <node_name> -i <asm_inst_name> -o <oracle_home> [-

p <spfile>] 185. Usage: srvctl config database 186. Usage: srvctl config database -d <name> [-a] [-t] 187. Usage: srvctl config service -d <name> [-s <service_name>] [-a] [-S <level>] 188. Usage: srvctl config nodeapps -n <node_name> [-a] [-g] [-o] [-s] [-l] 189. Usage: srvctl config asm -n <node_name> 190. Usage: srvctl config listener -n <node_name> 191. Usage: srvctl disable database -d <name> 192. Usage: srvctl disable instance -d <name> -i “<inst_name_list>” 193. Usage: srvctl disable service -d <name> -s “<service_name_list>” [-i

<inst_name>] 194. Usage: srvctl disable asm -n <node_name> [-i <inst_name>] 195. Usage: srvctl enable database -d <name> 196. Usage: srvctl enable instance -d <name> -i “<inst_name_list>” 197. Usage: srvctl enable service -d <name> -s “<service_name_list>” [-i

<inst_name>] 198. Usage: srvctl enable asm -n <node_name> [-i <inst_name>] 199. Usage: srvctl getenv database -d <name> [-t "<name_list>"] 200. Usage: srvctl getenv instance -d <name> -i <inst_name> [-t "<name_list>"] 201. Usage: srvctl getenv service -d <name> -s <service_name> [-t "<name_list>"] 202. Usage: srvctl getenv nodeapps -n <node_name> [-t "<name_list>"] 203. Usage: srvctl modify database -d <name> [-n <db_name] [-o <ohome>] [-m

<domain>] [-p <spfile>] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY}] [-s <start_options>] [-y {AUTOMATIC | MANUAL}]

204. Usage: srvctl modify instance -d <name> -i <inst_name> -n <node_name> 205. Usage: srvctl modify instance -d <name> -i <inst_name> {-s <asm_inst_name> | -

r}

Page 67: 11gR2 ASMCMD Commands

206. Usage: srvctl modify service -d <name> -s <service_name> -i <old_inst_name> -t <new_inst_name> [-f]

207. Usage: srvctl modify service -d <name> -s <service_name> -i <avail_inst_name> -r [-f]

208. Usage: srvctl modify service -d <name> -s <service_name> -n -i <prefered_inst> [-a <available_list>] [-f]

209. Usage: srvctl modify asm -n <node_name> -i <asm_inst_name> -p <spfile> 210. Usage: srvctl relocate service -d <name> -s <service_name> -i <old_inst_name> -

t <new_inst_name> [-f] 211. Usage: srvctl remove database -d <name> [-f] 212. Usage: srvctl remove instance -d <name> -i <inst_name> [-f] 213. Usage: srvctl remove service -d <name> -s <service_name> [-i <inst_name>] [-f] 214. Usage: srvctl remove nodeapps -n “<node_name_list>” [-f] 215. Usage: srvctl remove asm -n <node_name> [-i <asm_inst_name>] [-f] 216. Usage: srvctl setenv database -d <name> {-t <name>=<val>[,<name>=<val>,...] |

-T <name>=<val>} 217. Usage: srvctl setenv instance -d <name> [-i <inst_name>] {-t

“<name>=<val>[,<name>=<val>,...]” | -T “<name>=<val>”} 218. Usage: srvctl setenv service -d <name> [-s <service_name>] {-t

“<name>=<val>[,<name>=<val>,...]” | -T “<name>=<val>”} 219. Usage: srvctl setenv nodeapps -n <node_name> {-t

“<name>=<val>[,<name>=<val>,...]” | -T “<name>=<val>”} 220. Usage: srvctl start database -d <name> [-o <start_options>] [-c <connect_str> | -

q] 221. Usage: srvctl start instance -d <name> -i “<inst_name_list>” [-o <start_options>]

[-c <connect_str> | -q] 222. Usage: srvctl start service -d <name> [-s "<service_name_list>" [-i <inst_name>]]

[-o <start_options>] [-c <connect_str> | -q] 223. Usage: srvctl start nodeapps -n <node_name> 224. Usage: srvctl start asm -n <node_name> [-i <asm_inst_name>] [-o

<start_options>] [-c <connect_str> | -q] 225. Usage: srvctl start listener -n <node_name> [-l <lsnr_name_list>] 226. Usage: srvctl status database -d <name> [-f] [-v] [-S <level>] 227. Usage: srvctl status instance -d <name> -i “<inst_name_list>” [-f] [-v] [-S

<level>] 228. Usage: srvctl status service -d <name> [-s "<service_name_list>"] [-f] [-v] [-S

<level>] 229. Usage: srvctl status nodeapps -n <node_name> 230. Usage: srvctl status asm -n <node_name> 231. Usage: srvctl stop database -d <name> [-o <stop_options>] [-c <connect_str> | -q] 232. Usage: srvctl stop instance -d <name> -i “<inst_name_list>” [-o <stop_options>]

[-c <connect_str> | -q] 233. Usage: srvctl stop service -d <name> [-s "<service_name_list>" [-i <inst_name>]]

[-c <connect_str> | -q] [-f] 234. Usage: srvctl stop nodeapps -n <node_name>

Page 68: 11gR2 ASMCMD Commands

235. Usage: srvctl stop asm -n <node_name> [-i <asm_inst_name>] [-o <stop_options>] [-c <connect_str> | -q]

236. Usage: srvctl stop listener -n <node_name> [-l <lsnr_name_list>] 237. Usage: srvctl unsetenv database -d <name> -t “<name_list>” 238. Usage: srvctl unsetenv instance -d <name> [-i <inst_name>] -t “<name_list>” 239. Usage: srvctl unsetenv service -d <name> [-s <service_name>] -t “<name_list>” 240. Usage: srvctl unsetenv nodeapps -n <node_name> -t “<name_list>

241. Check enable/disable the startup of the Oracle Clusterware daemons242.243. Oracle has scls_scr directory at /etc/oracle path. We can check about enable/disable startup status of the Oracle Clusterware daemons at crsstart file in /etc/oracle/scls_scr/<hostname>/root/ path.

root@rac1# cat /etc/oracle/scls_scr/rac1/root/crsstartenable

root@rac1# cd CRS_HOME/bin

root@rac1# ./crsctl disable crsroot@rac1# cat /etc/oracle/scls_scr/rac1/root/crsstartdisable

after disabled by "crsctl disable crs", crsstart file was changed be "disable"

root@rac1# ./crsctl enable crsroot@rac1# cat /etc/oracle/scls_scr/rac1/root/crsstartenable

after enabled by "crsctl enable crs", crsstart file was changed be "enable"

CRS RESOURCE STATUS

srvctl status database -d <database-name> [-f] [-v] [-S <level>]srvctl status instance -d <database-name> -i <instance-name> >[,<instance-name-list>] [-f] [-v] [-S <level>]srvctl status service -d <database-name> -s <service-name>[,<service-name-list>] [-f] [-v] [-S <level>]srvctl status nodeapps [-n <node-name>]srvctl status asm -n <node_name>

EXAMPLES:Status of the database, all instances and all services. 

Page 69: 11gR2 ASMCMD Commands

srvctl status database -d ORACLE -vStatus of named instances with their current services. srvctl status instance -d ORACLE -i RAC01, RAC02 -vStatus of a named services.srvctl status service -d ORACLE -s ERP -vStatus of all nodes supporting database applications.srvctl status node

START CRS RESOURCES

srvctl start database -d <database-name> [-o < start-options>] [-c <connect-string> | -q]srvctl start instance -d <database-name> -i <instance-name> [,<instance-name-list>] [-o <start-options>] [-c <connect-string> | -q]srvctl start service -d <database-name> [-s <service-name>[,<service-name-list>]] [-i <instance-name>] [-o <start-options>] [-c <connect-string> | -q]srvctl start nodeapps -n <node-name>srvctl start asm -n <node_name> [-i <asm_inst_name>] [-o <start_options>]

EXAMPLES:Start the database with all enabled instances. srvctl start database -d ORACLEStart named instances. srvctl start instance -d ORACLE -i RAC03, RAC04Start named services. Dependent instances are started as needed.srvctl start service -d ORACLE -s CRMStart a service at the named instance.srvctl start service -d ORACLE -s CRM -i RAC04Start node applications.srvctl start nodeapps -n myclust-4

STOP CRS RESOURCES

srvctl stop database -d <database-name> [-o <stop-options>] [-c <connect-string> | -q]srvctl stop instance -d <database-name> -i <instance-name> [,<instance-name-list>] [-o <stop-options>][-c <connect-string> | -q]srvctl stop service -d <database-name> [-s <service-name>[,<service-name-list>]] [-i <instance-name>][-c <connect-string> | -q] [-f]

Page 70: 11gR2 ASMCMD Commands

srvctl stop nodeapps -n <node-name>srvctl stop asm -n <node_name> [-i <asm_inst_name>] [-o <start_options>]

EXAMPLES:Stop the database, all instances and all services. srvctl stop database -d ORACLEStop named instances, first relocating all existing services. srvctl stop instance -d ORACLE -i RAC03,RAC04Stop the service.srvctl stop service -d ORACLE -s CRMStop the service at the named instances. srvctl stop service -d ORACLE -s CRM -i RAC04Stop node applications. Note that instances and services also stop.srvctl stop nodeapps -n myclust-4

ADD CRS RESOURCES

srvctl add database -d <name> -o <oracle_home> [-m <domain_name>] [-p <spfile>] [-A <name|ip>/netmask] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY}] [-s <start_options>] [-n <db_name>]srvctl add instance -d <name> -i <inst_name> -n <node_name>srvctl add service -d <name> -s <service_name> -r <preferred_list> [-a <available_list>] [-P <TAF_policy>] [-u]srvctl add nodeapps -n <node_name> -o <oracle_home> [-A <name|ip>/netmask[/if1[|if2|...]]]srvctl add asm -n <node_name> -i <asm_inst_name> -o <oracle_home>

OPTIONS:

-A vip range, node, and database, address specification. The format of address string is:[<logical host name>]/<VIP address>/<net mask>[/<host interface1[ | host interface2 |..]>] [,] [<logical host name>]/<VIP address>/<net mask>[/<host interface1[ | host interface2 |..]>] -a for services, list of available instances, this list cannot include preferred instances-m domain name with the format “us.mydomain.com”-n node name that will support one or more instances-o $ORACLE_HOME to locate Oracle binaries-P for services, TAF preconnect policy - NONE, PRECONNECT-r for services, list of preferred instances, this list cannot include available instances.

Page 71: 11gR2 ASMCMD Commands

-s spfile name-u updates the preferred or available list for the service to support the specified instance. Only one instance may be specified with the -u switch. Instances that already support the service should not be included.

EXAMPLES:Add a new node:srvctl add nodeapps -n myclust-1 -o $ORACLE_HOME –A 139.184.201.1/255.255.255.0/hme0Add a new database. srvctl add database -d ORACLE -o $ORACLE_HOMEAdd named instances to an existing database. srvctl add instance -d ORACLE -i RAC01 -n myclust-1srvctl add instance -d ORACLE -i RAC02 -n myclust-2srvctl add instance -d ORACLE -i RAC03 -n myclust-3Add a service to an existing database with preferred instances (-r) and available instances (-a). Use basic failover to the available instances.srvctl add service -d ORACLE -s STD_BATCH -r RAC01,RAC02 -a RAC03,RAC04Add a service to an existing database with preferred instances in list one and available instances in list two. Use preconnect at the available instances.srvctl add service -d ORACLE -s STD_BATCH -r RAC01,RAC02 -a RAC03,RAC04 -P PRECONNECT

REMOVE CRS RESOURCES

srvctl remove database -d <database-name> srvctl remove instance -d <database-name> [-i <instance-name>] srvctl remove service -d <database-name> -s <service-name> [-i <instance-name>] srvctl remove nodeapps -n <node-name>

EXAMPLES:Remove the applications for a database. srvctl remove database -d ORACLE Remove the applications for named instances of an existing database. srvctl remove instance -d ORACLE -i RAC03 srvctl remove instance -d ORACLE -i RAC04 Remove the service.srvctl remove service -d ORACLE -s STD_BATCHRemove the service from the instances.srvctl remove service -d ORACLE -s STD_BATCH -i RAC03,RAC04Remove all node applications from a node.

Page 72: 11gR2 ASMCMD Commands

srvctl remove nodeapps -n myclust-4

MODIFY CRS RESOURCES

srvctl modify database -d <name> [-n <db_name] [-o <ohome>] [-m <domain>] [-p <spfile>] [-r {PRIMARY | PHYSICAL_STANDBY | LOGICAL_STANDBY}] [-s <start_options>]srvctl modify instance -d <database-name> -i <instance-name> -n <node-name>srvctl modify instance -d <name> -i <inst_name> {-s <asm_inst_name> | -r}srvctl modify service -d <database-name> -s <service_name> -i <instance-name> -t <instance-name> [-f]srvctl modify service -d <database-name> -s <service_name> -i <instance-name> -r [-f]srvctl modify nodeapps -n <node-name> [-A <address-description> ] [-x]

OPTIONS:

-i <instance-name> -t <instance-name> the instance name (-i) is replaced by the instance name (-t)-i <instance-name> -r the named instance is modified to be a preferred instance-A address-list for VIP application, at node level-s <asm_inst_name> add or remove ASM dependency

EXAMPLES:Modify an instance to execute on another node.srvctl modify instance -d ORACLE -n myclust-4Modify a service to execute on another node.srvctl modify service -d ORACLE -s HOT_BATCH -i RAC01 -t RAC02Modify an instance to be a preferred instance for a service.srvctl modify service -d ORACLE -s HOT_BATCH -i RAC02 –r

RELOCATE SERVICES

srvctl relocate service -d <database-name> -s <service-name> [-i <instance-name >]-t<instance-name > [-f]

EXAMPLES:Relocate a service from one instance to another

Page 73: 11gR2 ASMCMD Commands

srvctl relocate service -d ORACLE -s CRM -i RAC04 -t RAC01

ENABLE CRS RESOURCES (The resource may be up or down to use this function)

srvctl enable database -d <database-name>srvctl enable instance -d <database-name> -i <instance-name> [,<instance-name-list>] srvctl enable service -d <database-name> -s <service-name>] [, <service-name-list>] [-i <instance-name>]

EXAMPLES:Enable the database. srvctl enable database -d ORACLEEnable the named instances. srvctl enable instance -d ORACLE -i RAC01, RAC02Enable the service. srvctl enable service -d ORACLE -s ERP,CRMEnable the service at the named instance.srvctl enable service -d ORACLE -s CRM -i RAC03

DISABLE CRS RESOURCES (The resource must be down to use this function)

srvctl disable database -d <database-name>srvctl disable instance -d <database-name> -i <instance-name> [,<instance-name-list>] srvctl disable service -d <database-name> -s <service-name>] [,<service-name-list>] [-i <instance-name>]

EXAMPLES:Disable the database globally. srvctl disable database -d ORACLEDisable the named instances. srvctl disable instance -d ORACLE -i RAC01, RAC02Disable the service globally. srvctl disable service -d ORACLE -s ERP,CRMDisable the service at the named instance.srvctl disable service -d ORACLE -s CRM -i RAC03,RAC04

Page 74: 11gR2 ASMCMD Commands

11gR2 RAC Commands

Page 75: 11gR2 ASMCMD Commands

SRVCTL CommandsSRVCTL is used to manage the following resources (components):

Component Abbreviation Descriptionasm                        asm                                Oracle ASM instancedatabase                 db                                  Database instancediskgroup               dg                                  Oracle ASM disk groupfilesystem               filesystem                       Oracle ASM file systemhome                       home                             Oracle home or Oracle Clusterware homelistener                    lsnr                                Oracle Net listenerservice                    serv                               Database serviceons, eons                ons, eons                       Oracle Notification Services (ONS)

The available commands used with SRVCTL are: Command Descriptionadd                 Adds a component to the Oracle Restart configuration.config            Displays the Oracle Restart configuration for a component.disable           Disables management by Oracle Restart for a component.enable            Reenables management by Oracle Restart for a component.getenv            Displays environment variables in the Oracle Restart configuration for a database, Oracle ASM instance, or listener.modify           Modifies the Oracle Restart configuration for a component.remove           Removes a component from the Oracle Restart configuration.setenv             Sets environment variables in the Oracle Restart configuration for a database, Oracle ASM instance, or listener.start                Starts the specified component.status             Displays the running status of the specified component.stop                Stops the specified component.unsetenv         Unsets environment variables in the Oracle Restart configuration for a database, Oracle ASM instance, or listener.

Commands Objects Comment

srvctl addsrvctl modifysrvctl remove

instancedatabaseservicenodeapps

The OCR is modified.

srvctl relocate service You can reallocate a service from one named instance to

Page 76: 11gR2 ASMCMD Commands

another named instance.

srvctl startsrvctl stopsrvctl status

instancedatabaseserviceasmnodeapps

srvctl disablesrvctl enable

instancedatabaseserviceasm

enable = when the server restart the resource must be restarted

disable = when the server restart the resource must NOT be restarted              (perhaps we are working for some maintenance tasks)

srvctl config

databaseserviceasmnodeapps

Lists configuration information from the OCR (Oracle Cluster Registry).

srvctl getenvsrvctl setenvsrvctl unsetenv

instancedatabaseservicenodeapps

srvctl getenv = displays the environment variables stored in the OCR for target. 

srvctl setenv    = allows these variables to be setsrvctl unsetenv = llows these variables to be unset

Frequently used commands: srvctl start database -d DBnamesrvctl stop database -d DBname  srvctl start instance -d DBname -i INSTANCEnamesrvctl stop instance -d DBname -i INSTANCEname srvctl start instance -d DBname -i INSTANCEnamesrvctl stop instance -d DBname -i INSTANCEname srvctl status database -d DBnamesrvctl status instance -d DBname -i INSTANCEnamesrvctl status nodeapps -n NODEname srvctl enable database -d DBnamesrvctl disable database -d DBname 

Page 77: 11gR2 ASMCMD Commands

srvctl enable instance -d DBname -i INSTANCEnamesrvctl disable instance -d DBname -i INSTANCEname srvctl config database -d DBname      -> to get some information about the database from OCR. srvctl getenv nodeaps 

CRSCTL CommandsDual Environment CRSCTL Commands:

    crsctl add resource    crsctl add type    crsctl check css    crsctl delete resource    crsctl delete type    crsctl get hostname    crsctl getperm resource    crsctl getperm type    crsctl modify resource    crsctl modify type    crsctl setperm resource    crsctl setperm type    crsctl start resource    crsctl status resource    crsctl status type    crsctl stop resource

Oracle RAC Environment CRSCTL Commands:The commands listed in this section manage the Oracle Clusterware stack in an Oracle RAC environment, which consists of the following:

Oracle Clusterware, the member nodes and server poolsOracle ASM (if installed)Cluster Synchronization ServicesCluster Time Synchronization Services

    crsctl add crs administrator    crsctl add css votedisk    crsctl add serverpool    crsctl check cluster

Page 78: 11gR2 ASMCMD Commands

    crsctl check crs    crsctl check resource    crsctl check ctss    crsctl config crs    crsctl delete crs administrator    crsctl delete css votedisk    crsctl delete node    crsctl delete serverpool    crsctl disable crs    crsctl enable crs    crsctl get css    crsctl get css ipmiaddr    crsctl get nodename    crsctl getperm serverpool    crsctl lsmodules    crsctl modify serverpool    crsctl pin css    crsctl query crs administrator    crsctl query crs activeversion    crsctl query crs releaseversion    crsctl query crs softwareversion    crsctl query css ipmidevice    crsctl query css votedisk    crsctl relocate resource    crsctl relocate server    crsctl replace discoverystring    crsctl replace votedisk    crsctl set css    crsctl set css ipmiaddr    crsctl set css ipmiadmin    crsctl setperm serverpool    crsctl start cluster    crsctl start crs    crsctl status server    crsctl status serverpool    crsctl stop cluster    crsctl stop crs    crsctl unpin css    crsctl unset css

Page 79: 11gR2 ASMCMD Commands

Oracle Restart Environment CRSCTL Commands:The commands listed in this section control Oracle High Availability Services.

    crsctl check has    crsctl config has    crsctl disable has    crsctl enable has    crsctl query has releaseversion    crsctl query has softwareversion    crsctl start has    crsctl stop has

 ATTENTION:The following commands are deprecated in Oracle Clusterware 11g release 2 (11.2):

crs_statcrs_registercrs_unregistercrs_startcrs_stopcrs_getpermcrs_profilecrs_relocatecrs_setperm

crsctl check crsdcrsctl check cssdcrsctl check evmdcrsctl debug logcrsctl set css votediskcrsctl start resourcescrsctl stop resources

CRSD:

Cluster Ready Services Daemon Engine for HA operation Manages 'application resources'

Page 80: 11gR2 ASMCMD Commands

Starts, stops, and fails 'application resources' over Spawns separate 'actions' to start/stop/check application resources Maintains configuration profiles in the OCR (Oracle Configuration Repository)- Stores

current known state in the OCR. Runs as root Is restarted automatically on failure

OCSSD:

Cluster Synchronization Services Daemon OCSSD is part of RAC and Single Instance with ASM Provides access to node membership Provides group services Provides basic cluster locking Integrates with existing vendor clusteware, when present Can also runs without integration to vendor clustware Runs as Oracle. Failure exit causes machine reboot. This is a feature to prevent data corruption in event of a split brain.

EVMD:

Event Management Daemon Generates events when things happen Spawns a permanent child evmlogger Evmlogger, on demand, spawns children Scans callout directory and invokes callouts Runs as Oracle Restarted automatically on failure

OPROCD

Process monitor for the cluster (not used on Linux and Windows) Starting with 10.2.0.4, it replace hangcheck timer module on Linux. If OPROCS fails,

clusterware will reboot the nodes.

LMS (Global Cache Services)

Enables copies of blocks to be transferred from one instance to another without writing to disk (cache fusion)

LMON (Global Enqueue Services Monitor)

Lock monitor, responsible for cluster reconfiguration and locks when an instance joins or leaves the cluster

Page 81: 11gR2 ASMCMD Commands

LMD (Global Enqueue Services daemon)

Lock Manager, manage requests for resources to control access to blocks

LCK0 (Instance Enqueue process)

Manages instance resource requests and cross-instance call operations for shared resources

DIAG (Diagnostic daemon)

Diagnostic needs for a RAC environment

TAF Database Configurations

TAF works with the following database configurations to effectively mask a database failure:

Oracle Real Application Clusters Replicated systems Standby databases Single instance Oracle database

See Also:

Oracle Real Application Clusters Installation and Configuration Guide

FAILOVER_MODE Parameters

The FAILOVER_MODE parameter must be included in the CONNECT_DATA section of a connect descriptor. FAILOVER_MODE can contain the subparameters described in Table 13-4 .

Table 13-4 Subparameters of the FAILOVER_MODE Parameter

FAILOVER_MODE Subparameter Description

BACKUP Specify a different net service name for backup connections. A backup should be specified when using preconnect to pre-establish connections.

TYPE Specify the type of failover. Three types of Oracle Net failover functionality are available by default to Oracle Call Interface (OCI) applications:

session: Set to failover the session. If a user's connection is lost, a new session is automatically created for the user on the backup. This type of failover does not attempt to recover selects.

Page 82: 11gR2 ASMCMD Commands

FAILOVER_MODE Subparameter Description

select: Set to enable users with open cursors to continue fetching on them after failure. However, this mode involves overhead on the client side in normal select operations.

none: This is the default. No failover functionality is used. This can also be explicitly specified to prevent failover from happening.

METHOD Determines how fast failover occurs from the primary node to the backup node:

basic: Set to establish connections at failover time. This option requires almost no work on the backup server until failover time.

preconnect: Set to pre-established connections. This provides faster failover but requires that the backup instance be able to support all connections from every supported instance.

RETRIES Specify the number of times to attempt to connect after a failover. If DELAY is specified, RETRIES defaults to five retry attempts.

Note: If a callback function is registered, then this subparameter is ignored.

DELAY Specify the amount of time in seconds to wait between connect attempts. If RETRIES is specified, DELAY defaults to one second.

Note: If a callback function is registered, then this subparameter is ignored.

Note:

Oracle Net Manager does not provide support for TAF parameters. These parameters must be manually added.

TAF Implementation

Important:

Do not set the    GLOBAL_DBNAME    parameter in the    SID_LIST_listener_name    section of the    listener.ora . A statically configured global database name disables TAF.

Page 83: 11gR2 ASMCMD Commands

Depending on the FAILOVER_MODE parameters, you can implement TAF in a number of ways. Oracle recommends the following methods:

Example: TAF with Connect-Time Failover and Client Load Balancing Example: TAF Retrying a Connection Example: TAF Pre-Establishing a Connection

Example: TAF with Connect-Time Failover and Client Load Balancing

Implement TAF with connect-time failover and client load balancing for multiple addresses. In the following example, Oracle Net connects randomly to one of the protocol addresses on sales1-server or sales2-server . If the instance fails after the connection, the TAF application fails over to the other node's listener, reserving any SELECT statements in progress.

sales.us.acme.com= (DESCRIPTION= (LOAD_BALANCE=on) (FAILOVER=on) (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (FAILOVER_MODE= (TYPE=select) (METHOD=basic))))

Example: TAF Retrying a Connection

TAF also provides the ability to automatically retry connecting if the first connection attempt fails with the RETRIES and DELAY parameters. In the following example, Oracle Net tries to reconnect to the listener on sales1-server . If the failover connection fails, Oracle Net waits 15 seconds before trying to reconnect again. Oracle Net attempts to reconnect up to 20 times.

sales.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (FAILOVER_MODE= (TYPE=select) (METHOD=basic) (RETRIES=20)

Page 84: 11gR2 ASMCMD Commands

(DELAY=15))))

Example: TAF Pre-Establishing a Connection

A backup connection can be pre-established. The initial and backup connections must be explicitly specified. In the following example, clients that use net service name sales1.us.acme.com to connect to the listener on sales1-server are also preconnected to sales2-server . If sales1-server fails after the connection, Oracle Net fails over to sales2- server , preserving any SELECT statements in progress. Likewise, Oracle Net preconnects to sales1-server for those clients that use sales2.us.acme.com to connect to the listener on sales2-server .

sales1.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_NAME=sales1) (FAILOVER_MODE= (BACKUP=sales2.us.acme.com) (TYPE=select) (METHOD=preconnect))))sales2.us.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_NAME=sales2) (FAILOVER_MODE= (BACKUP=sales1.us.acme.com) (TYPE=select) (METHOD=preconnect))))

TAF Verification

You can query FAILOVER_TYPE , FAILOVER_METHOD , and FAILED_OVER columns in the V$SESSION view to verify that TAF is correctly configured.

Use the V$SESSION view to obtain information about the connected clients and their TAF status. For example, query the FAILOVER_TYPE , FAILOVER_METHOD , and FAILED_OVER columns to verify that you have correctly configured TAF as in the following SQL statement:

SELECT MACHINE, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER, COUNT(*)FROM V$SESSION

Page 85: 11gR2 ASMCMD Commands

GROUP BY MACHINE, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER;

The output before failover resembles the following:

MACHINE FAILOVER_TYPE FAILOVER_M FAI COUNT(*)-------------------- ------------- ---------- --- ----------sales1 NONE NONE NO 11sales2 SELECT PRECONNECT NO 1

The output after failover is:

MACHINE FAILOVER_TYPE FAILOVER_M FAI COUNT(*)-------------------- ------------- ---------- --- ----------sales2 NONE NONE NO 10sales2 SELECT PRECONNECT YES 1

Note:

You can monitor each step of TAF using an appropriately configured    OCI TAF CALLBACK    function.   

See Also:

Oracle Call Interface Programmer's Guide Oracle Database Reference for more information about the V$SESSION view

Specifying the Instance Role for Primary and Secondary Instance Configurations

The INSTANCE_ROLE parameter is an optional parameter for the CONNECT_DATA section of a connect descriptor. It enables you to specify a connection to the primary or secondary instance of Oracle9i Real Application Clusters configurations.

This parameter is useful when:

You want to explicitly connect to a primary or secondary instance. The default is the primary instance.

You want to use TAF to preconnect to a secondary instance.

INSTANCE_ROLE supports the following values:

primary — Specifies a connection to the primary instance

secondary — Specifies a connection to the secondary instance

Page 86: 11gR2 ASMCMD Commands

any — Specifies a connection to whichever instance has the lowest load, regardless of primary or secondary instance role

Example: Connection to Instance Role Type

In the following example, net service name sales_primary enables connections to the primary instance, and net service name sales_secondary enables connections to the secondary instance.

sales_primary= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=primary)))sales_secondary= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=secondary)))

Example: Connection To a Specific Instance

There are times when Oracle Enterprise Manager and other system management products need to connect to a specific instance regardless of its role to perform administrative tasks. For these types of connections, configure ( INSTANCE_NAME=instance_name) and ( INSTANCE_ROLE=any) to connect to the instance regardless of its role.

In the following example, net service name sales1 enables connections to the instance on sales1-server and sales2 enables connections to the instance on sales2-server . (SERVER=dedicated) is specified to force a dedicated server connection.

sales1= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server)

Page 87: 11gR2 ASMCMD Commands

(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=any) (INSTANCE_NAME=sales2) (SERVER=dedicated)))sales2= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=any) (INSTANCE_NAME=sales2) (SERVER=dedicated)))

Example: TAF Pre-Establishing a Connection

If Transparent Application Failover (TAF) is configured, a backup connection can be pre-established to the secondary instance. The initial and backup connections must be explicitly specified. In the following example, Oracle Net connects to the listener on sales1-server and preconnects to sales2-server , the secondary instance. If sales1-server fails after the connection, the TAF application fails over to sales2-server , the secondary instance, preserving any SELECT statements in progress.

sales1.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales1-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=primary) (FAILOVER_MODE= (BACKUP=sales2.acme.com) (TYPE=select) (METHOD=preconnect))))sales2.acme.com= (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=sales2-server) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=sales.us.acme.com) (INSTANCE_ROLE=secondary)))

racandtaf

Page 88: 11gR2 ASMCMD Commands

RAC and TAFHome >> Reference >> Oracle RAC >> RAC and TAF

From http://www.dba-oracle.com/art_oramag_rac_taf.htm

Oracle RAC and Hardware Failover

To detect a node failure, the Cluster Manager uses a background process—Global Enqueue Service Monitor (LMON)—to monitor the health of the cluster. When a node fails, the Cluster Manager reports the change in the cluster's membership to Global Cache Services (GCS) and Global Enqueue Service (GES). These services are then remastered based on the current membership of the cluster.

To successfully remaster the cluster services, Oracle RAC keeps track of all resources and resource states on each node and then uses this information to restart these resources on a backup node.

These processes also manage the state of in-flight transactions and work with TAF to either restart or resume the transactions on the new node. Now let's see how Oracle RAC and TAF work together to ensure that a server failure does not cause an unplanned service interruption.

Using Transparent Application Failover

After an Oracle RAC node crashes—usually from a hardware failure—all new application transactions are automatically rerouted to a specified backup node. The challenge in rerouting is to not lose transactions that were "in flight" at the exact moment of the crash. One of the requirements of continuous availability is the ability to restart in-flight application transactions, allowing a failed node to resume processing on another server without interruption. Oracle's answer to application failover is a new Oracle Net mechanism dubbed Transparent Application Failover. TAF allows the DBA to configure the type and method of failover for each Oracle Net client.

For an application to use TAF, it must use failover-aware API calls from the Oracle Call Interface (OCI). Inside OCI are TAF callback routines that can be used to make any application failover-aware.

While the concept of failover is simple, providing an apparent instant failover can be extremely complex, because there are many ways to restart in-flight transactions. The TAF architecture offers the ability to restart transactions at either the transaction (SELECT) or session level:

SELECT failover. With SELECT failover, Oracle Net keeps track of all SELECT statements issued during the transaction, tracking how many rows have been fetched back to the client for each cursor associated with a SELECT statement. If the connection to the instance is lost, Oracle Net establishes a connection to another Oracle RAC node and re-executes the SELECT statements, repositioning the cursors so the client can continue

Page 89: 11gR2 ASMCMD Commands

fetching rows as if nothing has happened. The SELECT failover approach is best for data warehouse systems that perform complex and time-consuming transactions.

SESSION failover. When the connection to an instance is lost, SESSION failover results only in the establishment of a new connection to another Oracle RAC node; any work in progress is lost. SESSION failover is ideal for online transaction processing (OLTP) systems, where transactions are small.

Oracle TAF also offers choices on how to restart a failed transaction. The Oracle DBA may choose one of the following failover methods:

BASIC failover. In this approach, the application connects to a backup node only after the primary connection fails. This approach has low overhead, but the end user experiences a delay while the new connection is created.

PRECONNECT failover. In this approach, the application simultaneously connects to both a primary and a backup node. This offers faster failover, because a pre-spawned connection is ready to use. But the extra connection adds everyday overhead by duplicating connections.

Currently, TAF will fail over standard SQL SELECT statements that have been caught during a node crash in an in-flight transaction failure. In the current release of TAF, however, TAF must restart some types of transactions from the beginning of the transaction.

The following types of transactions do not automatically fail over and must be restarted by TAF:

Transactional statements. Transactions involving INSERT, UPDATE, or DELETE statements are not supported by TAF.

ALTER SESSION statements. ALTER SESSION and SQL*Plus SET statements do not fail over.

The following do not fail over and cannot be restarted: Temporary objects. Transactions using temporary segments in the TEMP tablespace and

global temporary tables do not fail over. PL/SQL package states. PL/SQL package states are lost during failover.

Using Oracle RAC and TAF Together

The continuous availability features of Oracle RAC and TAF come together when these products cooperate in restarting failed transactions. Let's take a closer look at how this works.

Within each connected Oracle Net client, tnsnames.ora file parameters define the failover types and methods for that client. The parameters direct Oracle RAC and TAF on how to restart any transactions that may be in-flight during a hardware failure on the node.

It is important to note that TAF failover control is external to the Oracle RAC cluster, and each Oracle Net client may have unique failover types and methods, depending on processing requirements. The following is a client tnsnames.ora file entry for a node, including its current TAF failover parameters:

Page 90: 11gR2 ASMCMD Commands

bubba.world = (DESCRIPTION_LIST = (FAILOVER = true) (LOAD_BALANCE = true) (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = redneck)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = bubba) (SERVER = dedicated) (FAILOVER_MODE = (BACKUP=cletus) (TYPE=select) (METHOD=preconnect) (RETRIES=20) (DELAY=3) ) ) )

The failover_mode section of the tnsnames.ora file lists the parameters and their values:

BACKUP=cletus. This names the backup node that will take over failed connections when a node crashes. In this example, the primary server is bubba, and TAF will reconnect failed transactions to the cletus instance in case of server failure.

TYPE=select. This tells TAF to restart all in-flight transactions from the beginning of the transaction (and not to track cursor states within each transaction).

METHOD=preconnect. This directs TAF to create two connections at transaction startup time: one to the primary bubba database and a backup connection to the cletus database. In case of instance failure, the cletus database will be ready to resume the failed transaction.

RETRIES=20. This directs TAF to retry a failover connection up to 20 times.

DELAY=3. This tells TAF to wait three seconds between connection retries.

Remember, you must set these TAF parameters in every tnsnames.ora file on every Oracle Net client that needs transparent failover.

Putting It All Together

An Oracle Net client can be a single PC or a huge application server. In the architectures of giant Oracle RAC systems, each application server has a customized tnsnames.ora file that governs the failover method for all connections that are routed to that application server.

Watching TAF in Action

Page 91: 11gR2 ASMCMD Commands

The transparency of TAF operation is a tremendous advantage to application users, but DBAs need to quickly see what has happened and where failover traffic is going, and they need to be able to get the status of failover transactions. To provide this capability, the Oracle data dictionary has several new columns in the V$SESSION view that give the current status of failover transactions.

The following query calls the new FAILOVER_TYPE, FAILOVER_METHOD, and FAILED_OVER columns of the V$SESSION view. Be sure to note that the query is restricted to nonsystem sessions, because Oracle data definition language (DDL) and data manipulation language (DML) are not recoverable with TAF.

select username, sid, serial#, failover_type, failover_method, failed_overfrom v$sessionwhere username not in ('SYS','SYSTEM','PERFSTAT')and failed_over = 'YES';

You can run this script against the backup node after an instance failure to see those transactions that have been reconnected with TAF. Remember, TAF will quickly redirect transactions, so you'll only see entries for a short period of time immediately after the failover.  A backup node can have a variety of concurrent failover transactions, because the tnsnames.ora file on each Oracle Net client specifies the backup node, the failover type, and the failover method.

RAC Performance Tuning

Global Cache Wait Events

GC - Global CacheCurrent - Current blockCR - Consistent Read block

Page 92: 11gR2 ASMCMD Commands

Wait EventContention

typeDescription

gc current block 2-way

write/write

An instance requests authorization for a block to be accessed in current mode to modify a block, the instance mastering the resource receives the request. The master has the current version of the block and sends the current copy of the block to the requester via Cache Fusion and keeps a Past Image (.PI)

If you get this then do the following

Analyze the contention, segments in the "current blocks received" section of AWR Use application partitioning scheme Make sure the system has enough CPU power Make sure the interconnect is as fast as possible Ensure that socket send and receive buffers are configured correctly

gc current block 3-way

write/write

An instance requests authorization for a block to be accessed in current mode to modify a block, the instance mastering the resource receives the request and forwards it to the current holder of the block, asking it to relinquish ownership. The holding instance sends a copy of the current version of the block to the requester via Cache Fusion and transfers the exclusive lock to the requesting instance. It also keeps a past Image (PI).

Use the above actions to increase the performance

Page 93: 11gR2 ASMCMD Commands

gc current block 2-way

write/read The difference with the one above is that this sends a copy of the block thus keeping the current copy.

gc current block 3-way

write/read The difference with the one above is that this sends a copy of the block thus keeping the current copy.

gc current block busy

write/write

The requester will eventually get the block via cache fusion but it is delayed due to one of the following

The block was being used by another session on another session was delayed as the holding instance could not write the corresponding redo record immediately

If you get this then do the following

Ensure the log writer is tuned

gc current buffer busy

localThis is the same as above (gc current block busy), the difference is that another session on the same instance also has requested the block (hence local contention)

gc current block congested

none This is caused if heavy congestion on the GCS, thus CPU resources are stretched

Global Enqueue Waits

TX - Transaction enqueue; used for transaction demarcation and tracking TM - Table or partition enqueue; used to protect table definitions during DML operations HW - High-Water Mark enqueue; used to protect table definitions during DML operation SQ - Sequence enqueue; used to serialize incrementing of an Oracle sequence number US - Undo Segment enqueue; mainly used by the Automatic Undo Management (AUM)

feature TA - Enqueue used mainly for transaction recovery as part of instance recovery

Incremental Roll Forward

Overview

With Oracle Database 10g, you can use incremental backups to quickly move a standby database forward in time or load new data into a clone database for testing purposes. You can perform testing in a clone or standby database configuration, then flash back the test changes, and periodically refresh the clone database (or standby database) from the primary database by using the generated incremental backups.

Steps

1. Make an image copy (clone) of the primary database for test purposes.2. Roll the clone database forward to make it transactionally consistent.

Page 94: 11gR2 ASMCMD Commands

3. Enable Flashback Database on the clone database.4. Open the clone database resetlogs for use as a testing database.5. Perform testing for the required period (day or week).6. Flash back all changes done during the testing.7. Apply incremental backup from the original production database.8.  Go to step 2.

Startup and Open Standby Database

Startup commandsstartup nomountalter database mount standby database;alter database recover managed standby database disconnect; select severity, error_code,message,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') from v$dataguard_status;

Open standby read onlyalter database recover managed standby database cancel;

alter database open read only;

select OPEN_MODE from v$database;

Back to redo apply (it only works when users are disconnect from the database)

alter database recover managed standby database disconnect from session;

Errors when users are connecting:

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

alter database recover managed standby database disconnect from session

*

ERROR at line 1:

ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected

Check Primary and Standby Status

Check role and status (both primary and standby) select NAME, DB_UNIQUE_NAME, OPEN_MODE, DATABASE_ROLE from v$database; 

Page 95: 11gR2 ASMCMD Commands

select NAME, OPEN_MODE, DATABASE_ROLE from v$database; --9i db

Check protection mode on primary databaseselect protection_mode, protection_level from v$database;

PROTECTION_MODE      PROTECTION_LEVEL

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

MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

Check processes and statusesSELECT  PROCESS, STATUS,SEQUENCE#,BLOCK#,BLOCKS, DELAY_MINS FROM V$MANAGED_STANDBY;

Log Apply

Start log apply in standby alter database recover managed standby database disconnect from session;

Remove a delay from a standby

alter database recover managed standby database cancel;

alter database recover managed standby database nodelay disconnect; 

Cancel managed recovery/stop log apply alter database recover managed standby database cancel;

Disable/Enable archive log destinationsalter system set log_archive_dest_state_2 = 'defer';alter system set log_archive_dest_state_2 = 'enable';

Logical standby apply stop/startStop...

alter database stop logical standby apply;

Start...

alter database start logical standby apply;

Page 96: 11gR2 ASMCMD Commands

Logs

Check which logs are missing and log apply gapRun this on the standby 

 

alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

select sequence#, archived, applied, first_time, next_time  from v$archived_log order by sequence#;

Run this on both primary and standby

select count(*) from v$archive_gap;

select * from v$archive_gap;

select max(sequence#) from v$log_history;

select local.thread#

,      local.sequence# from 

       (select thread#

       ,       sequence# 

       from    v$archived_log 

       where dest_id=1) local 

where  local.sequence# not in 

       (select sequence#

       from v$archived_log

       where dest_id=2 and 

       thread# = local.thread#)

/

Page 97: 11gR2 ASMCMD Commands

See how up to date a physical standby isRun this on the primary

set numwidth 15

select max(sequence#) current_seq from v$log;

Then run this on the standby

set numwidth 15

select max(applied_seq#) last_seq from v$archive_dest_status;

Switch logsalter system switch logfile;

alter system archive log current;

Register a missing log file 

alter database register physical logfile '<fullpath/filename>';

If FAL doesn't work and it says the log is already registeredalter database register or replace physical logfile '<fullpath/filename>';

If that doesn't work, try this...

shutdown immediate

startup nomount

alter database mount standby database;

alter database recover automatic standby database;

wait for the recovery to finish - then cancel

Page 98: 11gR2 ASMCMD Commands

shutdown immediate

startup nomount

alter database mount standby database;

alter database recover managed standby database disconnect; 

Display info about all log destinationsTo be run on the primary

set lines 100set numwidth 15column ID format 99column "SRLs" format 99 column active format 99 col type format a4

select ds.dest_id id, ad.status, ds.database_mode db_mode, ad.archiver type, ds.recovery_mode, ds.protection_mode, ds.standby_logfile_count "SRLs", ds.standby_logfile_active active, ds.archived_seq#from v$archive_dest_status ds, v$archive_dest adwhere ds.dest_id = ad.dest_idand ad.status != 'INACTIVE'order byds.dest_id/

 

Display log destinations options

To be run on the primary

set numwidth 8 lines 100

Page 99: 11gR2 ASMCMD Commands

column id format 99 

select dest_id id

, archiver

, transmit_mode

, affirm

, async_blocks async

, net_timeout net_time

, delay_mins delay

, reopen_secs reopen

, register,binding 

from v$archive_dest

order by

dest_id

/

 

List any standby redo logs

 set lines 100 pages 999

col member format a70

select st.group#

, st.sequence#

, ceil(st.bytes / 1048576) mb

, lf.member

from v$standby_log st

, v$logfile lf

where st.group# = lf.group#

Page 100: 11gR2 ASMCMD Commands

Misc

Turn on fal tracing on the primary db alter system set LOG_ARCHIVE_TRACE = 128;

Stop the Data Guard broker

 alter system set dg_broker_start=false;

Startup and Open Standby Database

Startup commandsstartup nomountalter database mount standby database;alter database recover managed standby database disconnect; select severity, error_code,message,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') from v$dataguard_status;

Open standby read onlyalter database recover managed standby database cancel;

alter database open read only;

select OPEN_MODE from v$database;

Back to redo apply (it only works when users are disconnect from the database)

alter database recover managed standby database disconnect from session;

Errors when users are connecting:

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

alter database recover managed standby database disconnect from session

*

ERROR at line 1:

ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected

Page 101: 11gR2 ASMCMD Commands

Check Primary and Standby Status

Check role and status (both primary and standby) select NAME, DB_UNIQUE_NAME, OPEN_MODE, DATABASE_ROLE from v$database; 

select NAME, OPEN_MODE, DATABASE_ROLE from v$database; --9i db

Check protection mode on primary databaseselect protection_mode, protection_level from v$database;

PROTECTION_MODE      PROTECTION_LEVEL

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

MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE

Check processes and statusesSELECT  PROCESS, STATUS,SEQUENCE#,BLOCK#,BLOCKS, DELAY_MINS FROM V$MANAGED_STANDBY;

Log Apply

Start log apply in standby alter database recover managed standby database disconnect from session;

Remove a delay from a standby

alter database recover managed standby database cancel;

alter database recover managed standby database nodelay disconnect; 

Cancel managed recovery/stop log apply alter database recover managed standby database cancel;

Disable/Enable archive log destinationsalter system set log_archive_dest_state_2 = 'defer';alter system set log_archive_dest_state_2 = 'enable';

Logical standby apply stop/startStop...

alter database stop logical standby apply;

Page 102: 11gR2 ASMCMD Commands

Start...

alter database start logical standby apply;

Logs

Check which logs are missing and log apply gapRun this on the standby 

 

alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

select sequence#, archived, applied, first_time, next_time  from v$archived_log order by sequence#;

Run this on both primary and standby

select count(*) from v$archive_gap;

select * from v$archive_gap;

select max(sequence#) from v$log_history;

select local.thread#

,      local.sequence# from 

       (select thread#

       ,       sequence# 

       from    v$archived_log 

       where dest_id=1) local 

where  local.sequence# not in 

       (select sequence#

       from v$archived_log

       where dest_id=2 and 

Page 103: 11gR2 ASMCMD Commands

       thread# = local.thread#)

/

See how up to date a physical standby isRun this on the primary

set numwidth 15

select max(sequence#) current_seq from v$log;

Then run this on the standby

set numwidth 15

select max(applied_seq#) last_seq from v$archive_dest_status;

Switch logsalter system switch logfile;

alter system archive log current;

Register a missing log file 

alter database register physical logfile '<fullpath/filename>';

If FAL doesn't work and it says the log is already registeredalter database register or replace physical logfile '<fullpath/filename>';

If that doesn't work, try this...

shutdown immediate

startup nomount

alter database mount standby database;

alter database recover automatic standby database;

Page 104: 11gR2 ASMCMD Commands

wait for the recovery to finish - then cancel

shutdown immediate

startup nomount

alter database mount standby database;

alter database recover managed standby database disconnect; 

Display info about all log destinationsTo be run on the primary

set lines 100set numwidth 15column ID format 99column "SRLs" format 99 column active format 99 col type format a4

select ds.dest_id id, ad.status, ds.database_mode db_mode, ad.archiver type, ds.recovery_mode, ds.protection_mode, ds.standby_logfile_count "SRLs", ds.standby_logfile_active active, ds.archived_seq#from v$archive_dest_status ds, v$archive_dest adwhere ds.dest_id = ad.dest_idand ad.status != 'INACTIVE'order byds.dest_id/

 

Display log destinations options

To be run on the primary

Page 105: 11gR2 ASMCMD Commands

set numwidth 8 lines 100

column id format 99 

select dest_id id

, archiver

, transmit_mode

, affirm

, async_blocks async

, net_timeout net_time

, delay_mins delay

, reopen_secs reopen

, register,binding 

from v$archive_dest

order by

dest_id

/

 

List any standby redo logs

 set lines 100 pages 999

col member format a70

select st.group#

, st.sequence#

, ceil(st.bytes / 1048576) mb

, lf.member

from v$standby_log st

, v$logfile lf

where st.group# = lf.group#

Page 106: 11gR2 ASMCMD Commands

Misc

Turn on fal tracing on the primary db alter system set LOG_ARCHIVE_TRACE = 128;

Stop the Data Guard broker

 alter system set dg_broker_start=false;

Instance Tuning Steps

Step 1: Define the Problem

Identify the performance objective. What is the measure of acceptable performance? How many transactions an hour, or seconds, response time will meet the required performance level?

Identify the scope of the problem. What is affected by the slowdown? Is the whole instance slow? Is it a particular application, program, specific operation, or a single user?

Identify the time frame when the problem occurs. Is the problem only evident during peak hours? Does performance deteriorate over the course of the day? Was the slowdown gradual (over the space of months or weeks) or sudden?

Quantify the slowdown. Identify any changes. Has the operating system software, hardware, application software, or Oracle release been upgraded? Has more data been loaded into the system, or has the data volume or user population grown 

Step 2: Examine the Host System and Examine the Oracle Statistics

Examine Host System

CPU Usageo If there is a significant amount of idle CPU, then there could be an I/O, application, or database bottleneck. Note that wait I/O should be considered as idle CPU.

o If there is high CPU usage, then determine whether the CPU is being used effectively. Is the majority of CPU usage attributable to a small number of high-CPU using programs, or is the CPU consumed by an evenly distributed workload?

o If the CPU is used by a small number of high-usage programs, then look at the programs to determine the cause. If a small number of Oracle processes consumes most of the CPU resources, then use SQL_TRACE and TKPROF to identify the SQL or PL/SQL statements

o Oracle CPU statistics:   V$SYSSTAT, V$SESSTAT and V$RSRC_CONSUMER_GROUP  I/O Problems

Page 107: 11gR2 ASMCMD Commands

o An overly active I/O system can be evidenced by disk queue lengths greater than two, or disk service times that are over 20-30ms.

o Use operating system monitoring tools, such as sar -d or iostat, to determine what processes are running on the system as a whole and to monitor disk access to all files. 

o Check the Oracle wait event data in V$SYSTEM_EVENT to see whether the top wait events are I/O related.

o An I/O problem can also manifest itself with non-I/O related wait events. For example, the difficulty in finding a free buffer in the buffer cache or high wait times for log to be flushed to disk can also be symptoms of an I/O problem.

Network: Using operating system utilities, look at the network round-trip ping time and the number of collisions. If the network is causing large delays in response time, then investigate possible causes.

Step 3: Implement and Measure Change

  asdfasd 

Step 4: Determine whether the performance objective defined in step 1 has been met. If not, then repeat steps 2 and 3 until the performance goals are met.

Tuning Steps Scripts 

NOTES:

 1. SPOOL ALL THE RESULTS IN SQLPLUS IF NECESSARY     SQL> SPOOL FILENAME     SQL > ….     SQL> SPOO OFF 2. MARK TIME     $date     SQL> prompt -- current system time is:     SQL>select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time" from dual;

CPU Performance

Find CPU Consuming Sessions

Method 1: compare the PID from ‘top’ and ‘session.sql’:$ top (then 'c')SQL> @sess.sql

Method 2: run the following SQL script:SQL> @top_cpu_user.sql

Page 108: 11gR2 ASMCMD Commands

Wait Event

List Wait EventsSQL> @wait.sql

Lock and Block

List Blocking and Blocked Sessions

SQL> @whoblockSQL> @show_blocking_sessionsSQL> @rac_locks_blocking 

List Locks

SQL> @show_dml_lockSQL> @show_all_lock 

Running SQL

Find Bad SQL Statements

SQL> @expensive_sqlSQL> @find_sql.sql SQL> @suspicious_sqlSQL> @wait_sql

List Currently Running SQL Statements

SQL> @what_sqlSQL> @who_sqlSQL> @who_sql2

Memory Statistics

Memory Hit Ratio

SQL> @hit(The result is spooled to hit.lst)

SGA Statistics

SQL> @sga_statSQL> @sga_free_pool

Page 109: 11gR2 ASMCMD Commands

Hard Parsing Statistics

SQL> @hard_parseSQL> @recent_hard(The result is spooled to recent_hard.lst)

Other

RAC hang diag:SQL> @hangSQL> @racdiag 

Introduction to Explain Plan

Explain plan displays:

Row source tree :- an ordering of the tables referenced by the statement- an access method for each table mentioned in the statement- a join method for tables affected by join operations in the statement- Data operations like filter, sort, or aggregation

The plan table also contains:- optimization, such as the cost and cardinality of each operation- partitioning, such as the set of accessed partitions- parallel execution, such as the distribution method of join inputs

Examine an explain plan:

Look for the following in an explain plan:- Full scans- Unselective range scans- Late predicate filters- Wrong join order- Late filter operations- The columns of the index being used- Their selectivity (fraction of table being accessed)

How to Use Explain Plan

1. Create the plan table if it does not already exist

Page 110: 11gR2 ASMCMD Commands

SQL> @?/rdbms/admin/utlxplan.sql

2. Generate plan

General method:

SQL> delete plan_table;SQL> explain plan for <SQL_STATEMENT>;

Option 1: Identifying Statements for EXPLAIN PLAN 

Example:SQL> EXPLAIN PLAN SET STATEMENT_ID = 'st1' FOR SELECT last_name FROM employees;

Option 2: Specifying Different Tables for EXPLAIN PLAN 

Example:1) SQL> EXPLAIN PLAN INTO my_plan_table FOR SELECT last_name FROM employees;2) SQL> EXPLAIN PLAN SET STATEMENT_ID = 'st1' INTO my_plan_table FOR SELECT last_name FROM employees;

3. Show the plan

UTLXPLS.SQL: this script displays the plan table output for serial processing; same as "select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'))" 

SQL> @?/rdbms/admin/utlxpls;

UTLXPLP.SQL: this script displays the plan table output including parallel execution columns; same as "select * from table(dbms_xplan.display())"

SQL> @?/rdbms/admin/utlxplp;

DBMS_XPLAN.DISPLAY procedure accepts options for displaying the plan table output :

o A plan table name if you are using a table different than PLAN_TABLEo A statement Id if you have set a statement Id with the EXPLAIN PLANo A format option that determines the level of detail: BASIC, SERIAL, and TYPICAL, ALL,

Page 111: 11gR2 ASMCMD Commands

Examples:SQL> select * from table(dbms_xplan.display);SQL> select plan_table_output from table(dbms_xplan.display());SQL> select plan_table_output from table(dbms_xplan.display(<table_name>, <statement id>,'TYPICAL'));

Explain Plan for Past Queries

Examples:SQL> select sid,username,sql_id,prev_sql_id,sql_child_number,username from v$session where username='&user';SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR(('&sql_id'),0,'ALL')); --in memorySQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY_AWR('&sql_id')) --in AWR report

What to look in explain plan

Execution Plan shows the SQL optimizer's query execution path

Full Table Scan vs. Indexes

Full Table Scan -whole table is read up to the high water mark FTS is not recommended for large tables unless you are reading >5-10% Index lookup -Data is accessed by looking up key values in an index and returning rowids

Methods of index lookup:

index unique scan

Always returns a single value (a single rowid), like empno=1345 Quickest access method available (points to the block)  Index unique scan is one of the most efficient ways of accessing data. This access method is used for returning the data from B-tree indexes. The optimizer chooses a unique scan when all columns of a unique (B-tree) index are specified with equality conditions. 

Index range scan

Accessing a range values of a particular column, like empno> 34434 Index range scan is a common operation for accessing selective data. It can be bounded (bounded on both sides) or unbounded (on one or both sides). Data is returned in the ascending 

Page 112: 11gR2 ASMCMD Commands

order of index columns. Multiple rows with identical values are sorted (in ascending order) by the ROWIDs.

The optimizer uses a range scan when it finds one or more leading columns of an index specified in conditions, such as the following:

* col1 = :b1

* col1 < :b1

* col1 > :b1

* AND combination of the preceding conditions for leading columns in the index

* col1 like 'ASD%' wild-card searches should not be in a leading position otherwise the condition col1 like '%ASD' does not result in a range scan.

index full scan 

Statistics that indicate that it is going to be more efficient than a full table scan and a sort A full scan is available if a predicate references one of the columns in the index  A full scan is also available  if 1) all of the columns in the table referenced in the query are included in the index. 2) at least one of the index columns is not null

index fast full scan 

Scans all the block in the index. Rows are not returned in sorted order Fast full index scans are an alternative to a full table scan when the index contains all the columns that are needed for the query, and at least one column in the index key has the NOTNULL constraint. A fast full scan accesses the data in the index itself, without accessing the table. 

index skip scan 

Finds rows even if the column is not the leading column of a concatenated index This concept is easier to understand if one imagines a prefix index to be similar to a partitioned table. In a partitioned object the partition key (in this case the leading column) defines which partition data is stored within. In the index case every row underneath each key (the prefix column) would be ordered under that key. In a skip scan of a prefixed index, the prefixed value is skipped and the non-prefix columns are accessed as logical sub-indexes. The trailing columns are ordered within the prefix column and so a 'normal' index access can be done ignoring the prefix.

Join Types

Page 113: 11gR2 ASMCMD Commands

Sort Merge Join

Two steps:

1) sort join operation: Both the inputs are sorted on the join key

2) merge join operation: The sorted lists are merged together.

Sort merge joins are useful when the join condition between two tables is an inequality condition (but not a nonequality) like <, <=, >, or >=

Sort merge joins can perform better than hash joins if both of the following conditions exist: 

1) The row sources are sorted already.

2) A sort operation does not have to be done.

 Sort merge joins perform better than nested loop joins for large data sets. You cannot use hash joins unless there is an equality condition.

USE_MERGE hint 

Nested Loops 

Steps:

1) The optimizer determines the driving table and designates it as the outer table.

2) The other table is designated as the inner table.

3) For every row in the outer table, Oracle accesses all the rows in the inner table. The outer loop is for every row in outer table and the inner loop is for every row in the inner table. The outer loop appears before the inner loop in the execution plan, as follows:

NESTED LOOPS 

outer_loop

inner_loop

Nested Loop is better only if a few rows are being retrieved.  The optimizer uses nested loop joins when joining small number of rows, with a good driving condition between the two tables. The outer loop is the driving row source. The inner loop is iterated for every row returned from the outer loop, ideally by an index scan. 

USE_NL(table1 table2) hint 

Page 114: 11gR2 ASMCMD Commands

Hash Join 

Hash joins are used for joining large data sets.  The optimizer uses the smaller of two tables or data sources to build a hash table on the join key in memory. It then scans the larger table, probing the hash table to find the joined rows.

Hash joins generally perform better than sort merge joins USE_HASH hint

Cartesian Product 

No join conditions between tables Applying the ORDERED hint, instructs the optimizer to use a Cartesian join. By specifying a table before its join table is specified, the optimizer does a Cartesian join.

Sorts -expensive operations especially on large tables

Filter –limiting by where clause and some other conditions

AWR Introduction

Introduction

Automatic workload repository (AWR) is a collection of persistent system performance statistics owned by SYS. It resides in SYSAUX tablespace. By default snapshot are generated once every 60min and maintained for 7 days by default.

AWR is enabled only when the STATISTICS_LEVEL initialization parameter is set to TYPICAL (the default) or ALL. A value BASIC turns off all AWR statistics and metrics collection and disables all self-tuning capabilities of the database.

The V$STATISTICS_LEVEL view shows the statistic component, description, and at what level of the STATISTICS_LEVEL parameter the component is enabled.SQL> SELECT statistics_name, activation_level FROM v$statistics_level

The AWR infrastructure

An in-memory statistics collection facility that is used by Oracle Database 10g componentsto collect statistics. These statistics are stored in memory for performance reasons. Statistics stored in memory are accessible through dynamic performance (V$) views.

AWR snapshots represent the persistent portion of the facility. The AWR snapshots areaccessible through data dictionary views and Database Control. Data is owned by the SYS schema. The MMON (which stands for manageability monitor) process is responsible for filtering and transferring the memory statistics to the disk every hour. When the buffer is full, the MMNL (which stands for manageability monitor light) process is responsible to flush the information to the repository.

Page 115: 11gR2 ASMCMD Commands

 AWR Data

Object statistics that determine both access and usage statistics of database segments New SQL statistics that are used to efficiently identify top SQL statements based on

CPU,Elapsed, and Parse statistics

The new wait classes interface used for high-level performance analysis The new time-model statistics based on how much time activities have spent Some of the statistics currently collected in V$SYSSTAT and V$SESSTAT Some of the Oracle optimizer statistics that include statistics for self-learning and tuning Operating system statistics The Active Session History (ASH), which represents the history of recent session activity Metrics that provides the rate of change for certain base statistics

AWR Report

Quick Tip

1. Generate reports by executing one of following scripts:

$ORACLE_HOME/rdbms/admin/awrrpt.sql$ORACLE_HOME/rdbms/admin/awrrpti.sql$ORACLE_HOME/rdbms/admin/awrinput.sql

2. For text report, copy and paste the report to the following website to get recommendations:

Statspack Analyzer

AWR Report Information

Page 116: 11gR2 ASMCMD Commands

Report summary  Wait events statistics  SQL statistics  Instance activity statistics  I/O statistics  Buffer pool statistics  Advisory statistics  Wait statistics  Undo statistics  Latch statistics  Segment statistics  Dictionary cache statistics  Library cache statistics  SGA statistics  Resource limit statistics  init.ora parameters

Generate AWR reports

You can generate AWR reports by running SQL scripts:

1)The awrrpt.sql SQL script generates an HTML or text report that displaysstatistics for a range of snapshot Ids.

2)The awrrpti.sql SQL script generates an HTML or text report that displaysstatistics for a range of snapshot Ids on a specified database and instance.

3) The awrsqrpt.sql SQL script generates an HTML or text report that displaysstatistics of a particular SQL statement for a range of snapshot Ids. Run this reportto inspect or debug the performance of a SQL statement.

4) The awrsqrpi.sql SQL script generates an HTML or text report that displaysstatistics of a particular SQL statement for a range of snapshot Ids on a specified SQL.

5) The awrddrpt.sql SQL script generates an HTML or text report that comparesdetailed performance attributes and configuration settings between two selectedtime periods.

6) The awrddrpi.sql SQL script generates an HTML or text report that comparesdetailed performance attributes and configuration settings between two selectedtime periods on a specific database and instance.

To generate an HTML or text report for a range of snapshot Ids, run the awrrpt.sqlscript at the SQL prompt:

Views

Page 117: 11gR2 ASMCMD Commands

Few Views which helps while generating the AWR report

DBA_HIST_SNAPSHOTDBA_HIST_WR_CONTROLDBA_HIST_BASELINE

Procedures

How to Modify the AWR SNAP SHOT SETTINGS:BEGIN  DBMS_WORKLOAD_REPOSITORY.modify_snapshot_settings(    retention => 43200,        -- Minutes (= 30 Days). Current value retained if NULL.    interval  => 30);          -- Minutes. Current value retained if NULL.END;/

Creating the Baseline:BEGIN  DBMS_WORKLOAD_REPOSITORY.create_baseline (    start_snap_id => 10,     end_snap_id   => 100,    baseline_name => 'AWR First baseline');END;/

Dropping the AWR baseline:BEGIN    DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE (    baseline_name => 'AWR First baseline');END;/

Dropping the AWR snaps in range:BEGIN  DBMS_WORKLOAD_REPOSITORY.drop_snapshot_range((row_snap_id=>40,High_snap_id=>80);END;/

Page 118: 11gR2 ASMCMD Commands

Creating SNAPSHOT Manually:BEGIN  DBMS_WORKLOAD_REPOSITORY.create_snapshot();END;/

Workload Repository Views:

All AWR tables are stored under the SYS schema in the new special tablespace named SYSAUX, and named in the format WRM$_* and WRH$_*. 

WRM$_* stores metadata information such as the database being examined and the snapshots taken (M stands for "metadata.")

WRH$_* holds the actual collected statistics. (H stands for "historical" ) There are several views with the prefix DBA_HIST_ built upon these tables, which can be used to write your own performance diagnosis tool. The names of the views directly relate to the table; for example, the view DBA_HIST_SYSMETRIC_SUMMARY is built upon the table WRH$_SYSMETRIC_SUMMARY.

The following workload repository views are available:

    * V$ACTIVE_SESSION_HISTORY - Displays the active session history (ASH) sampled every second.    * V$METRIC - Displays metric information.    * V$METRICNAME - Displays the metrics associated with each metric group.    * V$METRIC_HISTORY - Displays historical metrics.    * V$METRICGROUP - Displays all metrics groups.    * DBA_HIST_ACTIVE_SESS_HISTORY - Displays the history contents of the active session history.    * DBA_HIST_BASELINE - Displays baseline information.    * DBA_HIST_DATABASE_INSTANCE - Displays database environment information.    * DBA_HIST_SNAPSHOT - Displays snapshot information.    * DBA_HIST_SQL_PLAN - Displays SQL execution plans.    * DBA_HIST_WR_CONTROL - Displays AWR settings.

ADDM

Page 119: 11gR2 ASMCMD Commands

Create ADDM Report in SQLPLUS

@?/rdbms/admin/addmrpt.sql

Create an Advisor Task

  BEGIN  -- Create an ADDM task.  DBMS_ADVISOR.create_task (    advisor_name      => 'ADDM',    task_name         => '970_1032_AWR_SNAPSHOT',    task_desc         => 'Advisor for snapshots 970 to 1032.');

  -- Set the start and end snapshots.  DBMS_ADVISOR.set_task_parameter (    task_name => '970_1032_AWR_SNAPSHOT',    parameter => 'START_SNAPSHOT',    value     => 970);

  DBMS_ADVISOR.set_task_parameter (    task_name => '970_1032_AWR_SNAPSHOT',    parameter => 'END_SNAPSHOT',    value     => 1032);

  -- Execute the task.  DBMS_ADVISOR.execute_task(task_name => '970_1032_AWR_SNAPSHOT');END;/

-- Display the report.SET LONG 100000SET PAGESIZE 50000SELECT DBMS_ADVISOR.get_task_report('970_1032_AWR_SNAPSHOT') AS reportFROM   dual;SET PAGESIZE 24

Display ADDM Report in SQLPLUSSET LONG 100000SET PAGESIZE 50000select * from DBA_ADVISOR_TASKS order by created desc  -- find out ADDM report nameSELECT DBMS_ADVISOR.get_task_report('&reportname') AS report FROM   dual;

Page 120: 11gR2 ASMCMD Commands

Related Views

    DBA_ADVISOR_TASKS - Basic information about existing tasks.     DBA_ADVISOR_LOG - Status information about existing tasks.     DBA_ADVISOR_FINDINGS - Findings identified for an existing task.     DBA_ADVISOR_RECOMMENDATIONS - Recommendations for the problems identified by an existing task.

Advisory Framework

Framework

Automatic Database Diagnostic Monitor (ADDM): Performs a top-down instance analysis, identifies problems and potential causes, and gives recommendations for fixing the problems. ADDM can potentially call other advisors.

SQL Tuning Advisor: Provides tuning advice for SQL statements SQL Access Advisor: Deals with schema issues and determines optimal data access paths

such as indexes and materialized views PGA Advisor: Gives detailed statistics for the work areas and provides recommendations

about optimal usage of PGA memory based on workload characteristics SGA Advisor: Responsible for tuning and recommending SGA size depending on pattern

of access for the various components within the SGA Segment Advisor: Monitors object space issues and analyzes growth trends Undo Advisor: Suggests parameter values and the amount of additional space that is

needed to support flashback for a specified time

ADDM

Page 121: 11gR2 ASMCMD Commands

ADDM analysis is performed every time an AWR snapshot is taken. The MMON process triggers ADDM analysis each time a snapshot is taken to do an analysis of the period corresponding to the last two snapshots.

The results of the ADDM analysis are also stored in the AWR and are accessible through the dictionary views and the EM Database Control. Analysis is performed from the top down, identifying symptoms first and then refining them to reach the root cause.

The goal of analysis is to reduce a single throughput metric called the DBtime. DBtime is the cumulative time spent by the database server in processing user requests, which includes wait time and CPU time.

The ADDM is enabled automatically only when the STATISTICS_LEVEL parameter is set to TYPICAL or ALL.

DBA Advisory Dictionaries

DBA_ADVISOR_USAGE - Usage information for each advisor DBA_ADVISOR_RATIONALE - Rationales for the recommendations DBA_ADVISOR_ACTIONS - Actions associated with recommendations DBA_ADVISOR_RECOMMENDATIONS - Task’s recommendations DBA_ADVISOR_FINDINGS - Findings discovered by the advisor DBA_ADVISOR_OBJECTS - Object referenced by tasks DBA_ADVISOR_COMMANDS - Commands associated with actions DBA_ADVISOR_PARAMETERS - Task’s parameters DBA_ADVISOR_LOG - Task’s current status information DBA_ADVISOR_TASKS - Global information about the task DBA_ADVISOR_DEFINITIONS - Properties of the advisors

Tips

Show the number of findings of ADDM for the last 24 hours by category:SQL> SELECT type, count(*) FROM dba_advisor_findings NATURAL JOIN dba_advisor_tasks WHERE created between sysdate -1 and sysdate GROUP BY type

You can invoke the ADDM report using SQL*Plus by running the $ORACLE_HOME/rdbms/admin/addmrpt.sql script. The output is saved as a text file.

You should look at the recommendations in the order they’re listed in the RANK column.

SQL> SELECT distinct message FROM dba_advisor_recommendations JOIN dba_advisor_findings USING (finding_id, task_id) WHERE rank = 0

Setting Alert 

Building Your Own Alert Mechanism

Page 122: 11gR2 ASMCMD Commands

You can use the following steps to set up a threshold and alert mechanism if you do not wantto use the EM Database Control:

1. Query V$METRICNAME to identify the metrics in which you are interested.2. Set warning and critical thresholds using the

DBMS_SERVER_ALERT.SET_THRESHOLD procedure.3. Subscribe to the ALERT_QUE AQ using the DBMS_AQADM.ADD_SUBSCRIBER

procedure.4. Create an agent for the subscribing user of the alerts using the

DBMS_AQADM.CREATE_AQ_AGENT procedure.5. Associate the user with the AQ agent using the

DBMS_AQADM.ENABLE_DB_ACCESS procedure.6. Grant the DEQUEUE privilege using the

DBMS_AQADM.GRANT_QUEUE_PRIVILEGE procedure.7. Optionally register for the alert enqueue notification using the DBMS_AQ.REGISTER

procedure.8. Configure e-mail using the DBMS_AQELM.SET* procedures.9. Dequeue the alert using the DBMS_AQ.DEQUEUE procedure.10. After the message has been dequeued, use

DBMS_SERVER_ALERT.EXPAND_MESSAGE toexpand the text of the message.

SQL Tuning AdvisorHome >> Reference >> Performance Tuning >> SQL Tuning Advisor

Automatic Tuning Optimizer (ATO) to perform the following four specific types of analysis:

Statistics Analysis: ATO checks each query object for missing or stale statistics and makes a recommendation to gather relevant statistics. It also collects auxiliary information to supply missing statistics or correct stale statistics in case recommendations are not implemented.

SQL Profiling: ATO verifies its own estimates and collects auxiliary information to remove estimation errors. It also collects auxiliary information in the form of customized optimizer settings, such as first rows and all rows, based on past execution history of the SQL statement. It builds a SQL Profile using the auxiliary information and makes a recommendation to create it. When a SQL Profile is created, the profile enables the query optimizer, under normal mode, to generate a well-tuned plan.

Access Path Analysis: ATO explores whether a new index can be used to significantly improve access to each table in the query, and when appropriate makes recommendations to create such indexes.

SQL Structure Analysis: Here, ATO tries to identify SQL statements that lend themselves to bad plans, and makes relevant suggestions to restructure them. The suggested restructuring can be syntactic as well as semantic changes to the SQL code.

SQL Tuning Advisor takes one or more SQL statements as input. The input can come from different sources:

Page 123: 11gR2 ASMCMD Commands

High-load SQL statements identified by ADDM SQL statements that are currently in cursor cache SQL statements from Automatic Workload Repository (AWR): A user can select any set of SQL statements captured by AWR. This can be done using snapshots or baselines.

Custom workload: A user can create a custom workload consisting of statements of interest to the user. These may be statements that are not in cursor cache and are not high-load to be captured by ADDM or AWR. For such statements, a user can create a custom workload and tune it using the advisor.

SQL Profile

How to export and then import a SQL Profile:

1. Create a staging table through a call to the CREATE_STGTAB_SQLPROF procedure.exec DBMS_SQLTUNE.CREATE_STGTAB_SQLPROF(table_name => 'STAGING_TABLE',schema_name => 'JFV');

2. Call the PACK_STGTAB_SQLPROF procedure one or more times to write existing SQL profile data into the staging table.exec DBMS_SQLTUNE.PACK_STGTAB_SQLPROF(profile_name => 'SP_DINA',staging_table_name => 'STAGING_TABLE');

3. Move the staging table from your production environment to a test machine through the means of choice—for example, by means of a Data Pump job or a database link. 

4. On the test machine, call the UNPACK_STGTAB_SQLPROF procedure to create SQL Profiles on the new system from the profile data in the staging table.EXEC DBMS_SQLTUNE.REMAP_STGTAB_SQLPROF(old_profile_name => 'SP_DINA',new_profile_name => 'SP_NEW_DINA',staging_table_name => 'STAGING_TABLE');EXEC DBMS_SQLTUNE.UNPACK_STGTAB_SQLPROF(replace => TRUE,staging_table_name => 'STAGING_TABLE');

SQL Access AdvisorHome >> Reference >> Performance Tuning >> SQL Access Advisor

Input to the SQL Access Advisor can come from one or all of the following sources:

Current SQL statements from V$SQL (the SQL cache) A user-specified list of SQL statements The name of a schema; in a data warehouse environment, this is typically a dimensional

model in a single schema STSs previously saved in the workload repository

Given the workload, the SQL Access Advisor performs an analysis that includes all the followingtasks:

Considers whether only indexes, only materialized views, or a combination of both wouldprovide the most benefit

Page 124: 11gR2 ASMCMD Commands

Balances storage and maintenance costs against the performance gains when recommendingnew indexes or materialized views

Generates DROP recommendations to drop an unused index or materialized view if a fullworkload is specified

Optimizes materialized views to leverage query rewrite and fast refresh where possible Recommends materialized view logs to facilitate fast refresh Recommends combining multiple indexes into a single index where appropriate

DBMS_ADVISOR

Using the procedures of the DBMS_ADVISOR package, a typical tuning advisor session may comprise the following steps:

1. Create an advisor task using the DBMS_ADVISOR.CREATE_TASK procedure. The advisor task is a data area in the advisor repository that manages the tuning efforts. An existing task can be a template for another task.

2. Use the DBMS_ADVISOR.SET_TASK_PARAMETERS procedure to set up appropriate parameters to control the advisor’s behavior. Typical parameters are TARGET_OBJECTS, TIME_WINDOW, and TIME_LIMIT.

3. Perform analysis using the DBMS_ADVISOR.EXECUTE_TASK procedure. You can interrupt the analysis process anytime to review the results up to that point. You can then resume the interrupted analysis for more recommendations, or you can adjust the task parameters and then resume execution.

4. Review the results using the DBMS_ADVISOR.GET_TASK_REPORT procedure. You can also view the results using dictionary views.

5. DBMS_SQLTUNEHome >> Reference >> Performance Tuning >> DBMS_SQLTUNE

6. A typical session using the SQL Tuning Advisor would use DBMS_SQLTUNE procedures andfunctions as follows:1. Create a tuning task with CREATE_TUNING_TASK.Understanding the SQL Tuning Advisor 3332. Execute the tuning task using EXECUTE_TUNING_TASK.3. Review the results of the tuning task by calling the function REPORT_TUNING_TASK.4. Accept the SQL profile generated by the tuning task using ACCEPT_SQL_PROFILE.

7. 5. Alters specific attributes of an existing SQL Profile object 8. exec dbms_sqltune.alter_sql_profile('some_sqlprofile', 'STATUS', 

'DISABLED');exec DBMS_SQLTUNE.alter_sql_profile('some_sqlprofile','DESCRIPTION','this is a test sql profile');

Page 125: 11gR2 ASMCMD Commands

Oracle Memory Compoments

SGA: Shared Pool (for SQL and PL/SQL execution): include library cache and

data dictionary cache Large pool (for large allocations such as RMAN backup buffers) Java pool (for java objects and other java execution memory) Buffer cache (for caching disk blocks) Streams pool Redo log buffer

PGA: Process-private memory, such as memory used for sorting and hash joins

Memory Management

Automatic Shared Memory Management (10g) Automatic Memory Management(AMM) (11g)

Memory Initialization Parameters

Parameter Description Dynamic?

SGA_MAX_SIZEspecifies the maximum size of the SGA for the lifetime of the instance.

NO

SGA_TARGET specifies the total size of all SGA componentsALTER SYSTEM

DB_CACHE_SIZE

specifies the size of the DEFAULT buffer pool for buffers with the primary block size (the block size defined by the DB_BLOCK_SIZE initialization parameter)

ALTER SYSTEM

DB_nK_CACHE_SIZE specifies the size of the cache for the nK buffersALTER SYSTEM

LOG_BUFFER the number of bytes allocated for the redo log buffer NO

SHARED_POOL_SIZEthe size in bytes of the area devoted to shared SQL and PL/SQL statements.

ALTER SYSTEM

LARGE_POOL_SIZE the size of the large pool; the default is 0ALTER SYSTEM

JAVA_POOL_SIZE the size of the Java poolALTER SYSTEM

STREAMS_POOL_SIZEALTER SYSTEM

Commands and Scripts

Page 126: 11gR2 ASMCMD Commands

Check SGA allocation:

SQL> select component, current_size/1024/1024 "CURRENT_SIZE", min_size/1024/1024, user_specified_size/1024/1024 "USER_SPECIFIED_SIZE", last_oper_type "TYPE" from v$sga_dynamic_components;

SQL> SELECT f.pool, f.name, s.sgasize, f.bytes, ROUND(f.bytes/s.sgasize*100, 2) "% Free" FROM (SELECT SUM(bytes) sgasize, pool FROM v$sgastat GROUP BY pool) s, v$sgastat f WHERE f.name = 'free memory' AND f.pool = s.pool;

SQL> sho sga

Read and Write Concurrency Rates

Component Read Rate Write Rate Concurrency

Archive logs High High Low

Redo logs High High Low

Undo segment tablespaces Low High High

TEMP tablespaces Low Low High

Index tablespaces Low Medium High

Data tablespaces High Medium High

Application log and output files Low Medium High

Binaries (shared) Low Low High

Oracle File I/O Statistics

select     NAME,    PHYRDS "Physical Reads",    round((PHYRDS / PD.PHYS_READS)*100,2) "Read %",    PHYWRTS "Physical Writes",    round(PHYWRTS * 100 / PD.PHYS_WRTS,2) "Write %",    fs.PHYBLKRD+FS.PHYBLKWRT "Total Block I/O's"from (    select     sum(PHYRDS) PHYS_READS,        sum(PHYWRTS) PHYS_WRTS    from      v$filestat    ) pd,    v$datafile df,    v$filestat fs

Page 127: 11gR2 ASMCMD Commands

where     df.FILE# = fs.FILE#order     by fs.PHYBLKRD+fs.PHYBLKWRT desc

  File Name - Datafile name 

  Physical Reads - Number of physical reads 

  Reads % - Percentage of physical reads 

  Physical Writes - Number of physical writes 

  Writes % - Percentage of physical writes 

  Total Block I/O's - Number of I/O blocks 

Tracing a User Session

dbms_support     dbms_system     dbms_monitor    (10g new feature)  Oracle Event 10046 Trace 

Trace session: Enable:SQL> ALTER SESSION SET EVENTS '10046 trace name context forever level 12'Disable: SQL> ALTER SESSION SET EVENTS '10046 trace name context off' 

System-wide tracing: Enable: SQL>  alter system set events '10046 trace name context forever,level 12'; Disable: SQL> alter system set events '10046 trace name context off'; 

Level 1 - the same as a normal set sql_trace=true  Level 4 - including values of bind variables  Level 8 - including wait events  Level 12 - including both bind variables and wait events.

Oradebug    (10046)  Logon Trigger: there may be some situations where it is necessary to trace the activity of a specific user. In this case a logon trigger could be used. An example:   

CREATE OR REPLACE TRIGGER SYS.set_trace  AFTER LOGON ON DATABASE  WHEN (USER like  '&USERNAME')  DECLARE      lcommand varchar(200);  BEGIN      EXECUTE IMMEDIATE 'alter session set statistics_level=ALL';

Page 128: 11gR2 ASMCMD Commands

      EXECUTE IMMEDIATE 'alter session set max_dump_file_size=UNLIMITED';      EXECUTE IMMEDIATE 'alter session set events ''10046 trace name context forever, level 12''';  END set_trace;  /

SQL*Plus Autotrace

1. Create Plan Table

SQL> @?/rdbms/admin/catplan.sql

2. Create PLUSTRACE RoleSQL> @?/sqlplus/admin/plustrce.sql

3.Grant PLUSTRACE RoleSQL> GRANT plustrace TO <user_name>;

4. AUTOTRACE syntax:

SET AUTOTRACE OFF- No report is generated. This is the default.

SET AUTOTRACE ON EXPLAIN- The report shows only the optimizer execution path.

SET AUTOTRACE ON STATISTICS- The report shows only the SQL statement execution statistics.

SET AUTOTRACE ON- The report includes both the optimizer execution path and the SQL statement execution statistics.

SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the query output.

Check Session History

Check Session History

Home >> Reference >> Performance Tuning >> Check Session History

Page 129: 11gR2 ASMCMD Commands

 Query 1

SELECT *FROM v$active_session_history sess, all_users usWHERE     TRUNC (sample_time, 'DD') = '16-MAY-2008'      AND us.user_id = sess.user_id      AND us.username = '&user';-- and sess.session_id=

 

Query 2

SELECT *FROM dba_hist_active_sess_historyORDER BY sample_time DESC;

Query 3

Find out history SQL statements which has blocking session

SELECT  *FROM v$active_session_history sess, all_users us, v$sqltext textWHERE     to_char (sample_time, 'DD-Mon-YYYY HH24:MI:SS') >= '07-Jun-2010 01:55:00'and to_char (sample_time, 'DD-Mon-YYYY HH24:MI:SS') <= '07-Jun-2010 02:05:00'AND us.user_id = sess.user_id      AND us.username not in ('SYS', 'SYSTEM','DBSNMP')      and text.sql_id=SESS.SQL_ID       and  sess.BLOCKING_SESSION_STATUS not in ('NO HOLDER','NOT IN WAIT' )

Find out history SQL statements

SELECT  *FROM v$active_session_history sess, all_users us, v$sqltext textWHERE     to_char (sample_time, 'DD-Mon-YYYY HH24:MI:SS') >= '07-Jun-2010 01:55:00'and to_char (sample_time, 'DD-Mon-YYYY HH24:MI:SS') <= '07-Jun-2010 02:05:00'--TRUNC (sample_time, 'DD') = '07-JUN-2010'AND us.user_id = sess.user_id      AND us.username not in ('SYS', 'SYSTEM','DBSNMP')      and text.sql_id=SESS.SQL_ID

Page 130: 11gR2 ASMCMD Commands

 Query 4

All blocking locks for last 7 days.

SELECT  distinct a.sql_id ,a.inst_id,a.blocking_session,a.blocking_session_serial#,a.user_id,s.sql_text,a.moduleFROM  GV$ACTIVE_SESSION_HISTORY a  ,gv$sql swhere a.sql_id=s.sql_idand blocking_session is not nulland a.user_id <> 0 -- exclude SYS user and a.sample_time > sysdate - 7 

          

select * from (SELECT a.sql_id ,COUNT(*) OVER (PARTITION BY a.blocking_session,a.user_id ,a.program) cpt,ROW_NUMBER() OVER (PARTITION BY a.blocking_session,a.user_id ,a.programorder by blocking_session,a.user_id ,a.program ) rn,a.blocking_session,a.user_id ,a.program, s.sql_textFROM sys.WRH$_ACTIVE_SESSION_HISTORY a ,sys.wrh$_sqltext swhere a.sql_id=s.sql_idand blocking_session_serial# <> 0and a.user_id <> 0and a.sample_time > sysdate - 10) where rn = 1

Set parameter in a session

Home >> Reference >> Performance Tuning >> Set parameters in a session

exec dbms_system.set_int_param_in_session( sid, serial#, '&param_name', &number);exec dbms_system.set_bool_param_in_session( sid, serial#,'&param_name', &bool); 

UNDO_RETENTION

Introduction

Proactive tuning– Undo retention is tuned for the longest-running query with an AUTOEXTEND undo tablespace.

Page 131: 11gR2 ASMCMD Commands

– Undo retention is tuned for the best possible value with a fixed size undo tablespace.– Query duration information is collected every 30 seconds.

Reactive tuning– Undo retention is gradually lowered under space pressure.– The oldest unexpired extents are used first.– Undo retention never goes below either UNDO_RETENTION or 15 minutes.

Enabled by default

UNDO_RETENTION

The default for this parameter is 900 seconds. If UNDO_RETENTION is set to zero or if no value is specified, Oracle 10g

automatically tunes the undo retention for the current undo tablespace using 900 as the minimum value.

If you set UNDO_RETENTION to a value other than zero, Oracle 10g autotunes the undo retention using the specified value as the minimum

RETENTION GUARANTEE

Use RETENTION GUARANTEE clause to guarantee the undo retention. This means that the database will make certain that undo will always be available for the specified undo retention period.

You can use the RETENTION GUARANTEE clause when creating the undo tablespace (CREATE UNDO TABLESPACE or CREATE DATABASE) or later using the ALTER TABLESPACE statement.

To turn the retention guarantee off, use the RETENTION NOGUARANTEE clause.

Automatic Checkpoint Tuning

MTTR

The Mean Time to Recovery Advisor (the MTTR Advisor) performs automatic checkpoint tuning. You do not need to set up any checkpoint related parameters.

Setting the FAST_START_MTTR_TARGET parameter to a nonzero value or not setting this parameter enables automatic checkpoint tuning. The STATISTICS_LEVEL parameter must be set to TYPICAL or ALL.

If you explicitly set this parameter to zero, you disable automatic checkpoint tuning. After the database runs a typical workload for some time, the

V$MTTR_TARGET_ADVICE dictionary view shows advisory information and an estimate of the number of additional I/O operations that would occur under different FAST_START_MTTR_TARGET values.

A new column OPTIMAL_LOGFILE_SIZE is now available in V$INSTANCE_RECOVERY. This column shows the redo log file size in me

Page 132: 11gR2 ASMCMD Commands

Checkpoint Overview

Check-pointing is an important Oracle activity which records the highest system change number (SCN,) so that all data blocks less than or equal to the SCN are known to be written out to the data files. If there is a failure and then subsequent cache recovery, only the redo records containing changes at SCN(s) higher than the checkpoint need to be applied during recovery.

As we are aware, instance and crash recovery occur in two steps - cache recovery followed by transaction recovery. During the cache recovery phase, also known as the rolling forward stage, Oracle applies all committed and uncommitted changes in the redo log files to the affected data blocks. The work required for cache recovery processing is proportional to the rate of change to the database and the time between checkpoints.

Trace Analyzer

Metalink 224270.1

1. Download Trace Analyzer

trca.zip 

trca_sample.zip 

2.  Installing the Trace AnalyzerSQL> @/trca/install/tacreateEnter value for default_tablespace: TOOLS01Using TOOLS01 for the default tablespace

Enter value for temporary_tablespace: TEMPUsing TEMP for the temporary tablespace

 3. Trace sessions

SQL> @sessexec sys.dbms_monitor.session_trace_enable (&sid ,&serial, TRUE,FALSE);exec sys.dbms_monitor.session_trace_disable(&sid, &serial)

4.  Using the Trace Analyzersqlplus trcanlzrSQL> start /trca/run/trcanlzr.sql <file_name>SQL> start trcanlzr.sql largesql.trc  <== your trace fileSQL> start trcanlzr.sql control_file.txt  <== your text file

Page 133: 11gR2 ASMCMD Commands

GATHER_DATABASE_STATS Procedures:

o statistics for all objects in a database

SQL> exec dbms_stats.gather_database_stats;SQL> exec dbms_stats.gather_database_stats(estimate_percent => NULL, method_opt => 'AUTO', granularity => 'ALL', cascade => 'TRUE', options => 'GATHER AUTO' );

GATHER_DICTIONARY_STATS Procedure:

o statistics for all dictionary objects

SQL> select distinct trunc(last_analyzed), count(*) from dba_tables where owner='SYS' group by trunc(last_analyzed); -- Check how many sys tables have statistics:SQL> exec dbms_stats.gather_dictionary_stats ;SQL> select distinct trunc(last_analyzed), count(*) from dba_tables where owner='SYS' group by trunc(last_analyzed);

GATHER_FIXED_OBJECTS_STATS Procedure

SQL> exec dbms_stats.gather_fixed_objects_stats ;

GATHER_INDEX_STATS Procedure:

an index statistics

SQL> exec dbms_stats.gather_index_stats('schema_name', 'index_name' );

GATHER_SCHEMA_STATS Procedures:

statistics for all objects in a schema

SQL> exec dbms_stats.gather_schema_stats('schema_name', cascade=>TRUE );

GATHER_SYSTEM_STATS Procedure

link

GATHER_TABLE_STATS Procedure:

Page 134: 11gR2 ASMCMD Commands

a table, column, and its index statistics

SQL> select * from dba_tab_modifications; --check table changes: modified since the last time statistics were gathered on the tables.SQL> exec dbms_stats.gather_table_stats('schema_name', 'table_name') ; SQL>select owner, table_name, last_analyzed from dba_tables order by 1,2,3;

Automated scheduler job

Optimizer statistics are automatically gathered with the job GATHER_STATS_JOB. This job gathers statistics on all objects in the database which have:* Missing statistics* Stale statisticsThis job is created automatically at database creation time and is managed by the Scheduler. The Scheduler runs this job when the maintenance window is opened. By default, the maintenance window opens every night from 10 P.M. to 6 A.M. and all day on weekends.

Query:

SQL> SELECT owner, job_name,enabled FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME = 'GATHER_STATS_JOB';

Enable automatic statistics collection:

SQL> exec dbms_scheduler.enable('GATHER_STATS_JOB'); ;

Disable automatic statistics collection:

SQL> exec dbms_scheduler.disalbe('GATHER_STATS_JOB');

DBMS_STATS vs ANALYZE

DBMS_STATS

DBMS_STATS can be done in parallel Monitoring can be done and stale statistics can be collected for changed rows using

DBMS_STATS Import/export/set statistics directly with dbms_stats It is easier to automate with dbms_stats (it is procedural, analyze is just a command) dbms_stats is the stated, preferred method of collecting statisttics. dbms_stats can analyze external tables, analyze cannot DBMS_STATS gathers statistics only for cost-based optimization; it does not gather

other statistics. For example, the table statistics gathered by DBMS_STATS include the number

Page 135: 11gR2 ASMCMD Commands

of rows, number of blocks currently containing data, and average row length but not the number of chained rows, average free space, or number of unused data blocks.

dbms_stats can gather system stats

ANALYZE

ANALYZE calculates global statistics for partitioned tables and indexes instead of gathering them directly. This can lead to inaccuracies for some statistics, such as the number of distinct values.  DBMS_Stats won't do that.

Most importantly, in the future, ANALYZE will not collect statistics needed bythe cost-based optimizer.

STATISTICS_LEVEL

The values for STATISTICS_LEVEL are as follows:

BASIC - A value of BASIC disables monitoring, and as a result the Automatic Workload Repository(AWR) snapshots are disabled in addition to the ADDM. Using BASIC may be advisable onlyin a DSS environment where the queries rarely vary day to day, the system has been thoroughlytuned already, the size of the database changes infrequently, the database is static, and the fastestpossible execution speed of all queries is the top priority.

TYPICAL - Using a value of TYPICAL will collect most statistics required for database self-managementand delivers the best overall performance

ALL - specifying ALL collects additional statistics such as timed operating system statistics and plan execution statistics, but incurs a significant amount of overhead above and beyond the TYPICAL level that may have a noticeable impact on user transactions.

Locks

 Scripts:

1. Display lock wait-for in hierarchy: the lock information to the right of session ID describes the lock that the session is waiting for (not the lock it is holding).(SQL> @?/rdbms/admin/catblock)SQL> @?/rdbms/admin/utllockt

 

Page 136: 11gR2 ASMCMD Commands

2. This script shows actual DML-Locks (incl. Table-Name), WAIT = YES means that users are waiting for a lockSQL> @show_dml_locks.sqlSQL> @show_all_lock.sql

3. This script shows users waiting for a lock, the locker and the SQL-Command they are waiting for a lock, the osuser, schema and PIDs are shown as well.SQL> @show_blocking_sessions.sql

4. This script shows who's blocking who:SQL> @whoblock.sql

Modes of Locking

Exclusive Locks         

select.. from table...                =>        Noinsert into table...                    =>        RXupdate table                           =>        RXdelete from table...                 =>        RXlock table...in row exclusive mode                 =>        RXlock table... in share row exlcusive mode      =>        RXlock table... in exclusive mode                       =>        RX 

Share Locks  

select... from table for update of...                            =>        RSlock table ... in row share mode                                 =>        RSlock table ... in share mode                                        =>        Slock table ... in row exclusive mode                           =>        SRX

V$ Views for locks

v$lock

LMODE: Lock mode in which the session holds the lock:      0 - none      1 - null (NULL)      2 - row-S (SS)      3 - row-X (SX)      4 - share (S)      5 - S/Row-X (SSX)      6 - exclusive (X) 

REQUEST: Lock mode in which the process requests the lock:

Page 137: 11gR2 ASMCMD Commands

      0 - none      1 - null (NULL)      2 - row-S (SS)      3 - row-X (SX)      4 - share (S)      5 - S/Row-X (SSX) 

v$locked_objects    

select count(*) from v$locked_object; 

Commands

SQL> lock <table_name> in lock mode;

SQL> alter table xxx disable table lock nowait;

SQL> alter system kill session 'sid, serial#' immediate;

Configuring for Materialized Views

Oracle Tips by Burleson Consulting

Oracle materialized views are one of the single most important SQL tuning tools and they are a true silver bullet, allowing you to pre-join complex views and pre-compute summaries for super-fast response time. 

I've devoted over a hundred pages to SQL tuning with Oracle materialized views in my book "Oracle Tuning: The Definitive Reference", and also see "Oracle Replication" a deeply-technical book on creating and managing materialized views.

Also see my notes now how to identify opportunities for Oracle Materialized Views.

Introduction to Oracle materialized views   

Finding Oracle materialized view opportunities    

Page 138: 11gR2 ASMCMD Commands

Introduction to Oracle materialized views

Oracle materialized views perform miracles in our goal to reduce repetitive I/O.  You want tips on tuning materialized views internal performance, see:

Oracle materialized views and partitioning   

Materialized Views Tuning    Materialized Views Refreshing Performance   

Oracle materialized views were first introduced in Oracle8, and in Oracle materialized views were enhanced to allow very fast dynamic creation of complex objects. Oracle materialized views allow sub-second response times by pre-computing aggregate information, and Oracle dynamically rewrites SQL queries to reference existing Oracle materialized views. In this article, we continue our discussion of Oracle materialized views and discuss how to set up and configure your Oracle database to use this powerful new feature. We begin with a look at the initialization parameters and continue with details of the effective management and use of Oracle materialized views.

Without Oracle materialized views you may see unnecessary repeating large-table full-table scans, as summaries are computed, over and over:

Prerequisites for using Oracle materialized views

In order to use Oracle  materialized views, the Oracle DBA must set special initialization

Page 139: 11gR2 ASMCMD Commands

parameters and grant special authority to the users of Oracle materialized views. You start by setting these initialization parameters within Oracle to enable the mechanisms for Oracle materialized views and query rewrite, as shown here:

trusted:  Assumes that the Oracle materialized view is current. enforced (default):  Always goes to Oracle materialized view with fresh data. 

stale_tolerated:  Uses Oracle materialized view with both stale and fresh data

Next, you must grant several system privileges to all users who will be using the Oracle materialized views. In many cases, the Oracle DBA will encapsulate these grant statements into a single role and grant the role to the end users:

grant query rewrite to scott;grant create materialized view to scott;alter session set query_rewrite_enabled = true;

Invoking SQL query rewrite

Once Oracle materialized views have been enabled, Oracle provides several methods for invoking query rewrite. Query rewrite is generally automatic, but you can explicitly enable it by using Isession, alter system, or SQL hints: 

ALTER {SESSION|SYSTEM} DISABLE QUERY REWRITE

Select /*+REWRITE(mv1)*/...

Refreshing materialized views

In Oracle, if you specify REFRESH FAST for a single-table aggregate Oracle materialized view, you must have created a materialized view log for the underlying table, or the refresh command will fail. When creating an Oracle materialized view, you have the option of specifying whether the refresh occurs manually (ON DEMAND) or automatically (ON COMMIT, DBMS_JOB). To use the fast warehouse refresh facility, you must specify the ON DEMAND mode. To refresh the Oracle materialized view, call one of the procedures in DBMS_MVIEW.

The DBMS_MVIEW package provides three types of refresh operations: 

Page 140: 11gR2 ASMCMD Commands

DBMS_MVIEW.REFRESH:  Refreshes one or more Oracle materialized views 

DBMS_MVIEW.REFRESH_ALL_MVIEWS:  Refreshes all Oracle materialized views 

DBMS_MVIEW.REFRESH_DEPENDENT:  Refreshes all table-based Oracle materialized views

Manual complete refresh

A complete refresh occurs when the Oracle materialized view is initially defined, unless it references a prebuilt table, and a complete refresh may be requested at any time during the life of the Oracle materialized view. Because the refresh involves reading the detail table to compute the results for the Oracle materialized view, this can be a very time-consuming process, especially if huge amounts of data need to be read and processed.

Manual fast (incremental) refresh

If you specify REFRESH FAST (which means that only deltas performed by UPDATE, INSERT, DELETE on the base tables will be refreshed), Oracle performs further verification of the query definition to ensure that fast refresh can always be performed if any of the detail tables change. These additional checks include the following: 

An Oracle materialized view log must be present for each detail table. 

The RowIDs of all the detail tables must appear in the SELECT list of the MVIEW query definition.

If there are outer joins, unique constraints must be placed on the join columns of the inner table.

You can use the DBMS_MVIEW package to manually invoke either a fast refresh or a complete refresh, where F equals Fast Refresh and C equals Complete Refresh:

EXECUTE DBMS_MVIEW.REFRESH('emp_dept_sum','F');

Automatic fast refresh of materialized views

The automatic fast refresh feature is completely new in Oracle, so you can refresh a snapshot with DBMS_JOB in a short interval according to the snapshot log. With Oracle, it's possible to refresh automatically on the next COMMIT performed at the master table. This ON COMMIT refreshing can be used with materialized views on single-table aggregates and materialized views containing joins only. ON COMMIT MVIEW logs must be built as ROWID logs, not as primary-key logs. For performance reasons, it's best to create indexes on the ROWIDs of the MVIEW. Note that the underlying table for the MVIEW can be prebuilt.

Below is an example of an Oracle materialized view with an ON COMMIT refresh.

Page 141: 11gR2 ASMCMD Commands

CREATE MATERIALIZED VIEW   empdepON PREBUILT TABLEREFRESH FAST ON COMMITENABLE QUERY REWRITE  AS SELECT empno, ename, dname, loc,         e.rowid emp_rowid,         d.rowid dep_rowid    FROM emp e, dept d   WHERE e.deptno = d.deptno;

Creating an Oracle materialized view

To see all the steps in the creation of a materialized view, let’s take it one step at a time. The code for each step is shown here:

Step 1

optimizer_mode = choose, first_rows, or all_rowsjob_queue_interval = 3600job_queue_processes = 1query_rewrite_enabled = truequery_rewrite_integrity = enforcedcompatible = 8.1.5.0.0 (or greater)

Step 2

CREATE MATERIALIZED VIEW emp_sumENABLE QUERY REWRITEAS SELECT deptno,job,SUM(sal)      FROM empGROUP BY deptno,job  PCTFREE 5  PCTUSED 60  NOLOGGING PARALLEL 5  TABLESPACE users    STORAGE (INITIAL 50K NEXT 50K)    USING INDEX STORAGE (INITIAL 25K NEXT 25K)  REFRESH FAST  START WITH SYSDATENEXT SYSDATE + 1/12;

Step 3

execute dbms_utility.analyze_schema('SCOTT','ESTIMATE');execute dbms_mview.refresh('emp_sum');

Page 142: 11gR2 ASMCMD Commands

Step 4

set autotrace on explainSELECT deptno, job, SUM(sal)  FROM empGROUP BY deptno, job;Execution Plan-----------------------------------0 SELECT STATEMENT Optimizer=CHOOSE1 0 TABLE ACCESS (FULL) OF 'EMP_SUM'

Step 5

CREATE MATERIALIZED VIEW LOG ON   emp_sumWITH ROWID;CREATE MATERIALIZED VIEW LOG ON   deptWITH ROWID;

Step 6

EXECUTE DBMS_MVIEW.REFRESH('emp_sum');

1. Set the initialization parameters and bounce the database. 2. Create the materialized view table. Here, we specify that the materialized view will be refreshed every two hours with the refresh fast option. Instead of using DBMS_MVIEW, you can automatically refresh the MVIEW (Snapshot) using Oracle DBMS_JOB Management. 

3. Create the optimizer statistics and refresh the materialized view. 4. Test the materialized view. 5. Create the MVIEW log(s) MATERIALIZED VIEW. 6. Execute a manual complete refresh.

Monitoring materialized views

Oracle provides information in the data dictionary to monitor the behavior of Oracle materialized views. When you’re monitoring Oracle materialized views, it’s critical that you check the refresh interval in the dba_jobs view. Here is a SQL statement to check the generated job status for Oracle materialized views:

Page 143: 11gR2 ASMCMD Commands

Conclusion

Oracle materialized views are quite complex in nature and require a significant understanding to be used effectively. In this article, I covered the required set-up methods and the steps for creating Oracle materialized views and appropriate refresh intervals

Types of Histogram

Height-balanced histograms: the column values are divided into bands so that each band contains approximately the same number of rows. The useful information that the histogram provides is where in the range of values the endpoints fall. 

o Height-Balanced Histogram with Uniform Distribution 

o Height-Balanced Histogram with Non-Uniform Distribution

Frequency histograms: each value of the column corresponds to a single bucket of the histogram. Each bucket contains the number of occurrences of that single value. Frequency histograms are automatically created instead of height-balanced histograms when the number of distinct values is less than or equal to the number of histogram buckets specified. 

Query for the type of histogram: 

SQL> select owner, table_name, column_name, num_distinct, num_buckets, histogram from DBA_TAB_COL_STATISTICS order by 1,2,3

Generating Histogram and Disabling Histogram

Page 144: 11gR2 ASMCMD Commands

DBMS_STATS

Syntax: dbms_stats.gather_table_stats(<schema_name>, <table_name>,METHOD_OPT => FOR COLUMN SIZE <integer> <column_name>) Example: 

SQL> exec dbms_stats.gather_schema_stats(ownname=> &owner , estimate_percent=> 10 , method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => TRUE);SQL> DBMS_STATS.GATHER_table_STATS (OWNNAME => &owner, TABNAME => &tab_name, METHOD_OPT => 'FOR COLUMNS SIZE 10 &col_name');

Histograms are specified using the METHOD_OPT argument of the DBMS_STATS gathering procedures. Oracle Corporation recommends setting the METHOD_OPT to FOR ALL COLUMNS SIZE AUTO. With this setting, Oracle automatically determines which columns require histograms and the number of buckets (size) of each histogram. You can also manually specify which columns should have histograms and the size of each histogram.

Disabling Histogram: DBMS_STATS to gather statistics using ‘METHOD_OPT => 'FOR COLUMNS SIZE 1’  

Analyze

Syntax: ANALYZE TABLE <schema.object_name> COMPUTE STATISTICS FOR COLUMNS <column_name>SIZE <number_of_buckets_integer>

Viewing Histogram Statistics

Histogram Types: 

SQL> select owner, table_name, column_name, num_distinct, num_buckets, histogram from DBA_TAB_COL_STATISTICS order by 1,2,3

Histogram Statistics: see if the histogram is uniformed or skewed

SQL> select * from dba_histograms order by 1,2,3

SYS.COL_USAGE$: monitor the usage of predicates on columns in select statements. DBMS_STATS will make use of that info when deciding if it needs to create a histogram on a column. 

Page 145: 11gR2 ASMCMD Commands

SQL> select distinct r.name owner, o.name table_name, c.name col_name, equality_preds, equijoin_preds, nonequijoin_preds, range_preds, like_preds, null_preds from sys.col_usage$ u, sys.obj$ o, sys.col$ c, sys.user$ r where o.obj# = u.obj# and c.obj# = u.obj# and c.col# = u.intcol# and o.owner# = r.user# and (u.equijoin_preds > 0 or u.nonequijoin_preds > 0) order by 1,2,3

Histogram Distribution: 

SQL> SELECT endpoint_number, endpoint_value FROM DBA_HISTOGRAMS WHERE table_name = &tab_name and column_name = &col_name ORDER BY endpoint_number;

Creating the Recovery Catalog Owner

To create the recovery catalog schema in the recovery catalog database:

1. Start SQL*Plus and then connect with administrator privileges to the database containing the recovery catalog.

Example:connect to recovery catalog database (catdb)SQL> CONNECT SYS/oracle@catdb AS SYSDBA

2. Create a user, schema and tablespace for the recovery catalog.

Example: 1. create tablespace (rmantbs)SQL> create tablespace rmantbsdatafile '/u02/oradata/RMANDB/rmantbs.dbf' size 100MAUTOEXTEND OFFBLOCKSIZE 8192EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64kSEGMENT SPACE MANAGEMENT auto;2. Create user (rman)SQL> CREATE USER rman IDENTIFIED BY rmanTEMPORARY TABLESPACE temp DEFAULT TABLESPACE rmantbsQUOTA UNLIMITED ON rmantbs;

3. Grant the RECOVERY_CATALOG_OWNER role to the schema owner. This role provides the user with privileges to maintain and query the recovery catalog.

Page 146: 11gR2 ASMCMD Commands

Example:SQL> GRANT RECOVERY_CATALOG_OWNER TO rman;

4. Grant other desired privileges to the RMAN user.

Example:SQL> GRANT CONNECT, RESOURCE TO rman;

Creating the Recovery Catalog

To create the recovery catalog:

1. Connect to the database that will contain the catalog as the catalog owner.

Example:connect to recovery catalog database (catdb)% rman CATALOG rman/cat@catdb

Or connect from the RMAN prompt:

Example:% rmanRMAN> CONNECT CATALOG rman/cat@catdb

2. Run the CREATE CATALOG command to create the catalog. If the catalog tablespace is this user's default tablespace, then:

RMAN> CREATE CATALOG;

3. Optionally, start SQL*Plus and query the recovery catalog to see which tables were created:

SQL> SELECT TABLE_NAME FROM USER_TABLES

Registering a Database in the Recovery Catalog

To register the target database:

1. Connect to the target database and recovery catalog database.

Example:connect to the target database and recovery catalog database (catdb)% rman TARGET / CATALOG rman/cat@catdb

Page 147: 11gR2 ASMCMD Commands

2. If the target database is not mounted, then mount or open it. The recovery catalog database must be open.

3. To use RMAN with a target database, register the database.

RMAN> REGISTER DATABASE;

After run REGISTER DATABASE:

RMAN creates rows in the repository that contain information about the target database. RMAN performs a full resynchronization with the catalog in which it transfers all

pertinent data about the target database from the control file and saves it in the catalog.

4. Test that the registration was successful by running REPORT SCHEMA. This command shows the database structure as it is stored in the repository.

RMAN> REPORT SCHEMA;

5. If there are any existing user-created copies of datafiles or archived logs on disk that were created under Oracle release 8.0 or higher, you can add them to the recovery catalog with the CATALOG command.

Example:

RMAN> CATALOG DATAFILECOPY 'users01.dbf';RMAN> CATALOG ARCHIVELOG 'archive1_731.dbf', 'archive1_732.dbf';

Connect at Command Line

Syntax:

RMAN [ TARGET [=] connectStringSpec | { CATALOG [=] connectStringSpec | NOCATALOG } | AUXILIARY [=] connectStringSpec | LOG [=] ['] filename [']... ]...

connectStringSpec::=['] [userid] [/ [password]] [@net_service_name] [']

Page 148: 11gR2 ASMCMD Commands

Example: 1. Connects in NOCATALOG mode% rman TARGET SYS/pwd@target_str 2. Connect to target database and catalog% rman TARGET / CATALOG cat_usr/pwd@cat_str3. Connect to target, catalog and auxiliary databases% rman TARGET / CATALOG cat_usr/pwd@cat_str AUXILIARY aux_usr/pwd@aux_str4. Connect to target database and run command file% rman TARGET SYS/pwd@target_str @/scripts/test.rcv 5. Connect to target and log% rman TARGET / LOG $ORACLE_HOME/dbs/log/backup.log APPEND # using OS Authentication

Connect from RMAN Prompt

In RMAN prompt:

CONNECT TARGET <connectString>:Establishes a connection between RMAN and the target database.

CONNECT CATALOG <connectString>: Establishes a connection between RMAN and the recovery catalog database. You must run this command before running any command that requires a repository. Otherwise, RMAN defaults to NOCATALOG mode and invalidates the use of CONNECT CATALOG in the session.

CONNECT AUXILIARY <connectString>:Establishes a connection between RMAN and an auxiliary instance. You can use an auxiliary instance with the DUPLICATE command or during TSPITR.

Example: 1. Connecting Without a Recovery Catalog: % rman NOCATALOGRMAN> CONNECT TARGET sys/pwd@target_str ;2. Connecting in the Default NOCATALOG Mode: % rmanRMAN> CONNECT TARGET sys/pwd@target_str ;# You cannot run CONNECT CATALOG after this point because RMAN has defaulted to NOCATALOG3.Connecting with a Recovery Catalog: % rmanRMAN> CONNECT TARGET / # connects to the target database using OS authenticationRMAN> CONNECT CATALOG rman/rman@cat_str4.Connecting to Target, Recovery Catalog, and Duplicate Databases: % rmanRMAN> CONNECT TARGET SYS/sysdba@target_str

Page 149: 11gR2 ASMCMD Commands

RMAN> CONNECT CATALOG rman/rman@cat_strRMAN> CONNECT AUXILIARY SYS/sysdba@dupdb

Hiding Passwords When Connecting to Databases

To connect to RMAN from the operating system command line and hide authentication information, you must first start RMAN and then perform either of the following actions:

Run the CONNECT commands at the RMAN prompt. If the password is not provided in the connect string, then RMAN prompts for the password.

Run a command file at the RMAN prompt that contains the connection information. You can set the read privileges on the command file to prevent unauthorized access.

Example: if you are running RMAN in an UNIX environment, then you can use the following procedure:1. Start RMAN without connecting to any databases:% rman

2. Place the connection information in a text file. Place the following lines in a file called connect.rman:CONNECT TARGET SYS/oracle@trgt CONNECT CATALOG rman/cat@catdb

3. Change the permissions on the connect script so that everyone can execute the script but only the desired users have read access. For example, enter:% chmod 711 connect.rman

4. Run the script from the RMAN prompt to connect to the target and catalog databases. RMAN> @connect.rman

RMAN Commands

"@"

 Run a command file.

"@@"

 Run a command file in the same directory as another command file that is currently running. The @@ command differs from the @ command only when run from within a command file.

"ALLOCATE CHANNEL"

Page 150: 11gR2 ASMCMD Commands

Establish a channel, which is a connection between RMAN and a database instance.

"ALLOCATE CHANNEL FOR MAINTENANCE"

Allocate a channel in preparation for issuing maintenance commands such as DELETE.

"BACKUP"

Back up a database, tablespace, datafile, archived log, or backup set.

"BLOCKRECOVER"

Recover an individual data block or set of data blocks within one or more datafiles.

"CATALOG"

Add information about a datafile copy, archived redo log, or control file copy to the repository.

"CHANGE"

Mark a backup piece, image copy, or archived redo log as having the status UNAVAILABLE or AVAILABLE; remove the repository record for a backup or copy; override the retention policy for a backup or copy.

"CONFIGURE"

Configure persistent RMAN settings. These settings apply to all RMAN sessions until explicitly changed or disabled.

"CONNECT"

Establish a connection between RMAN and a target, auxiliary, or recovery catalog database.

"COPY"

Create an image copy of a datafile, control file, or archived redo log.

"CREATE CATALOG"

Create the schema for the recovery catalog.

"CREATE SCRIPT"

Create a stored script and store it in the recovery catalog.

Page 151: 11gR2 ASMCMD Commands

"CROSSCHECK"

Determine whether files managed by RMAN, such as archived logs, datafile copies, and backup pieces, still exist on disk or tape.

"DELETE"

Delete backups and copies, remove references to them from the recovery catalog, and update their control file records to status DELETED.

"DELETE SCRIPT"

Delete a stored script from the recovery catalog.

"DROP CATALOG"

Remove the schema from the recovery catalog.

"DUPLICATE"

Use backups of the target database to create a duplicate database that you can use for testing purposes or to create a standby database.

"EXECUTE SCRIPT"

Run an RMAN stored script.

"EXIT"

Quit the RMAN executable.

"HOST"

Invoke an operating system command-line subshell from within RMAN or run a specific operating system command.

"LIST"

Produce a detailed listing of backup sets or copies.

"PRINT SCRIPT"

Display a stored script.

"QUIT"

Page 152: 11gR2 ASMCMD Commands

Exit the RMAN executable.

"RECOVER"

Apply redo logs or incremental backups to a restored backup set or copy in order to update it to a specified time.

"REGISTER"

Register the target database in the recovery catalog.

"RELEASE CHANNEL"

Release a channel that was allocated with an ALLOCATE CHANNEL command.

"REPLACE SCRIPT"

Replace an existing script stored in the recovery catalog. If the script does not exist, then REPLACE SCRIPT creates it.

"REPORT"

Perform detailed analyses of the content of the recovery catalog.

"RESET DATABASE"

Inform RMAN that the SQL statement ALTER DATABASE OPEN RESETLOGS has been executed and that a new incarnation of the target database has been created, or reset the target database to a prior incarnation.

"RESTORE"

Restore files from backup sets or from disk copies to the default or a new location.

"RESYNC"

Perform a full resynchronization, which creates a snapshot control file and then copies any new or changed information from that snapshot control file to the recovery catalog.

"RUN"

Execute a sequence of one or more RMAN commands, which are one or more statements executed within the braces of RUN.

"SEND"

Page 153: 11gR2 ASMCMD Commands

Send a vendor-specific quoted string to one or more specific channels.

"SET"

Make the following session-level settings:

    * Control whether RMAN commands are displayed in the message log    * Set the DBID when restoring a control file or server parameter file    * Specify new filenames for restored datafiles    * Specify a limit for the number of permissible block corruptions    * Override default archived redo log destinations    * Specify the number of copies of each backup piece    * Determine which server session corresponds to which channel    * Control where RMAN searches for backups when using an Oracle Real Application Clusters configuration    * Override the default format of the control file autobackup

"SHOW"

Displays the current CONFIGURE settings.

"SHUTDOWN"

Shut down the target database. This command is equivalent to the SQL*Plus SHUTDOWN command.

"SPOOL"

Write RMAN output to a log file.

"SQL"

Execute a SQL statement from within Recovery Manager.

"STARTUP"

Start up the target database. This command is equivalent to the SQL*Plus STARTUP command.

"SWITCH"

Specify that a datafile copy is now the current datafile, that is, the datafile pointed to by the control file. This command is equivalent to the SQL statement ALTER DATABASE RENAME FILE as it applies to datafiles.

Page 154: 11gR2 ASMCMD Commands

"UPGRADE CATALOG"

Upgrade the recovery catalog schema from an older version to the version required by the RMAN executable.

"VALIDATE"

Examine a backup set and report whether its data is intact. RMAN scans all of the backup pieces in the specified backup sets and looks at the checksums to verify that the contents can be successfully restored.

Flashback

Overview

Flashback Time Navigation

Flashback Query– Query all data at point in time. 

Flashback Versions Query– See all versions of a row between two times.– See transactions that changed the row. 

Flashback Transaction Query– See all changes made by a transaction

Flashback Error Correction

Recovery at all levels

Database level:– Flashback Database restores the whole database to a point in time. 

Table level:– Flashback Table restores all rows in a set of tables to a point in time.– Flashback Drop restores a dropped table or index. 

Row level:– Flashback Query features are used to restore rows to a point in time. 

Oracle Flashback Technology

 

Flashback Technology

Scenario Uses/PriviledgesAffects Data

Database Truncate table Flashback Logs/ Y

Page 155: 11gR2 ASMCMD Commands

undesired changes made by DDL or DML

drop user

batch job: partial changes

SYSDBA DB connections

Drop Drop TableRecyclebin/

Object privileges for objects in the recycle bin before they were dropped

Y

QueryCompare current and past data or data from different point-in-time

Undo Data, Flashback Archive N

TableUpdate with the wrong or no WHERE clause

Undo Data, Flashback Archive/

FLASHBACK TABLE system privilege and the appropriate object privileges

Y

Transaction Backout

Reverse transaction(s) with/without cascade (DBMS_FLASHBACK)

Undo Data, Flashback Archive Y

Transaction Query

Investigate several historical states of data

Undo Data, Flashback Archive/

SELECT ANY TRANSACTION system privilege

N

Version Query Compare versions of a row

Undo Data, Flashback Archive/

FLASHBACK TABLE system privilege and the appropriate object privileges

N

Flashback Database     Flashback Versions Query and Flashback Transaction Query     Flashback Table     Flashback Drop (Recylebin)     Guaranteed Undo Retention  SCN and Time Mapping Enhancements

o The mapping granularity is three seconds. o The mapping is retained for: Max(five days, UNDO_RETENTION) o  Access the mapping by using the following SQLfunctions:– SCN_TO_TIMESTAMP– TIMESTAMP_TO_SCNSQL> SELECT current_scn, SCN_TO_TIMESTAMP(current_scn), TIMESTAMP_TO_SCN(systimestamp)FROM v$database;

Page 156: 11gR2 ASMCMD Commands

Flashback database

Flashbacking a database means going back to a previous database state.  The Flashback Database feature provides a way to quickly revert entire Oracle database to the state it was in at a past point in time. 

A new background process RVWR introduced which is responsible for writing flashback logs which stores pre-image(s) of data blocks 

One can use Flashback Database to back out changes that: o Have resulted in logical data corruptions. o Are a result of user error.

This feature is not applicable for recovering the database in case of media failure. 

How to Configure Flashback database

Prerequisite

a) Database must be in archivelog mode.b) Last clean shutdown.

Steps

1. Configure the following parameters in parameter file(init.ora) or spfile 

DB_RECOVERY_FILE_DESTdynamically modifiable

Physical location where RVWR background process writes flashback logs

DB_RECOVERY_FILE_DEST_SIZE dynamically  Maximum size flashback logs can occupy in 

Page 157: 11gR2 ASMCMD Commands

modifiable DB_RECOVERY_FILE_DEST

DB_FLASHBACK_RETENTION_TARGETdynamically modifiable

Upper limit in minutes on how far back one can flashback the database

Example:SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area' scope=spfile;SQL> alter system set db_recovery_file_dest_size=2147483648 scope=spfile;SQL> alter system set DB_FLASHBACK_RETENTION_TARGET=2880; (2 days)

2. Turn flashback on: 

SQL> Startup mount exclusive;SQL> alter database archivelog;SQL> Alter database flashback on;SQL> Alter database open;

3. Check status 

SQL> SELECT flashback_on, log_mode FROM gv$database;Sql> SELECT estimated_flashback_size FROM gv$flashback_database_log;$ ps -eaf | grep rvwr

 

Disable Flashback Database

Disabling Flashback Database with ALTER DATABASE FLASHBACK OFF automatically deletes all flashback logs in the flash recovery area.

Flashback Database Using SQL or RMAN Commands

Flashback Using SQL

Use an SCN or a time stamp in the SQL version Example: Flash back the database to a day before using SQLSQL> shutdown immediate;SQL> startup mount exclusive;

Page 158: 11gR2 ASMCMD Commands

SQL> flashback database to timestamp(sysdate-1);SQL> alter database open resetlogs;

Flashback Using RMAN

Using RMAN, you can flash back to a time stamp, SCN, or log sequence number (SEQUENCE) and thread number (THREAD). 

Example: RMAN> FLASHBACK DATABASE TO TIME = TO_DATE('2002-12-10 16:00:00','YYYY-MM-DD HH24:MI:SS');RMAN> FLASHBACK DATABASE TO SCN=23565;RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1;

Views

V$FLASHBACK_DATABASE_LOG - monitor the estimated and actual size of the flashback logs in the flash recovery - Check flash recovery area disk quota:SQL> select retention_target, flashback_size, estimated_flashback_size FROM V$FLASHBACK_DATABASE_LOG;- Determine the current flashback window:SQL> SELECT oldest_flashback_scn,oldest_flashback_time FROM V$FLASHBACK_DATABASE_LOG;

V$FLASHBACK_DATABASE_STAT - monitors the overhead of logging flashback data in the flashback logs. It contains at most 24 rows, with one row for each of the last 24 hours. - The flashback generation for the last hour:SQL> select to_char(end_time,'yyyy-mm-dd hh:miAM') end_timestamp, flashback_data, db_data, redo_data from v$flashback_database_stat where rownum=1;

Excluding Tablespaces from Flashback Database

SQL> ALTER TABLESPACE <ts_name> FLASHBACK {ON|OFF}SQL> SELECT name, flashback_on 2 FROM v$tablespace;

Notes:

Take the tablespace offline before you perform the database flashback operation. After performing Flashback Database, drop the tablespace or recover the offline files with traditional point-in-time recovery.

Flash back a RESETLOGS operation

You can flash back to a point in time before a RESETLOGS operation:SQL> FLASHBACK DATABASE TO BEFORE RESETLOGS;

Limitations

Page 159: 11gR2 ASMCMD Commands

 You cannot use Flashback Database in the following situations:o The control file has been restored or re-created.o A tablespace has been dropped.o A data file has been shrunk.

Flashback Versions Query

Flashback Versions Query provides an easy way to show all versions of all rows in a table between two SCNs or time stamps, whether the rows were inserted, deleted, or updated.

Syntax: query the actual tableSELECT [pseudo_columns]...FROM table_nameVERSION BETWEEN{SCN | TIMESTAMP {expr | MINVALUE} AND{expr | MAXVALUE}}[AS OF {SCN|TIMESTAMP expr}]WHERE [pseudo_column | column] . .

The pseudo-columns:VERSIONS_STARTSCN The SCN at which this version of the row was createdVERSIONS_STARTTIME The time stamp at which this version of the row was createdVERSIONS_ENDSCN The SCN at which this row no longer existed (either changed or deleted)VERSIONS_ENDTIME The time stamp at which this row no longer existed (either changed or deleted)VERSIONS_XID The transaction ID of the transaction that created this version of the rowsVERSIONS_OPERATION The operation done by this transaction: I=Insert, D=Delete, U=Update

MINVALUE and MAXVALUE resolve to the SCN or time stamp of the oldest and most recent data available, respectively

Example 1: Track history of changes made on employee number 111. The period of the past is determined by the oldest SCN available and the read SCN of the query (5525300):SQL> SELECT versions_xid AS XID, versions_startscn AS START_SCN, versions_endscn AS END_SCN, versions_operation AS OPERATION, first_name FROM employees VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE AS OF SCN 5525300 WHERE employee_id = 111;

Example 2:Track the salary of employee number 124. Use midnight as your starting point for the Flashback Versions Query:SQL> select versions_startscn startscn,versions_endscn endscn, versions_xid xid, versions_operation oper, employee_id empid, last_name name, salary sal from hr.employees versions between timestamp trunc(systimestamp) and systimestamp where employee_id = 124;

Maximum available versions are dependent on the UNDO_RETENTION parameter. Limitations:

Page 160: 11gR2 ASMCMD Commands

o The VERSIONS clause cannot be used to query:– External tables– Temporary tables– Fixed tables– Views

o The VERSIONS clause cannot span DDLs. o Segment shrink operations are filtered out.

Flashback Transaction Query

Flashback Transaction Query is a diagnostic tool that you can use to view changes made to the database at the transaction level.

FLASHBACK_TRANSACTION_QUERY o retrieve transaction information for all tables involved in a transaction. o provides the SQL statements that you can use to undo the changes made by a

particular transaction Example 1: returns information about all transactions, both active and committed, in all

undo segments in the database.SQL> SELECT operation, undo_sql, table_name FROM flashback_transaction_query;

Example 2: returns information relevant to the transaction whose identifier is specified in the WHERE clause.SQL> SELECT operation, undo_sql, table_name FROM flashback_transaction_query WHERE xid = HEXTORAW('8C0024003A000000') ORDER BY undo_change#;

Example 3: returns information about all transactions that began and committed within a half-hour interval.SQL> SELECT operation, undo_sql, table_name FROM flashback_transaction_query WHERE start_timestamp >= TO_TIMESTAMP ('2003-10-21 11:00:00','YYYY-MM-DD HH:MI:SS')AND commit_timestamp <= TO_TIMESTAMP('2003-10-21 11:30:00','YYYY-MM-DD HH:MI:SS');

Considerations o DDLs are seen as dictionary updates. o Updates on key columns of IOTs are seen as delete statements followed by insert

statements. o Dropped objects appear as object numbers. o Dropped users appear as user identifiers. o Minimal supplemental logging may be needed:

ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;

Flashback Table

Overview

Page 161: 11gR2 ASMCMD Commands

Using Flashback Table, you can recover a set of tables to a specific point in time without having to perform traditional point-in-time recovery operations.

A Flashback Table operation is done in-place while the database is online, by rolling back only the changes that were made to the given tables and their dependent objects.

A Flashback Table statement is executed as a single transaction. All tables must be flashed back successfully or the entire transaction is rolled back.

Note: You can use Flashback Versions Query and Flashback Transaction Query to determine the appropriate flashback time.

Examples

Example 1 : uses a time stamp to determine thepoint in time to which to flash back the EMPLOYEES table.SQL> ALTER TABLE employees ENABLE ROW MOVEMENT;SQL> FLASHBACK TABLE employees TO TIMESTAMP (SYSDATE-1);

Example 2: uses an SCN instead of a time stamp

because both the EMPLOYEES table and the DEPARTMENTS table are linked by a referential integrity constraint, the FLASHBACK TABLE statement groups both tables together.

In the default operation mode, triggers currently enabled on the tables being flashed back are disabled for the duration of the flashback operation and brought back to the enabled state after the completion of the flashback operation.

SQL> ALTER TABLE employees ENABLE ROW MOVEMENT;SQL> ALTER TABLE departments ENABLE ROW MOVEMENT;SQL> FLASHBACK TABLE employees, departments TO SCN 5525293 ENABLE TRIGGERS;

 

Considerations

Flashback Table is executed within a single transaction. It acquires exclusive DML locks. Statistics are not flashed back. Current indexes and dependent objects are maintained. Operation is written to the alert log file. The operation maintains data integrity. Flashback Table cannot span DDLs. Flashback Table cannot be performed on system tables.

10g Recycle Bin

Page 162: 11gR2 ASMCMD Commands

Introduction

The Recycle Bin is a virtual container where all dropped objects reside.

The objects are occupying the same space as when they were created. Dropped tables and any associated objects such as indexes, constraints, nested tables, and

other dependant objects are not moved, they are simply renamed with a prefix of BIN$$. Users can view their dropped tables by querying the new RECYCLEBIN view. Objects in the Recycle Bin will remain in the database until the owner of the dropped

objects decides to permanently remove them using the new PURGE command. Objects in the Recycle Bin will be automatically purged by the space reclamation process

if o A user creates a new table or adds data that causes their quota to be exceeded. o The tablespace needs to extend its file size to accommodate create/insert

operations. When a tablespace or a user is dropped there is NO recycling of the objects. Recyclebin does not work for SYS objects

Technical Details

Tables and Views of Recycle Bin Purging Objects in Recycle Bin   Restoring Objects from Recycle Bin Disabling Recycle Bin

Limitations

Protected tables:– Are non-SYSTEM tablespace tables– Are stored in locally managed tablespaces– Do not use FGA or VPD

The following dependencies are not protected:– Bitmap join indexes– Materialized view logs– Referential integrity constraints– Indexes dropped before tables

 Purged tables cannot be flashed back.

Flash Recovery Area Occupants

Control files - A copy of the control file is created in the flash recovery area when the database is created. This copy of the control file can be used as one of the mirrored copies of the control file to ensure that at least one copy of the control file is available after a media failure.

Archived log files - When the flash recovery area is configured, the initialization parameter LOG_ARCHIVE_DEST_10 is automatically set to the flash recovery area location. The corresponding

Page 163: 11gR2 ASMCMD Commands

ARCn processes create archived log files in the flash recovery area and any other defined LOG_ARCHIVE_DEST_n locations.

Flashback logs - If Flashback Database is enabled, then its flashback logs are stored in the flashrecovery area.

Control file and SPFILE autobackups - The flash recovery area holds control file and SPFILE autobackups generated by RMAN, if RMAN is configured for control file autobackup. When RMAN backs up datafile #1, the control file is automatically included in the RMAN backup.

Data file copies - For RMAN BACKUP AS COPY image files, the default destination is the flash recovery area.

RMAN backup sets - By default, RMAN uses the flash recovery area for both backup sets and image copies. In addition, RMAN puts restored archive log files from tape into the flash recovery area in preparation for a recovery operation.

Defining Flash Recovery Area

 The flash recovery area is defined by setting the following initialization parameters:

DB_RECOVERY_FILE_DEST_SIZE: Specify the disk limit, which is the amount of space the flash recovery area is permitted to use with this initialization parameter. 

The minimum size of the flash recovery area should be at least large enough to contain archive logs that have not been copied to tape. 

To maximize the benefits of the flash recovery area, it should be large enough to hold a copy of all datafiles, all incremental backups, online redologs, archived redo logs not yet backed up to tape, control files, and control file autobackups.

 DB_RECOVERY_FILE_DEST: Specify this initialization parameter as a valid destination to create the flash recovery files.

Notes:

You must specify the DB_RECOVERY_FILE_DEST_SIZE initialization parameter before the DB_RECOVERY_FILE_DEST initialization parameter.

These parameters are dynamic and can be altered or disabled.SQL> ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = 4G;SQL> ALTER SYSTEM SET DB_RECOVERY_FILE_DEST = '/oracle/frec_area';

All instances in a RAC database must have the same values for these parameters. Theflash recovery area is also supported by Data Guard.

Flash Recovery Directory Structure

The flash recovery area directory structure is used by RMAN in a very organized fashion with separate directories for each file type, such as archived logs, backupsets, image copies, control file autobackups, and so forth. In addition, each subdirectory is further divided by a datestamp,making it easy to locate backupsets or image copies based on their creation date.

 

Backing Up the Flash Recovery Area

Page 164: 11gR2 ASMCMD Commands

RMAN> BACKUP RECOVERY AREA;This command backs up all flash recovery files created in the current (and any previous) flashrecovery area destinations that have not previously been backed up to tape. Files that fall intothis category are full and incremental backup sets, control file autobackups, archive logs, anddata file copies. Other files such as flashback logs, incremental bitmaps, current control file,and online redo log files are not backed up.

RMAN> BACKUP RECOVERY FILES;This command backs up all recovery files on disk that have not previously been backed up totape. The files that fall into this category are full and incremental backup sets, control fileautobackups, archive logs, and data file copies. This can also include files not part of arecovery area

Views

 V$RECOVERY_FILE_DEST - information regarding the flash recovery area:SQL> SELECT name, space_limit AS size, space_used AS used, space_reclaimable AS reclaimable, number_of_files AS files FROM v$recovery_file_dest ;

V$FLASH_RECOVERY_AREA_USAGE - indicate the flash recovery area disk space usage:SQL> SELECT file_type,percent_space_used AS used,percent_space_reclaimable AS reclaimable, number_of_files AS number FROM v$flash_recovery_area_usage ;

New columnso IS_RECOVERY_DEST_FILE– Indicates whether the file was created in the flash recovery area– Values: YES / NO– Tracked in V$CONTROLFILE, V$LOGFILE, V$ARCHIVED_LOG, V$DATAFILE_COPY,V$BACKUP_PIECE

o BYTES– Size of the file– Tracked in V$BACKUP_PIECE

Best Practices for the Database and Flash Recovery Area

Use OMF for the database area:– Simplifies the administration of database files– Puts database files, control files, and online logs in the database area

Use the flash recovery area for recovery-related files:– Simplifies the location of database backups– Automatically manages the disk space allocated for recovery files– No changes needed for existing scripts– Puts database backups, archive logs, and control file backups in the flash recovery area

Recovery from User Error

Page 165: 11gR2 ASMCMD Commands

Flashback Database

Using Flashback Database enables you to return your whole database to a previous state without restoring old copies of your datafiles from backup, as long as you have enabled logging for flashback database in advance. >>more about Flashback Database

Creating Normal and Guaranteed Restore Points

Guaranteed restore points ensure that you can return your database to a specific previous time using Flashback Database.

Normal restore points do not provide protection for your data. You can avoid having to record the SCN of the database before an operation from which you wish to recover using point-in-time recovery or Flashback Table, or having to investigate after the operation to determine the correct SCN.

Database Point-in-Time Recovery

You can perform point-in-time recovery (incomplete recovery), bringing one tablespace or the whole database back to its state before the time of the error.

You need: 1) backups from before the time of the error; 2) the redo logs from the time of the backup to the time of the error.

DBPITR: 1. Restore whole database backup.2. Recover the database to the time just before the error.3. Open RESETLOGS

TSPITR: 1. Create auxiliary instance with RMAN or user-managed methods.2. Recover the tablespace on the auxiliary to the time just before the error.3. Import data back into the primary database.

Importing Lost Objects from Logical Backup

If you have performed a logical backup by exporting the contents of the affected tables, sometimes you can import the data back into the table. This technique presumes that you are regularly exporting logical backups of your data, and that any changes between exports are unimportant.

Recovery from Media Failures

RMAN Media Recovery General Steps

The generic steps for media recovery using RMAN are as follows:

Page 166: 11gR2 ASMCMD Commands

1. Place the database in the appropriate state: mounted or open (refer to the following Table). For example, mount the database when performing whole database recovery, or open the database when performing online tablespace recovery

2. To perform incomplete recovery, use the SET UNTIL command to specify the time, SCN, or log sequence number at which recovery terminates. Alternatively, specify the UNTIL clause on the RESTORE and RECOVER commands.

3. Restore the necessary files using the RESTORE command.4. Recover the datafiles using the RECOVER command.5. Place the database in its normal state (refer to the following Table). For example, open it

or bring recovered tablespaces online

Media Failures and Recovery Strategies

Lost/Inaccessible Files Archiving Mode Status Strategy

One or more datafiles NOARCHIVELOG Closed

* Restore whole database from a consistent database backup.* All changes made after the backup are lost.* Open with the RESETLOGS option.Note: The only time you can open a database without performing RESETLOGS after restoring a NOARCHIVELOG backup is when you have not already overwritten the online log files that were current at the time of the most recent backup.

One or more datafiles and an online redo log

NOARCHIVELOG Closed* Restore whole database from consistent backup.* Lose all changes made after the last backup. * Open with the RESETLOGS option.

One or more datafiles and all control files

NOARCHIVELOG Closed* Restore the whole database and control file from consistent backup. * Lose all changes made after the last backup. * Open the database with the RESETLOGS option.

One or more (but not all) datafiles

ARCHIVELOG Open

* Perform tablespace or datafile recovery while the database is open. * The tablespaces or datafiles are taken offline, restored from backups, recovered, and placed online.* No changes are lost * The database remains available during the recovery.

All datafiles ARCHIVELOG Closed

* Restore the backup datafiles* Mount the control file and recover the database completely. * Assuming all redo logs are available, open the database as normal (that is, do not perform a RESETLOGS).

One or more datafiles and an archived redo log required for recovery

ARCHIVELOG Open* Perform TSPITR on the tablespaces containing the lost datafiles up to the point of the latest available archived redo log.

All control files and possibly one or more datafiles

ARCHIVELOGNot open

* Restore the lost control files and datafiles from backups and recover the datafiles. * No changes are lost* The database is unavailable during recovery. * Open with the RESETLOGS option.

All control files and possibly one or more datafiles, as well as an archived or online redo log required for recovery

ARCHIVELOGNot open

* Restore the necessary files from backups* Perform incomplete recovery of the database up to the point of the most recent available log.* Lose all changes contained in the lost log and in all subsequent logs.* Open with the RESETLOGS option.

Online Redo Log Recovery

Page 167: 11gR2 ASMCMD Commands

The method of recovery from loss of all members of an online log group depends on a number of factors, such as: * The state of the database (open, crashed, closed consistently, and so on)* Whether the lost redo log group was current* Whether the lost redo log group was archived

Scenarios: Lose the current group, and the database is not closed consistently (either

it is open, or it has crashed): * restore an old backup * perform point-in-time recovery* OPEN RESETLOGS. * lose all transactions that were in the lost log. * take a new full database backup immediately after the OPEN RESETLOGS.

o Lose the current redo log group, and the database is closed consistently: * perform OPEN RESETLOGS with no transaction loss. * take a new full database backup after that

o Lose a noncurrent redo log group: * use the ALTER DATABASE CLEAR LOGFILE statement to re-create all members in the group. * no transactions are lost. * If the lost redo log group was archived before it was lost, then nothing further is required. * Otherwise, you should immediately take a new full backup of your database.

Recovery from Datafile Block Corruption

Introduction

Use the RMAN BLOCKRECOVER command to perform block media recovery. Block media recovery recovers an individual corrupt datablock or set of datablocks

within a datafile. In cases when a small number of blocks require media recovery, you can selectively

restore and recover damaged blocks rather than whole datafiles. Advantages:

o Lowers the Mean Time to Recovery (MTTR) because only blocks needing recovery are restored and only necessary corrupt blocks undergo recovery.

o Allows affected datafiles to remain online during recovery of the blocks.

Restrictions

You can only perform block media recovery with RMAN. No SQL*Plus recovery interface is available.

Page 168: 11gR2 ASMCMD Commands

You can only perform complete recovery of individual blocks. In other words, you cannot stop recovery before all redo has been applied to the block.

You can only recover blocks marked media corrupt. The V$DATABASE_BLOCK_CORRUPTION view indicates which blocks in a file were marked corrupt since the most recent BACKUP or BACKUP ... VALIDATE command was run against the file.

You must have a full RMAN backup. Incremental backups are not used by block media recovery. Only full backups and archived log files are used.

Block media recovery is able to restore blocks from parent incarnation backups and recover the corrupted blocks through a RESETLOGS.

Blocks that are marked media corrupt are not accessible to users until recovery is complete. Any attempt to use a block undergoing media recovery results in an error message indicating that the block is media corrupt.

Identify Block Corruption

Block-level data loss usually results from intermittent, random I/O errors that do not cause widespread data loss, as well as memory corruptions that get written to disk.Block corruption are reported in the following locations:

Error messages in standard output The alert log User trace files Results of the SQL commands ANALYZE TABLE and ANALYZE INDEX Results of the DBVERIFY utility Third-party media management output

Example:1) you discover the following messages in a user trace file:ORA-01578: ORACLE data block corrupted (file # 7, block # 3)ORA-01110: data file 7: '/oracle/oradata/trgt/tools01.dbf'ORA-01578: ORACLE data block corrupted (file # 2, block # 235)ORA-01110: data file 2: '/oracle/oradata/trgt/undotbs01.dbf'

2) You can then specify the corrupt blocks in the BLOCKRECOVER command as follows:RMAN>BLOCKRECOVER            DATAFILE 7 BLOCK 3             DATAFILE 2 BLOCK 235;

Block Media Recovery When Redo Is Missing

Block media recovery can survive gaps in the redo stream if the missing or corrupt redo records do not affect the blocks being recovered.Block media recovery only requires an unbroken set of redo changes for the blocks being recovered.

Page 169: 11gR2 ASMCMD Commands

Each block is recovered independently during block media recovery, so recovery may be successful for a subset of blocks.

When RMAN first detects missing or corrupt redo records during block media recovery, it does not immediately signal an error because the block undergoing recovery may become a newed block later in the redo stream. When a block is newed all previous redo for that block becomes irrelevant because the redo applies to an old incarnation of the block. For example, the database can new a block when users delete all the rows recorded in the block or drop a table.

 Data Protection Strategies

Backup and Recovery - A well-designed and well-integrated Backup and Recovery strategy, without data loss, is a must for every database deployment. Effective backup strategies usually include local and remote copies of data, full and incremental backups, online backups, support for desired secondary devices (e.g. hi-speed tape, disks), off site tape archiving, etc.

Snapshots - Snapshots are images of all or part of a disk filesystem that are taken periodically and stored in another disk allocation. Thus, in the event of a database corruption, rather than going back to the previous night's tape backup, the DBA may resort to the earliest snapshot in which the corruption does not exist. 

RAID (Redundant Array Of Inexpensive/Independent Disks) - The fundamental principle behind RAID is the use of multiple hard disk drives in an array that behaves like a single large, fast one. There are many different ways to implement a RAID array, using some combination of mirroring, striping, duplexing and parity technologies. The degree of benefits using RAID depends on the exact type of RAID that is configured, but RAID generally provides some combination of these benefits: higher data security, fault tolerance, improved availability, increased and integrated capacity and improved performance.  >>more about RAID

Remote Data Mirroring - In Remote Data Mirroring, data is replicated between a primary and a remote secondary storage subsystem by sending track-by-track changes from the primary site to the remote site over a secure network. In the event of an outage or a disaster, the database may be restored and recovered at the mirrored site, and systems may then point to this mirrored site and continue operations. 

Data Replication - In contrast to remote data mirroring, Data Replication is a software-based solution that copies data from the primary database to one or more secondary databases. These multiple databases together constitute a distributed database system. Transactions can be replicated continuously or on a scheduled basis. Replication usually involves some strategy to resolve conflicting transactions that appear on the same dataset but in different databases.

Automated Standby Databases - Automated Standby Databases are an effective means for disaster recovery by providing a completely automated framework to maintain transactionally consistent copies of the primary database. Changes can be transmitted from the primary database to these standby databases in a synchronous manner - enabling

Page 170: 11gR2 ASMCMD Commands

zero data loss, or in an asynchronous manner - minimizing any potential performance impact on the production system. This technology also provides an automated framework to switch over to the standby system in the event of a disaster or a corruption on the production site, or even during planned maintenances.

Oracle's Data Protection and Disaster Recovery Solutions

Oracle Data Guard - Oracle Data Guard is the most effective and comprehensive data protection and disaster recovery solution available today for enterprise data. Available as a feature of the Enterprise Edition of the Oracle database, it is a software infrastructure that creates, maintains, manages and monitors one or more standby databases to protect enterprise data from failures, disasters, errors, and corruptions. It maintains these standby databases as transactionally consistent copies of the production database. If the production database becomes unavailable because of a planned or an unplanned outage, Data Guard can switch any standby database to the production role, thus minimizing the downtime associated with the outage and enabling zero data loss. Click here for an overview of the functional components of Oracle Data Guard.

Oracle Streams - Oracle Streams, which is an integrated feature of Oracle Database Enterprise Edition, can be used to maintain one or more replica copies of a production database. These replicas need not all be identical - they can be subsets of a production database, or related by a well defined transformation. Streams also supports bi-directional replication with conflict detection and optional resolution. Its unique flexibility supports replication across large numbers of databases via any network topology. Although some business situations may require the flexibility offered by Streams, it is designed for integration of large distributed database environments, rather than pure disaster protection. Click here for further details on Oracle Streams.

Oracle Advanced Replication - Oracle Advanced Replication enables the copying and maintenance of database objects in multiple databases that make up a distributed database system. Oracle Advanced Replication allows an application to update any replicas of a database, and have those changes automatically propagate to other databases, while ensuring global transactional consistency and data integrity. In the event of a disaster at one of the sites, the surviving databases will remain online. Click here for further details on Oracle Advanced Replication.

Oracle Recovery Manager - Oracle Recovery Manager (RMAN) is Oracle's utility to manage the database backup, restore and recovery process. It creates and maintains backup policies, and catalogs all backup and recovery activities. The database can be kept online while RMAN is performing its backup. All data blocks can be analyzed for corruption during backup and restore, to prevent propagation of corrupt data through backups. Most importantly, Recovery Manager ensures all necessary data files are backed up, and the database is recoverable. Click here for further details on Oracle Recovery Manager.

OSCP Validated Remote Mirroring - Through Oracle's Storage Compatibility Program (OSCP), Oracle partners have validated their remote mirroring solutions to be used with the Oracle database. Click here for details on the OSCP. The list of partners which have their solutions validated through OSCP is available here.

Page 171: 11gR2 ASMCMD Commands

Control File Backup and Recovery

Backup Control File

Restore Control Fileo Restore Lost Copy of a Multiplexed Control File o Restore Control File from Backup After Loss of All Current Control Files  o Restore Control File Using RMAN

Recreate Control File

 User Managed Backups of Control File

Backing Up the Control File to a Binary File

A binary backup is preferable to a trace file backup because it contains additional information such as the archived log history, offline range for read-only and offline tablespaces, and backup sets and copies (if you use RMAN). But binary control file backups do not include tempfile entries.

Syntax:ALTER DATABASE BACKUP CONTROLFILE TO <filename>; 

Backing Up the Control File to a Trace File

To back up the control file to a trace file, mount or open the database and issue the following SQL statement:SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE; This command writes a SQL script to the database's trace file where it can be captured and edited to reproduce the control file. 

Specify neither the RESETLOGS nor NORESETLOGS option in the SQL statement, then the resulting trace file contains versions of the control file for both RESETLOGS and NORESETLOGS options. 

Tempfile entries are included in the output using "ALTER TABLESPACE... ADD TEMPFILE" statements.

RMAN Backups of Control File

Auto Backups of Control File

Configure auto backups of control file: RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;RMAN> CONFIGURE CONTROLFILE AUTOBACKUP OFF; (default)

Page 172: 11gR2 ASMCMD Commands

Autobackups of Control File After Backup Acivities:* After every BACKUP command issued at the RMAN prompt.* At the end of a RUN block, if the last command in the block was BACKUP.* Whenever a BACKUP command within a RUN block is followed by a command that is not BACKUP.

Autobackups of Control File After Database Structural Changes:* adding a new tablespace* altering the state of a tablespace or datafile (for example, bringing it online) * adding a new online redo log * renaming a file * adding a new redo thread, and so on 

Manual Backups of Control File

In manual backups, only RMAN repository data for backups within the current RMAN session is in the control file backup, and a manually backed-up control file cannot be automatically restored. 

Run BACKUP CURRENT CONTROLFILE

Example:Backs up the current control file to the default disk device and assigns a tagRMAN> BACKUP CURRENT CONTROLFILE TAG = mondaypmbackup;

Include a backup of the control file within any backup by using the INCLUDE CURRENT CONTROLFILE option of the BACKUP command :

Example:Backs up tablespace users to tape and includes the current control file in the backupRMAN> BACKUP DEVICE TYPE sbt TABLESPACE users INCLUDE CURRENT CONTROLFILE;

Back up datafile 1, because RMAN automatically includes the control file and SPFILE in backups of datafile 1

Backing Up a Control File Copy 

Example: Creates the control file copy '/tmp/control01.ctl' on disk and then backs it up to tape:RMAN> BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/tmp/control01.ctl';RMAN> BACKUP DEVICE TYPE sbt CONTROLFILECOPY '/tmp/control01.ctl';

Restore Lost Copy of a Multiplexed Control File

Copying a Multiplexed Control File to a Default Location

Page 173: 11gR2 ASMCMD Commands

If the disk and file system containing the lost control file are INTACT, then copy one of the intact control files to the location of the missing control file.

Do not have to alter the CONTROL_FILES initialization parameter setting. STEPS: to replace a damaged control file by copying a multiplexed control file:

o 1. If the instance is still running, shut it down:

SQL> SHUTDOWN ABORT

o 2. Correct the hardware problem that caused the media failure. If you cannot repair the hardware problem quickly, then proceed with database recovery by restoring damaged control files to an alternative storage device, as described in "Copying a Multiplexed Control File to a Nondefault Location".

o 3. Use an intact multiplexed copy of the database's current control file to copy over the damaged control files.

Example: % cp /oracle/good_cf.f /oracle/dbs/bad_cf.f

o

o 4. Start a new instance and mount and open the database.

SQL> STARTUP

Copying a Multiplexed Control File to a Nondefault Location

Assuming that the disk and file system containing the lost control file are NOT INTACT, then CANNOT copy one of the good control files to the location of the missing control file.

Alter the CONTROL_FILES initialization parameter to indicate a new location for the missing control file.

STEPS: to restore a control file to a nondefault location:o 1. If the instance is still running, shut it down:

SQL> SHUTDOWN ABORT

o 2. Copy the intact control file to new locations.

Example:to copy a good version of control01.dbf to a new disk location:% cp $ORACLE_HOME/oradata/oldlocation/control01.dbf $ORACLE_HOME/oradata/newlocation/ control01.dbf

o 3. Edit the parameter file of the database so that the CONTROL_FILES parameter reflects the current locations of all control files and excludes all control files that were not restored.

Page 174: 11gR2 ASMCMD Commands

Example: 1. In the original initialization parameter file: CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/bad_disk/control02.dbf' 2. Change it to in initialization parameter file:CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/new_disk/control02.dbf'

o

o 4. Start a new instance and mount and open the database.

SQL> STARTUP

Restore Control File from Backup After Loss of All Current Control Files

Home >> Reference >> Backup and Recovery >> Control File Backup and Recovery >> Restore Control File from Backup After Loss of All Current Control Files

Status of Online Logs

Status of Datafiles

Restore Procedure

Available Current

If the online logs contain redo necessary for recovery, then restore a backup control file and apply the logs during recovery. You must specify the filename of the online logs containing the changes in order to open the database. After recovery, open RESETLOGS.

Unavailable Current

If the online logs contain redo necessary for recovery, then re-create the control file. Because the online redo logs are inaccessible, open RESETLOGS (when the online logs are accessible it is not necessary to OPEN RESETLOGS after recovery with a created control file).

Available BackupRestore a backup control file, perform complete recovery, and then open RESETLOGS.

Unavailable BackupRestore a backup control file, perform incomplete recovery, and then open RESETLOGS.

Restoring a Backup Control File to the Default Location

If possible, restore the control file to its original location. In this way, you avoid having to specify new control file locations in the initialization parameter file.

STEPS: to restore a backup control file to its default location:o 1. If the instance is still running, shut it down:

SQL> SHUTDOWN ABORT

o 2.Correct the hardware problem that caused the media failure.

Page 175: 11gR2 ASMCMD Commands

o 3.Restore the backup control file to all locations specified in the CONTROL_FILES parameter.

For example:if ORACLE_HOME/oradata/trgt/control01.dbf and ORACLE_HOME/oradata/trgt/control02.dbf are the control file locations listed in the server parameter file, then use an operating system utility to restore the backup control file to these locations:% cp /backup/control01.dbf ORACLE_HOME/oradata/trgt/control01.dbf% cp /backup/control02.dbf ORACLE_HOME/oradata/trgt/control02.dbf

o

o 4.Start a new instance and mount the database:

SQL> STARTUP MOUNT

o 5.Begin recovery by executing the RECOVER command with the USING BACKUP CONTROLFILE clause. Specify UNTIL CANCEL if you are performing incomplete recovery.

Example: SQL> RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL

o

o 6.Apply the prompted archived logs. 1) If you then receive another message saying that the required archived

log is missing, it probably means that a necessary redo record is located in the online redo logs. This situation can occur when unarchived changes were located in the online logs when the instance crashed.

For example: 1. assume that you see the following:ORA-00279: change 55636 generated at 11/08/2002 16:59:47 needed for thread 1ORA-00289: suggestion : /oracle/work/arc_dest/arcr_1_111.arcORA-00280: change 55636 for thread 1 is in sequence #111Specify log: {<RET>=suggested | filename | AUTO | CANCEL}2. You can specify the name of an online redo log and press Enter (you may have to try this a few times until you find the correct log):ORACLE_HOME/oradata/redo01.dbfLog applied.Media recovery complete.

2) If the online logs are inaccessible, then you can cancel recovery without applying them. If all datafiles are current, and if redo in the online logs is required for recovery, then you cannot open the database without applying the online logs. If the online logs are inaccessible, then you must re-create

Page 176: 11gR2 ASMCMD Commands

the control file, using the procedure described in "Create New Control File After Losing All Current and Backup Control Files".

o 7.Open the database with the RESETLOGS option after finishing recovery:

SQL> ALTER DATABASE OPEN RESETLOGS;

o

Copying a Multiplexed Control File to a Nondefault Location

Assuming that the disk and file system containing the lost control file are NOT INTACT, then CANNOT copy one of the good control files to the location of the missing control file.

Alter the CONTROL_FILES initialization parameter to indicate a new location for the missing control file.

STEPS: to restore a control file to a nondefault location:o 1.If the instance is still running, then shut it down:

SQL> SHUTDOWN ABORT

o 2. Copy the intact control file to new locations.

Example:to copy a good version of control01.dbf to a new disk location:% cp $ORACLE_HOME/oradata/oldlocation/control01.dbf $ORACLE_HOME/oradata/newlocation/ control01.dbf

o 3. Edit the parameter file of the database so that the CONTROL_FILES parameter reflects the current locations of all control files and excludes all control files that were not restored.

Example: 1. In the original initialization parameter file: CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/bad_disk/control02.dbf' 2. Change it to in initialization parameter file:CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/new_disk/control02.dbf'

o

o 4. Start a new instance and mount and open the database.

SQL> STARTUP

Restore Control File Using RMAN

Page 177: 11gR2 ASMCMD Commands

Home >> Reference >> Backup and Recovery >> Control File Backup and Recovery >> Restore Control File Using RMAN

See also here

Source: http://www.idevelopment.info/

The following examples use Oracle Database 10g and make use of a Recovery Catalog and the Flash Recovery Area (FRA).

1.   Restore controlfile from autobackup.

RMAN> restore controlfile from autobackup;

2.   Restore controlfile from a specific backup piece.

RMAN> restore controlfile from '/backup_dir/piece_name';

3.   Restore controlfile from most recent available controlfile backup.

RMAN> restore controlfile;

The following examples use Oracle Database 10g and do not require the use of a Recovery Catalog or a Flash Recovery Area (FRA). The big difference is the requirement to set the dbid of the database before executing restore with the instance in a nomount state.

4.   The following backup used all defaults. If not using a FRA, this backup should be in $ORACLE_HOME/dbs.

RMAN> set dbid=nnnnnnnnn;RMAN> restore controlfile from autobackup;

5.   Restore from autobackup looks at the most recent 7 days backups by default. If you want to restore an autobackup that's older then the default you can use the 'maxdays' parameter..

RMAN> set dbid=nnnnnnnnn;RMAN> restore controlfile from autobackup maxdays 20;

6.   Restore from autobackup increasing the number of autobackup sequences looked for restore in case your database generated many autobackups in a given day.

Page 178: 11gR2 ASMCMD Commands

RMAN> set dbid=nnnnnnnnn;RMAN> restore controlfile from autobackup maxseq 10;

7.   Restoring from autobackup when the backup location is not default.

RMAN> set dbid=nnnnnnnnn;RMAN> set controlfile autobackup format for device type disk to '/tmp/%F';RMAN> restore controlfile from autobackup;

8.   Restore the controlfile from this specific autobackup.

RMAN> set dbid=nnnnnnnnn;RMAN> restore controlfile from '/tmp/c-1140771490-20080502-03';

9.   Restore the controlfile from a specific autobackup file to a temporary disk location the replicate the temp controlfile to the respective locations and names given in control_files..

RMAN> set dbid=nnnnnnnnn;RMAN> restore controlfile from '/tmp/c-1140771490-2008050203' to '/tmp/control.tmp';RMAN> replicate controlfile from '/tmp/control.tmp'

Once you have the controlfile restored and mounted you have access to your previous backup configuration which will also be used during restore as well as the backup information required to restore and recover your database.After you mount the controlfiles from Oracle101g 10.2.x > you can use the RESTORE PREVIEW command to see what backups will be required to restore and recover and what checkpoint you must exceed to open the database resetlogs.

Recreate Control File

Options

How You Backed Up Control File How to Recreate Control File

Backed up to a trace file: ALTER DATABASE BACKUP CONTROLFILE TO TRACE NORESETLOGS after you made the last structural change to the database, and if you have saved the SQL command trace output

Use the CREATE CONTROLFILE statement from the trace output as-is.

Backed up to a trace file: ALTER DATABASE BACKUP CONTROLFILE TO TRACE before you made a structural

Edit the output of ALTER DATABASE BACKUP

Page 179: 11gR2 ASMCMD Commands

change to the databaseCONTROLFILE TO TRACE to reflect the change.

Backed up to a binary file: Backed up the control file with the ALTER DATABASE BACKUP CONTROLFILE TO filename statement

Use the control file copy to obtain SQL output. 1) Create a temporary database instance 2) mount the backup control file3) then run ALTER DATABASE BACKUP CONTROLFILE TO TRACE NORESETLOGS. 4) If the control file copy predated a recent structural change, then edit the trace to reflect the change.

Do not have a control file backup in either TO TRACE format or TO filename format

Execute the CREATE CONTROLFILE statement manually

STEPS

1. Start the database in NOMOUNT mode.

SQL> STARTUP NOMOUNT

2 Create the control file with the CREATE CONTROLFILE statement, specifying the

NORESETLOGS option (refer to the above for options).

Example: CREATE CONTROLFILE REUSE DATABASE SALES NORESETLOGS ARCHIVELOGMAXLOGFILES 32MAXLOGMEMBERS 2MAXDATAFILES 32MAXINSTANCES 16MAXLOGHISTORY 1600LOGFILEGROUP 1 ('/diska/prod/sales/db/log1t1.dbf','/diskb/prod/sales/db/log1t2.dbf') SIZE 100KGROUP 2 ('/diska/prod/sales/db/log2t1.dbf','/diskb/prod/sales/db/log2t2.dbf') SIZE 100K,

Page 180: 11gR2 ASMCMD Commands

DATAFILE'/diska/prod/sales/db/database1.dbf','/diskb/prod/sales/db/filea.dbf';

3. After creating the control file, the instance mounts the database.

SQL> ALTER DATABASE MOUNT;

4. Recover the database as normal (without specifying the USING BACKUP

CONTROLFILE clause):

SQL> RECOVER DATABASE

5. Open the database after recovery completes (RESETLOGS option not required):

SQL> ALTER DATABASE OPEN;

6. Immediately back up the control file.

Example: SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/backup/control01.dbf' REUSE;

Fast Incremental Backup

Overview

Optimizes incremental backups– Tracks which blocks have changed since the lastbackup

Oracle Database 10g has integrated change tracking:– A change tracking file is introduced.– Changed blocks are tracked as redo is generated.– Database backup automatically uses the changedblock list.

The size of the block change tracking file is proportional to:- Database size in bytes- Number of enabled threads in a RAC environment- Number of old backups maintained by the block change tracking file -The minimum size for the block change tracking file is 10 MB, and any new space is allocated in 10 MB increments.

The background process that performs the writes to the change tracking file is called thechange tracking writer (CTWR). 

Page 181: 11gR2 ASMCMD Commands

Configuration

Enable block change tracking

SQL> alter database enable block change tracking; The block change-tracking file was automatically named and placed in the directory specified by the DB_CREATE_FILE_DEST initialization parameter

SQL> alter database enable block change tracking using file '/u04/oradata/ord/changetracking/chg01.dbf';Oracle recommends placing the block change-tracking file on the same disk asthe database files; this is automatic if you are using OMF.

Disable block change tracking

SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

Monitor block change tracking

The dynamic performance view V$BLOCK_CHANGE_TRACKING shows where the block changetracking file is stored, whether it is enabled, and how large it is:SQL> select * from v$block_change_tracking;

Monitor how effective the block change tracking is in minimizing the incremental backup I/O (the PCT_READ_FOR_BACKUP column)SQL> SELECT file#, avg(datafile_blocks), avg(blocks_read), avg(blocks_read/datafile_blocks) * 100 AS PCT_READ_FOR_BACKUP, avg(blocks) FROM v$backup_datafile WHERE used_change_tracking = 'YES'  AND incremental_level > 0 GROUP BY file#;

Fast Recovery Using Switch Database

Overview

Page 182: 11gR2 ASMCMD Commands

The new RMAN command SWITCH DATABASE is the fastest way to recover a database using backup copies of the database: No files are copied, and no files need to be renamed. It takes one command.

RMAN> switch database to copy;

The downside to this method is that your datafiles are now in the flash recovery area. This may cause problems when you create backups: Now your datafiles and backups are in the same location. At your earliest opportunity, you should migrate the datafiles out of the flash recovery area and create new backups.

Differences Between Restore and Switch

RESTORE DATABASE: The restore process copies the backup data files from their backup location to the location specified in the control file, and the recovery process begins.

SWITCH DATABASE: The switch process does not copy any backup data files. Instead, RMAN adjusts the control file so that the data files point to the backup file location, and the recovery process begins.

Automatic Storage Management

What is ASM

Automatic Storage Management (ASM) is an integrated, high-performance database file system and disk manager. ASM eliminates the need for you to directly manage potentially thousands of Oracle database files.

ASM Installation and Configuration

ASM Installation 'oraenv Does Not Set oracle_home For +asm Instance': Metalink Note:338441.1 Initialization Parameters for ASM Instances   

ASM New Features

10g Release 2 New Features    11g Release 1 New Features    11g Release 2 New Features

ASM Administration

Page 183: 11gR2 ASMCMD Commands

ASM Instance    Disk groups and disks    Files    ASM Dynamic Views    ASM Metadata and Internals    ASM File Handling    Migrating Databases from non-ASM to ASM    Migrating Databases from ASM to non-ASM    ASMLIB    ASM Scripts    Gather ASM Metadata   

ASM Commands

ASM and SRVCTL    ASMCMD    asm.sh   

Why Use ASM

Striping—ASM spreads data evenly across all disks in a disk group to optimize performance and utilization. This even distribution of database files eliminates the need for regular monitoring and I/O performance tuning.

 Mirroring—ASM can increase availability by optionally mirroring any file. ASM mirrors at the file level, unlike operating system mirroring, which mirrors at the disk level. Mirroring means keeping redundant copies, or mirrored copies, of each extent of the file, to help avoid data loss caused by disk failures. The mirrored copy of each file extent is always kept on a different disk from the original copy. If a disk fails, ASM can continue to access affected files by accessing mirrored copies on the surviving disks in the disk group. ASM supports 2-way mirroring, where each file extent gets one mirrored copy, and 3-way mirroring, where each file extent gets two mirrored copies.

 Online storage reconfiguration and dynamic rebalancing—ASM permits you to add or remove disks from your disk storage system while the database is operating. When you add a disk, ASM automatically redistributes the data so that it is evenly spread across all disks in the disk group, including the new disk. This redistribution is known as rebalancing. It is done in the background and with minimal impact to database performance. When you request to remove a disk, ASM first rebalances by evenly relocating all file extents from the disk being removed to the other disks in the disk group.

Managed file creation and deletion—ASM further reduces administration tasks by enabling files stored in ASM disk groups to be Oracle-managed files. ASM automatically assigns filenames when files are created, and automatically deletes files when they are no longer needed.

Key Benefits of ASM

I/O is spread evenly across all available disk drives to prevent hot spots and maximize performance.

Page 184: 11gR2 ASMCMD Commands

ASM eliminates the need for over provisioning and maximizes storage resource utilization facilitating database consolidation.

Inherent large file support. Performs automatic online redistribution after the incremental addition or removal of storage capacity.

Maintains redundant copies of data to provide high availability, or leverage 3rd party RAID functionality.

Supports Oracle Database 10g as well as Oracle Real Application Clusters (RAC). Capable of leveraging 3rd party multipathing technologies. For simplicity and easier migration to ASM, an Oracle Database 10g Release 2 database can contain ASM and non-ASM files. Any new files can be created as ASM files whilst existing files can also be migrated to ASM.

RMAN commands enable non-ASM managed files to be relocated to an ASM disk group. Oracle Database 10g Enterprise Manager can be used to manage ASM disk and file management activities.

ASM reduces Oracle Database 10g cost and complexity without compromising performance or availability.

Note

ASM does not manage binaries, alert logs, trace files, or password files.

11g Release 1 New Features

Scalability and Performance

Fast Mirror Resynchronization for ASM redundancy disks groups Preferred Read for ASM redundancy disks groups Support for large allocation units Optimized rebalance operations

Rolling upgrade and patching support

New security features

Separate connect privilege, SYSASM, different from SYSDBA

ASM Instance Introduction

ASM doesn't have to be installed in order to install an Oracle database. To use ASM files, there must be at least one ASM instance configured and started prior to starting a database instance that uses ASM files. As part of the ASM instance startup procedure, the various disk groups and their files are identified. The ASM instance mounts the disks, and then creates an extent map,

Page 185: 11gR2 ASMCMD Commands

which is passed to the database instance. The database instance itself is responsible for any actual input/output operations.

The ASM instance is only involved during the creation or deletion of files and when disk configurations change (such as dropping or adding a disk). When these types of changes occur, the ASM instance automatically rebalances the disks and provides the necessary information to refresh the extent map in the SGA of the database instance. Of course, this process requires that the ASM instance run concurrently with the database instance, and only shut down after the database instance is closed.

The impact of the ASM instance on performance of the database instance is minimal. The former does not process transactions affecting the individual database objects; therefore, the average SGA allocation needed by the instance is no more than 64MB. Unless the server's memory is already at the maximum recommended operating system/DBMS allocation, 64MB should have no impact on the memory available for the database instance.

New Background Processes of ASM Instance

RBAL: coordinating rebalance activity for disk groups  ARBn: performing database the data extent movements  GMON: monitoring operations that maintain ASM metadata inside disk groups

New Background Processes of Database Instance That Uses ASM

RBAL: performing global opens of the disks in the disk groups  ASMB: connecting to foreground processes in ASM instances

ASM Instance Initialization Parameters

INSTANCE_TYPE: Must be set to ASM. This is the only required parameter.  ASM_POWER_LIMIT: The default power for disk rebalancing. Controls the speed for a rebalance operation. Default: 1, Range: 0 – 11. 

ASM_DISKSTRING: A comma-separated list of strings that limits the set of disks that ASM discovers. May include wildcard characters. Only disks that match one of the strings are discovered. Default: NULL. A NULL value causes ASM to search a default path for all disks in the system to which the ASM instance has read/write access. 

ASM_DISKGROUPS: A list of the names of disk groups to be mounted by an ASM instance at startup, or when the ALTER DISKGROUP ALL MOUNT statement is used. Default: NULL (If this parameter is not specified, then no disk groups are mounted.)

The difference between ASM Instance and Regular Instance

Page 186: 11gR2 ASMCMD Commands

While it does have an initialization parameter file and a password file, it has no data dictionary, and therefore all connections to an ASM instance are via SYS and SYSTEM using operating system authentication only. 

Disk group commands such as CREATE DISKGROUP, ALTER DISKGROUP, and DROP DISKGROUP are validonly from an ASM instance.

An ASM instance doen't mount database, but it mounts disk groups, since it does not have a control file.

Starting up an ASM Instance

Startup Parameters:

FORCE: Issues a SHUTDOWN ABORT to the ASM instance before restarting it  MOUNT, OPEN: Mounts the disk groups specified in the ASM_DISKGROUPS initialization parameter. This is the default if no command parameter is specified. 

NOMOUNT: Starts up the ASM instance without mounting any disk groups 

Note:

Set the ORACLE_SID environment variable to the ASM SID. Default ASM SID for a single instance database is +ASMDefault SID for ASM on Real Application Clusters is +ASMnode# 

The initialization parameter file, which can be a server parameter file, must contain:   INSTANCE_TYPE = ASM

The STARTUP command tries to mount the disk groups specified by the initialization parameter ASM_DISKGROUPS. If ASM_DISKGROUPS is blank, the ASM instance starts and warns that no disk groups were mounted. You can then mount disk groups with the ALTER DISKGROUP...MOUNT command.

Example:% sqlplus /nologSQL> CONNECT / AS sysdbaConnected to an idle instance. SQL> startupASM instance startedTotal System Global Area  130023424 bytesFixed Size                  1976920 bytesVariable Size             102880680 bytesASM Cache                  25165824 bytesASM diskgroups mounted

Page 187: 11gR2 ASMCMD Commands

Shutting Down an ASM Instance

Shutdown Mode: 

NORMAL, IMMEDIATE, or TRANSACTIONAL: ASM waits for any in-progress SQL to complete before doing an orderly dismount of all disk groups and shutting down the ASM instance. If any database instances are connected to the ASM instance, the SHUTDOWN command returns an error and leaves the ASM instance running. 

ABORT: The ASM instance immediately shuts down without the orderly dismount of disk groups. This causes recovery upon the next startup of ASM. If any database instance is connected to the ASM instance, the database instance aborts. 

Example:% sqlplus /nologSQL> CONNECT / AS sysdbaConnected to an idle instance.SQL> shutdown normalASM diskgroups dismountedASM instance shutdown

Overview of Disk Group

A disk group is a collection of disks managed as a logical unit. Storage is added and removed from disk groups in units of ASM disks.

Every ASM disk has an ASM disk name, which is a name common to all nodes in a cluster.

Files in a disk group are striped on the disks using either coarse striping or fine striping.o Coarse striping spreads files in units of 1MB each across all disks. Coarse

striping is appropriate for a system with a high degree of concurrent small I/O requests, such as an OLTP environment.

o Fine striping spreads files in units of 128KB and is appropriate for traditional data warehouse environments or OLTP systems with low concurrency and maximizes response time for individual I/O requests. For files (such as log files) that require low latency, ASM provides fine-grained (128 KB) striping

Failure Groups and Disk Group Mirroring

A failure group is one or more disks within a disk group that share a common resource, such as a disk controller, whose failure would cause the entire set of disks to be unavailable to the group.

Disk Group Mirroringo Mirror at extent level

Page 188: 11gR2 ASMCMD Commands

o Mix primary and mirror extents on each disko External redundancy: Defers to hardware mirroringo Normal redundancy:

– Two-way mirroring– At least two failure groups

o High redundancy:– Three-way mirroring– At least three failure groups 

Disk Group Dynamic Rebalancing

Automatic online rebalance whenever storage configuration changes Only moves data proportional to storage added No need for manual I/O tuning Online migration to new storage Any impact to ongoing database I/O can be controlled by adjusting the value of the

initialization parameter ASM_POWER_LIMIT to a lower value.

Creating A Disk Group

Syntax:

CREATE DISKGROUP diskgroup_name[ { HIGH | NORMAL | EXTERNAL } REDUNDANCY ] [ FAILGROUP failgroup_name ]DISK qualified_disk_clause[, qualified_disk_clause ]...[ [ FAILGROUP failgroup_name ]DISK qualified_disk_clause[, qualified_disk_clause ]...]... ;

Example:

SQL> CREATE DISKGROUP dgroup1 NORMAL REDUNDANCY2 FAILGROUP controller1 DISK3 '/devices/disk1',4 '/devices/disk2',5 '/devices/disk3',6 '/devices/disk4'7 FAILGROUP controller2 DISK8 '/devices/disk5',9 '/devices/disk6',10 '/devices/disk7',11 '/devices/disk8';

Page 189: 11gR2 ASMCMD Commands

Deleting A Disk Group

Syntax:

DROP DISKGROUP diskgroup_name

[ { INCLUDING | EXCLUDING }

CONTENTS

] ;

Example:

DROP DISKGROUP dgroup1 including contents;

Altering A Disk Group

ALTER DISKGROUP ... ADD FAILGROUP ... DISK This adds a disk to a failure group and performs an automatic rebalance

ALTER DISKGROUP ... REBALANCE POWER This changes the power limit for this particular rebalance operation

ALTER DISKGROUP ... DROP DISK This removes a disk from a failure group within a disk group and performs an automatic rebalance.

ALTER DISKGROUP ... UNDROP DISKS This cancels the drop of the disk that was dropped. The UNDROP command operates only on pending drops of disks, not after drop completion.

ALTER DISKGROUP ... DROP ... ADD This drops a disk from a failure group and adds another disk in the same command.

ALTER DISKGROUP ... MOUNT This makes a disk group available to all instances. ALTER DISKGROUP ... DISMOUNT This makes a disk group unavailable to all

instances. ALTER DISKGROUP ... CHECK ALL This verifies the internal consistency of the disk

group.

Migrating Databases from non-ASM to ASM

Migrating Databases from non-ASM to ASMHome >> Reference >> Automatic Storage Management >> Migrating Databases from non-ASM to ASM

Because ASM files cannot be accessed via the operating system, you must use the Recovery Manager (RMAN) to move database objects from a non-ASM disk location to an ASM disk group.

Page 190: 11gR2 ASMCMD Commands

Follow these steps to move these objects:

1. Note the filenames of the control files and the online redo log files. 2. Shut down the database NORMAL, IMMEDIATE, or TRANSACTIONAL. 3. Back up the database. 4. Edit the SPFILE to use OMF for all file destinations. 5. Edit the SPFILE to remove the CONTROL_FILES parameter. 6. Run the following RMAN script, substituting your specific filenames as needed:

STARTUP NOMOUNT;RESTORE CONTROLFILE FROM '/u1/c1.ctl';ALTER DATABASE MOUNT;BACKUP AS COPY DATABASE FORMAT '+dgroup1';SWITCH DATABASE TO COPY;# Repeat command for all online redo log members ...SQL "ALTER DATABASE RENAME '/u1/log1' TO '+dgroup1' ";ALTER DATABASE OPEN RESETLOGS;# Repeat command for all temporary tablespacesSQL "ALTER TABLESPACE temp ADD TEMPFILE";SQL "ALTER DATABASE TEMPFILE '/u1/temp1' DROP";

7. Delete or archive the old database files.

Refer detailed steps to

http://www.idevelopment.info/data/Oracle/DBA_tips/Automatic_Storage_Management/

ASM_33.shtml

ASMLIB

Page 191: 11gR2 ASMCMD Commands

Linux OS Service 'oracleasm'

Service Name

oracleasm

Description

The oracleasm service is used to provision, configure and manage Oracle Automatic Storage Management (ASM) disks via the Oracle Automatic Storage Management library driver (ASMLib). The oracleasm services creates the necessary library interface through which ASM disk devices are made available to Oracle ASM (instance).

Nature

System service

Configuration File

/etc/sysconfig/oracleasm

Oracle Enterprise Linux Version(s)

OEL 4 OEL 5

Requirement

Optional - needed only if operating system-level management and configuration of Oracle ASM disk devices is required. Not needed if Oracle ASM (instance-only) management of ASM group/disk devices is required/preferred.

oracleasm/etc/init.d/oracleasm

$ oracleasm -hUsage: oracleasm [--exec-path=<exec_path>] <command> [ <args> ]       oracleasm --exec-path       oracleasm -h       oracleasm -V

The basic oracleasm commands are:    configure        Configure the Oracle Linux ASMLib driver    init             Load and initialize the ASMLib driver    exit             Stop the ASMLib driver

Page 192: 11gR2 ASMCMD Commands

    scandisks        Scan the system for Oracle ASMLib disks    status           Display the status of the Oracle ASMLib driver    listdisks        List known Oracle ASMLib disks    querydisk        Determine if a disk belongs to Oracle ASMlib    createdisk       Allocate a device for Oracle ASMLib use    deletedisk       Return a device to the operating system    renamedisk       Change the label of an Oracle ASMlib disk    update-driver    Download the latest ASMLib driver

Option Description

configure Use the configure option to reconfigure the Automatic Storage Management library driver, if necessary:

# /etc/init.d/oracleasm configure

enabledisable

Use the disable and enable options to change the actions of the Automatic Storage Management library driver when the system starts. The enable option causes the Automatic Storage Management library driver to load when the system starts:

# /etc/init.d/oracleasm enable

startstoprestart

Use the start, stop, and restart options to load or unload the Automatic Storage Management library driver without restarting the system:

# /etc/init.d/oracleasm restart

createdisk Use the createdisk option to mark a disk device for use with the Automatic Storage Management library driver and give it a name:

# /etc/init.d/oracleasm createdisk DISKNAME devicename

deletedisk Use the deletedisk option to unmark a named disk device:

# /etc/init.d/oracleasm deletedisk DISKNAME

Caution: Do not use this command to unmark disks that are being used by an Automatic Storage Management disk group. You must delete the disk from the Automatic Storage Management disk group before you unmark it.

querydisk Use the querydisk option to determine if a disk device or disk name is being used by the Automatic Storage Management library driver:

# /etc/init.d/oracleasm querydisk {DISKNAME | devicename}

listdisks Use the listdisks option to list the disk names of marked Automatic Storage

Page 193: 11gR2 ASMCMD Commands

Option Description

Management library driver disks:

# /etc/init.d/oracleasm listdisks

scandisks Use the scandisks option to enable cluster nodes to identify which shared disks have been marked as Automatic Storage Management library driver disks on another node:

# /etc/init.d/oracleasm scandisks

Q&A

Is /dev/oracleasm created?

When ASMLIB is configured, a special filesystem is created and mounted: /dev/oracleasm.  

$ df -haFilesystem            Size  Used Avail Use% Mounted on/dev/hdc2              13G   11G  1.9G  85% /none                     0     0     0   -  /procnone                     0     0     0   -  /dev/ptsusbdevfs                 0     0     0   -  /proc/bus/usb/dev/hdc1             101M   14M   81M  15% /bootnone                  250M     0  250M   0% /dev/shm/dev/sda1             8.4G  4.8G  3.2G  60% /oradata2/dev/sde1             8.3G  6.6G  1.4G  84% /oradata3oracleasmfs              0     0     0   -  /dev/oracleasm

When command oracleasm createdisk is executed, a block device is created under /dev/oracleasm/disks.   This is the device discovered by ASMLIB using the string ORCL:*.

$ ll /dev/oracleasm/diskstotal 0brw-rw----  1 oracle dba 8,  97 Apr 28 15:20 VOL001brw-rw----  1 oracle dba 8,  81 Apr 28 15:20 VOL002brw-rw----  1 oracle dba 8,  65 Apr 28 15:20 VOL003brw-rw----  1 oracle dba 8,  49 Apr 28 15:20 VOL004brw-rw----  1 oracle dba 8,  33 Apr 28 15:20 VOL005brw-rw----  1 oracle dba 8,  17 Apr 28 15:20 VOL006brw-rw----  1 oracle dba 8, 129 Apr 28 15:20 VOL007brw-rw----  1 oracle dba 8, 113 Apr 28 15:20 VOL008

Page 194: 11gR2 ASMCMD Commands

Checking if ASMLIB was installed properly:

[root@arlnx2 asm_tar]# /etc/init.d/oracleasm statusChecking if ASM is loaded:                                  [  OK  ]Checking if /dev/oracleasm is mounted:                [  OK  ]

If the command fails, use strace and generate a log file:

strace -f -o asm_status.out /etc/init.d/oracleasm status

Additional information to verify the installation can be found in note 269194.1

Listing the ASMLIB disks:

$ /etc/init.d/oracleasm listdisksVOL001VOL002VOL003VOL004VOL005VOL006VOL007VOL008

$ ll /dev/oracleasm/diskstotal 0brw-rw----  1 oracle dba 8,  97 Apr 28 15:20 VOL001brw-rw----  1 oracle dba 8,  81 Apr 28 15:20 VOL002brw-rw----  1 oracle dba 8,  65 Apr 28 15:20 VOL003brw-rw----  1 oracle dba 8,  49 Apr 28 15:20 VOL004brw-rw----  1 oracle dba 8,  33 Apr 28 15:20 VOL005brw-rw----  1 oracle dba 8,  17 Apr 28 15:20 VOL006brw-rw----  1 oracle dba 8, 129 Apr 28 15:20 VOL007brw-rw----  1 oracle dba 8, 113 Apr 28 15:20 VOL008

You will find an entry under /dev/oracleasm/disks.   This is the block device associated to the physical device. If the file exist the command will return information, but if not, plese execute:

strace -f -o asm_listd.out /etc/init.d/oracleasm listdisks

Page 195: 11gR2 ASMCMD Commands

How to identify the physical disk bound to the ASMLIB disk.

  Use  /etc/init.d/oracleasm querydisk <NAME>  where NAME is any name under /dev/oracleasm/disks.

[root@arlnx2 asm_tar]# /etc/init.d/oracleasm querydisk -d VOL1

Disk "VOL1" is a valid ASM disk on device [8, 33]

The command reports the device identified with major,minor numbers which are unique numbers associated to each disk.  File /proc/partitions can be used to find the name of the device associated with those numbers:

$ more /proc/partitions

major minor  #blocks  name     rio rmerge rsect ruse wio wmerge wsect wuse running use aveq

   8     0    8891620 sda 39715 78016 941080 417000 156198 242472 3189752 214180 0 420630 631180   8     1    8891376 sda1 39691 77970 940922 416780 156198 242472 3189752 214180 0 420410 630960   8    16    8891620 sdb 87 250 803 740 0 0 0 0 0 740 740   8    17    8891376 sdb1 57 193 632 480 0 0 0 0 0 480 480   8    32   17783250 sdc 745 2993 8321 8300 0 0 0 0 0 5250 8300   8    33     977904 sdc1 87 139 644 1040 0 0 0 0 0 1040 1040    8    34     977920 sdc2 35 193 456 230 0 0 0 0 0 230 230   8    35          1 sdc3 4 0 8 40 0 0 0 0 0 40 40   8    37     977904 sdc5 57 193 632 1240 0 0 0 0 0 1240 1240   8    38     977904 sdc6 57 193 632 1170 0 0 0 0 0 1170 1170

Also connected as root you can run the same command but referencing the physical device:

[root@arlnx2 dbs]# /etc/init.d/oracleasm querydisk /dev/sdc1Disk "/dev/sdc1" is marked an ASM disk with the label "VOL1"

Page 196: 11gR2 ASMCMD Commands

Any error on this command will require using strace:

strace -f -o asm_query.out /etc/init.d/oracleasm querydisk <NAME>

How to identify if ASMLIB is used or not

SQL> select path ,library from v$asm_disk;PATH                 LIBRARY-------------------- ------------------------------------------------------------ORCL:VOL001          ASM Library - Generic Linux, version 2.0.2 (KABI_V2)ORCL:VOL002          ASM Library - Generic Linux, version 2.0.2 (KABI_V2)ORCL:VOL003          ASM Library - Generic Linux, version 2.0.2 (KABI_V2)ORCL:VOL004          ASM Library - Generic Linux, version 2.0.2 (KABI_V2)

PATH                                               LIBRARY-------------------------------------------------- ------------------------------------------------------------/dev/oracleasm/disks/ASM7                          System/dev/oracleasm/disks/ASM2                          System/dev/oracleasm/disks/ASM1                          System/dev/oracleasm/disks/ASM5                          System/dev/oracleasm/disks/ASM6                          System/dev/oracleasm/disks/ASM4                          System/dev/oracleasm/disks/ASM3                          System

Troubleshooting ASM/ASMLIB issues

1) In order to check if the ASMLIB API is correctly configured, please execute the next commands and provide us the output (from each node if this is RAC):

$> cat /etc/*release $> uname -a $> rpm -qa |grep oracleasm $> df -ha

2) Check the discovery path (from each node if this is RAC):

Page 197: 11gR2 ASMCMD Commands

$> /etc/init.d/oracleasm status $> /usr/sbin/oracleasm-discover $> /usr/sbin/oracleasm-discover 'ORCL:*'

3) Please check if the ASMLIB devices can be accessed (from each node if this is RAC):

$> /etc/init.d/oracleasm scandisks $> /etc/init.d/oracleasm listdisks $> /etc/init.d/oracleasm querydisk <each disk from previous output> $> ls -l /dev/oracleasm/disks

4) Upload the next files from each node if this is RAC:

=)> /var/log/messages* =)> /var/log/oracleasm=)> /etc/sysconfig/oracleasm

5) Please show us the partition table (from each node if this is RAC):

$> cat /proc/partitions

6) If you are using multipath devices (mapper devices or emcpower) then show me the output of:

$> ls -l /dev/mpath/*

$> ls -l /dev/mapper/*

$> ls -l /dev/dm-* 

$> ls -l /dev/emcpower*

Or if you have another multipath configuration then list the devices:

$> ls -l /dev/<multi path device name>*

7) Finally connect to your ASM instance, execute the next script and upload me the output file (from each node if this is RAC):

spool asm<#>.htmlSET MARKUP HTML ON set echo on

set pagesize 200

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';

Page 198: 11gR2 ASMCMD Commands

select 'THIS ASM REPORT WAS GENERATED AT: ==)> ' , sysdate " " from dual;

select 'HOSTNAME ASSOCIATED WITH THIS ASM INSTANCE: ==)> ' , MACHINE " " from v$session where program like '%SMON%';

select * from v$asm_diskgroup;

SELECT * FROM V$ASM_DISK ORDER BY GROUP_NUMBER,DISK_NUMBER;

SELECT * FROM V$ASM_CLIENT;

select * from V$ASM_ATTRIBUTE;

select * from v$asm_operation;select * from gv$asm_operation

select * from v$version;

show parameter asmshow parameter clustershow parameter instance_typeshow parameter instance_nameshow parameter spfile

show sga

spool off

exit

Gather ASM Metadata

Connect to your ASM instance(s) and execute the next scripts (on each node if this is RAC):

SPOOL ASM_FIRST<instance#>.HTML SET MARKUP HTML ON set echo on

set pagesize 200

Page 199: 11gR2 ASMCMD Commands

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';

select 'THIS ASM REPORT WAS GENERATED AT: ==)> ' , sysdate " " from dual;select 'HOSTNAME ASSOCIATED WITH THIS ASM INSTANCE: ==)> ' , MACHINE " " from v$session where program like '%SMON%';select * from v$asm_diskgroup;SELECT * FROM V$ASM_DISK ORDER BY GROUP_NUMBER,DISK_NUMBER; SELECT * FROM V$ASM_CLIENT; select * from V$ASM_ATTRIBUTE;select * from v$asm_operation;select * from gv$asm_operationselect * from v$version;

show parameter asmshow parameter clustershow parameter instance_typeshow parameter instance_nameshow parameter spfile

show sga

spool off

exit

SPOOL ASM_SECOND<instance#>.HTML  SET MARKUP HTML ON  SET ECHO ON

SET PAGESIZE 200

SELECT * FROM  V$ASM_CLIENT;  SELECT * FROM  V$ASM_DISK_STAT ORDER BY GROUP_NUMBER,DISK_NUMBER;  SELECT * FROM  V$ASM_DISKGROUP_STAT ORDER BY GROUP_NUMBER;  SELECT * FROM  V$ASM_FILE ORDER BY GROUP_NUMBER,FILE_NUMBER;  SELECT * FROM  V$ASM_ALIAS ORDER BY GROUP_NUMBER,FILE_NUMBER;  SELECT * FROM  V$ASM_TEMPLATE ORDER BY GROUP_NUMBER,ENTRY_NUMBER; 

select * from v$version;

show parameter asmshow parameter clustershow parameter instance_typeshow parameter instance_nameshow parameter spfile

Page 200: 11gR2 ASMCMD Commands

SPOOL OFF

EXIT

ASM and SRVCTL

Start an ASM instance:

Syntax:    srvctl start asm -n node_name [-i asm_instance_name] [-o start_options] [-c <connect_str> | -q]

Example: start an ASM instance on the specified node$srvctl start asm -n linuxnode1

Stop an ASM instance:

Syntax:    srvctl stop asm -n node_name [-i asm_instance_name] [-o stop_options] [-c <connect_str> | -q]

Example: stop an ASM instance on the specified node$srvctl stop asm -n linuxnode1 immediate

Add configuration information (OCR data) about an existing ASM instance:

Syntax:    srvctl add asm -n node_name -i asm_instance_name -o oracle_home

Example:$srvctl add asm -n linuxnode1 -i +ASM1 -o $ORACLE_HOME

Remove an ASM instance:

Syntax:srvctl remove asm -n node_name [-i asm_instance_name]

Page 201: 11gR2 ASMCMD Commands

Enable an ASM instance:

Syntax:    srvctl enable asm -n node_name [-i ] asm_instance_name

Disable an ASM instance:

Syntax:    srvctl disable asm -n node_name [-i asm_instance_name]

Example:$srvctl disable asm -n linuxnod1 -i +ASM1

Show the configuration of an ASM instance:

Syntax:    srvctl config asm -n node_name

Obtain the status of an ASM instance:

Syntax:    srvctl status asm -n node_name

  ASM Command-Line Utility (ASMCMD)ASMCMD is a command-line utility that you can use to easily view andmanipulate files and directories within Automatic Storage Management(ASM) disk groups. It can list the contents of disk groups, performsearches, create and remove directories and aliases, display spaceutilization, and more.ASMCMD works with Automatic Storage Management (ASM) files,directories, and aliases. Before using ASMCMD, you must understandhow these common computing concepts apply to the unique ASMenvironment. The following are some key definitions.System-generated filename or 'fully qualified filename'Every file created in ASM gets a system-generated filename, otherwiseknown as a fully qualified filename. This is analogous to a completepath name in a local file system. An example of a fully qualifiedfilename is the following:+dgroup2/sample/controlfile/Current.256.541956473ASM generates filenames according to the following scheme:+diskGroupName/databaseName/fileType/fileTypeTag.file.incarnation In the previous fully qualified filename,dgroup2is the disk groupname,sampleis the database name,controlfileis the file type,and so on.

Page 202: 11gR2 ASMCMD Commands

  DirectoryAs in other file systems, an ASM directory is a container for files, and itcan be part of a tree structure of other directories. The fully qualified filename in fact represents a hierarchy of directories,with the plus sign (+) as the root. In each disk group, ASM creates adirectory hierarchy that corresponds to the structure of the fullyqualified filenames in the disk group. The directories in this hierarchyare known as system-generated directories. ASMCMD enables you tomove up and down this directory hierarchy with thecd(changedirectory) command. The ASMCMDls(list directory) command liststhe contents of the current directory, while thepwdcommand printsthe name of the current directory.When you start ASMCMD, the current directory is set to root (+). For anASM instance with two disk groups,dgroup1anddgroup2, enteringanlscommand with the root directory as the current directoryproduces the following output:ASMCMD> lsDGROUP1/DGROUP2/ The following example demonstrates navigating the ASM directory tree(refer to the fully qualified filename shown previously):ASMCMD> cd +dgroup1/sample/controlfileASMCMD> lsCurrent.256.541956473Current.257.541956475 You can also create your own directories as subdirectories of thesystem-generated directories. You do so with theALTER DISKGROUPcommand or with the ASMCMDmkdircommand. Your user-createddirectories can have subdirectories, and you can navigate thehierarchy of both system-generated directories and user-generateddirectories with thecdcommand   The following example creates the directorymydirin the disk groupdgroup1:ASMCMD> mkdir +dgroup1/mydir(Note that the directorydgroup1is a system-generated directory. Itscontents represent the contents of the disk groupdgroup1.)If you start ASMCMD with the-pflag, ASMCMD always shows thecurrent directory as part of its prompt.ASMCMD [+] > cd dgroup1/mydirASMCMD [+DGROUP1/MYDIR] >AliasAn alias is a filename that is a reference (or pointer) to a system-generated filename, but with a more user-friendly name. It is similar toa symbolic link in Unix operating systems. You create aliases to makeit easier to work with ASM filenames. You can create an alias with an

Page 203: 11gR2 ASMCMD Commands

ALTER DISKGROUPcommand or with themkaliasASMCMDcommand.An alias has at a minimum the disk group name as part of its completepath. You can create aliases at the disk group level or in any system-generated or user-created subdirectory. The following are examples of aliases:+dgroup1/ctl1.f+dgroup1/sample/ctl1.f+dgroup1/mydir/ctl1.fIf you run the ASMCMDls(list directory) with the-lflag, each alias islisted with the system-generated file that it references.ctl1.f =>+dgroup2/sample/controlfile/Current.256.541956473Absolute path and Relative path

################################################################# Adding/Removing/Managing the configuration of ASM instances################################################################

--Use the following syntax to add configuration information about an existing ASM instance:srvctl add asm -n node_name -i +asm_instance_name -o oracle_home

--Use the following syntax to remove an ASM instance:srvctl remove asm -n node_name [-i +asm_instance_name]

--Use the following syntax to enable an ASM instance:srvctl enable asm -n node_name [-i ] +asm_instance_name

--Use the following syntax to disable an ASM instance:srvctl disable asm -n node_name [-i +asm_instance_name]

--Use the following syntax to start an ASM instance:srvctl start asm -n node_name [-i +asm_instance_name] [-o start_options]

--Use the following syntax to stop an ASM instance:srvctl stop asm -n node_name [-i +asm_instance_name] [-o stop_options]

--Use the following syntax to show the configuration of an ASM instance:srvctl config asm -n node_name

--Use the following syntax to obtain the status of an ASM instance:srvctl status asm -n node_name

--P.S.:--For all of the SRVCTL commands in this section for which the--option is not required, if you do not specify an instance name, then -i

Page 204: 11gR2 ASMCMD Commands

--the command applies to all of the ASM instances on the node.

#################################### Managing DiskGroup inside ASM:###################################

--Note that adding or dropping disks will initiate a rebalance of the data on the disks. --The status of these processes can be shown by selecting from v$asm_operation.

--Quering ASM Disk Groupscol name format a25col DATABASE_COMPATIBILITY format a10col COMPATIBILITY format a10select * from v$asm_diskgroup;--orselect name, state, type, total_mb, free_mb from v$asm_diskgroup;

--Quering ASM Diskscol PATH format a55col name format a25select name, path, group_number, TOTAL_MB, FREE_MB, READS, WRITES, READ_TIME,WRITE_TIME from v$asm_disk order by 3,1;--orcol PATH format a50col HEADER_STATUS  format a12col name format a25--select INCARNATION,select name, path, MOUNT_STATUS,HEADER_STATUS, MODE_STATUS, STATE, group_number,OS_MB, TOTAL_MB, FREE_MB, READS, WRITES, READ_TIME, WRITE_TIME, BYTES_READ,BYTES_WRITTEN, REPAIR_TIMER, MOUNT_DATE, CREATE_DATE from v$asm_disk;

####################################TUNING and Analysis###################################--Only Performance Statistics--N.B Time in Hundred seconds!col READ_TIME format 9999999999.99col WRITE_TIME format 9999999999.99col BYTES_READ format 99999999999999.99col BYTES_WRITTEN  format 99999999999999.99select name, STATE, group_number, TOTAL_MB, FREE_MB,READS, WRITES, READ_TIME, WRITE_TIME, BYTES_READ, BYTES_WRITTEN, REPAIR_TIMER,MOUNT_DATE

Page 205: 11gR2 ASMCMD Commands

from v$asm_disk order by group_number, name;

--Check the Num of Extents in use per Disk inside one Disk Group.select max(substr(name,1,30)) group_name, count(PXN_KFFXP) extents_per_disk,DISK_KFFXP, GROUP_KFFXP from x$kffxp, v$ASM_DISKGROUP grwhere GROUP_KFFXP=&group_nr and GROUP_KFFXP=GROUP_NUMBERgroup by GROUP_KFFXP, DISK_KFFXP order by GROUP_KFFXP, DISK_KFFXP;

--Find The File distribution Between DisksSELECT * FROM v$asm_alias  WHERE  name='PWX_DATA.272.669293645';

SELECT GROUP_KFFXP Group#,DISK_KFFXP Disk#,AU_KFFXP AU#,XNUM_KFFXP Extent#FROM   X$KFFXP WHERE  number_kffxp=(SELECT file_number FROM v$asm_aliasWHERE name='PWX_DATA.272.669293645');

--or

SELECT GROUP_KFFXP Group#,DISK_KFFXP Disk#,AU_KFFXP AU#,XNUM_KFFXP Extent#FROM X$KFFXP WHERE  number_kffxp=&DataFile_Number;

--orselect d.name, XV.GROUP_KFFXP Group#, XV.DISK_KFFXP Disk#,XV.NUMBER_KFFXP File_Number, XV.AU_KFFXP AU#, XV.XNUM_KFFXP Extent#,XV.ADDR, XV.INDX, XV.INST_ID, XV.COMPOUND_KFFXP, XV.INCARN_KFFXP,XV.PXN_KFFXP, XV.XNUM_KFFXP,XV.LXN_KFFXP, XV.FLAGS_KFFXP,XV.CHK_KFFXP, XV.SIZE_KFFXP from v$asm_disk d, X$KFFXP XVwhere d.GROUP_NUMBER=XV.GROUP_KFFXP and d.DISK_NUMBER=XV.DISK_KFFXPand number_kffxp=&File_NUM order by 2,3,4;

--List the hierarchical tree of files stored in the diskgroupSELECT concat('+'||gname, sys_connect_by_path(aname, '/')) full_alias_path FROM(SELECT g.name gname, a.parent_index pindex, a.name aname,a.reference_index rindex FROM v$asm_alias a, v$asm_diskgroup gWHERE a.group_number = g.group_number)START WITH (mod(pindex, power(2, 24))) = 0CONNECT BY PRIOR rindex = pindex;

################################################################

####################################Create and Modify Disk Group###################################

Page 206: 11gR2 ASMCMD Commands

create diskgroup FRA1 external redundancy disk '/dev/vx/rdsk/oraASMdg/fra1'ATTRIBUTE 'compatible.rdbms' = '11.1', 'compatible.asm' = '11.1';

alter diskgroup FRA1  check all;

--on +ASM2 :alter diskgroup FRA1 mount;

--Add a second disk:alter diskgroup FRA1 add disk '/dev/vx/rdsk/oraASMdg/fra2';

--Add several disks with a wildcard:alter diskgroup FRA1 add disk '/dev/vx/rdsk/oraASMdg/fra*';

--Remove a disk from a diskgroup:alter diskgroup FRA1 drop disk 'FRA1_0002';

--Drop the entire DiskGroupdrop diskgroup DATA1 including contents;

--How to DROP the entire DiskGroup when it is in NOMOUNT Status--Generate the dd command which will reset the header of all the--disks belong the GROUP_NUMBER=0!!!!select 'dd if=/dev/zero of=''' ||PATH||''' bs=8192 count=100' from v$asm_diskwhere GROUP_NUMBER=0;

select * from v$asm_operation;

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

alter diskgroup FRA1 drop disk 'FRA1_0002';alter diskgroup FRA1 add disk '/dev/vx/rdsk/fra1dg/fra3';

alter diskgroup FRA1 drop disk 'FRA1_0003';alter diskgroup FRA1 add disk '/dev/vx/rdsk/fra1dg/fra4';

--When a new diskgroup is created, it is only mounted on the local instance,--and only the instance-specific entry for the asm_diskgroups parameter is updated. --By manually mounting the diskgroup on other instances, the asm_diskgroups parameter--on those instances are updated.

--on +ASM1 :

Page 207: 11gR2 ASMCMD Commands

create diskgroup FRA1 external redundancy disk '/dev/vx/rdsk/fradg/fra1'ATTRIBUTE 'compatible.rdbms' = '11.1', 'compatible.asm' = '11.1';

--on +ASM2 :alter diskgroup FRA1 mount;

--It works even for on going balances!!!alter diskgroup DATA1 rebalance power 10;

################################################################# New ASM Command Line Utility (ASMCMD) Commands and Options################################################################

ASMCMD Command Reference:

Command Description--------------------- cd Command Changes the current directory to the specified directory.- cp Command Enables you to copy files between ASM disk groups on a local instance and remote instances.- du Command Displays the total disk space occupied by ASM files in the specified- ASM directory and all of its subdirectories, recursively.- exit Command Exits ASMCMD.- find Command Lists the paths of all occurrences of the specified name (with wildcards) under the specified directory.- help Command Displays the syntax and description of ASMCMD commands.- ls Command Lists the contents of an ASM directory, the attributes of the specified- file, or the names and attributes of all disk groups.- lsct Command Lists information about current ASM clients.- lsdg Command Lists all disk groups and their attributes.- lsdsk Command Lists disks visible to ASM.- md_backup Command Creates a backup of all of the mounted disk groups.- md_restore Command Restores disk groups from a backup.- mkalias Command Creates an alias for system-generated filenames.- mkdir Command Creates ASM directories.- pwd Command Displays the path of the current ASM directory.- remap Command Repairs a range of physical blocks on a disk.- rm Command Deletes the specified ASM files or directories.- rmalias Command Deletes the specified alias, retaining the file that the alias points to.

---------- kfed tool From Unix Prompt for reading ASM disk header.kfed read /dev/vx/rdsk/fra1dg/fra1

Page 208: 11gR2 ASMCMD Commands

################################################################# CREATE and Manage Tablespaces and Datafiles on ASM################################################################

CREATE TABLESPACE my_ts DATAFILE '+disk_group_1' SIZE 100M AUTOEXTEND ON;

ALTER TABLESPACE sysaux ADD DATAFILE '+disk_group_1' SIZE 100M;

ALTER DATABASE DATAFILE '+DATA1/dbname/datafile/audit.259.668957419' RESIZE 150M;

-------------------------create diskgroup DATA1 external redundancy disk '/dev/vx/rdsk/oraASMdg/fra1'ATTRIBUTE 'compatible.rdbms' = '11.1', 'compatible.asm' = '11.1';

select 'alter diskgroup DATA1 add disk ''' || PATH || ''';' from v$asm_diskwhere GROUP_NUMBER=0 and rownum<=&Num_Disks_to_add;

select 'alter diskgroup FRA1 add disk ''' || PATH || ''';' from v$asm_diskwhere GROUP_NUMBER=0 and rownum<=&Num_Disks_to_add;

--Remove ASM headerselect 'dd if=/dev/zero of=''' ||PATH||''' bs=8192 count=100' from v$asm_diskwhere GROUP_NUMBER=0;

 =====

###################################################        ###### 11gR2 GRID Installation on Red Hat Enterprise 5 #########################################################

     #List of Operating System packages:

        binutils-2.17.50.0.6-6.el5 (x86_64)         compat-libstdc++-33-3.2.3-61 (x86_64) <<< both ARCH's are required.        compat-libstdc++-33-3.2.3-61 (i386) <<< both ARCH's are required.        elfutils-libelf-0.125-3.el5 (x86_64)         glibc-2.5-24 (x86_64) <<< both ARCH's are required.         glibc-2.5-24 (i686) <<< both ARCH's are required.        glibc-common-2.5-24 (x86_64)         ksh-20060214-1.7 (x86_64)         libaio-0.3.106-3.2 (x86_64) <<< both ARCH's are required.         libaio-0.3.106-3.2 (i386) <<< both ARCH's are required.

Page 209: 11gR2 ASMCMD Commands

        libgcc-4.1.2-42.el5 (i386) <<< both ARCH's are required.         libgcc-4.1.2-42.el5 (x86_64) <<< both ARCH's are required.        libstdc++-4.1.2-42.el5 (x86_64) <<< both ARCH's are required.        libstdc++-4.1.2-42.el5 (i386) <<< both ARCH's are required.        make-3.81-3.el5 (x86_64)         elfutils-libelf-devel-0.125-3.el5.x86_64.rpm         elfutils-libelf-devel-static-0.125-3.el5.x86_64.rpm         elfutils-libelf-devel and elfutils-libelf-devel-static         glibc-headers-2.5-24.x86_64.rpm         kernel-headers-2.6.18-92.el5.x86_64.rpm         glibc-devel-2.5-24.x86_64.rpm <<< both ARCH's are required.         glibc-devel-2.5-24.i386.rpm <<< both ARCH's are required.          gcc-4.1.2-42.el5.x86_64.rpm         libgomp-4.1.2-42.el5.x86_64.rpm         libstdc++-devel-4.1.2-42.el5.x86_64.rpm         gcc-c++-4.1.2-42.el5.x86_64.rpm         libaio-devel-0.3.106-3.2.x86_64.rpm <<< both ARCH's are required.         libaio-devel-0.3.106-3.2.i386.rpm <<< both ARCH's are required.          sysstat-7.0.2-1.el5.x86_64.rpm         unixODBC-2.2.11-7.1.x86_64.rpm <<< both ARCH's are required.        unixODBC-2.2.11-7.1.i386.rpm <<< both ARCH's are required.          unixODBC-devel-2.2.11-7.1.x86_64.rpm <<< both ARCH's are required.          unixODBC-devel-2.2.11-7.1.i386.rpm <<< both ARCH's are required. 

#ASMLIB packages#Platform depenfent but Kernel independentoracleasm-support-2.1.3-1.SLE10.x86_64.rpm oracleasmlib-2.0.4-1.SLE10.x86_64.rpm

#Platform and Kernel dependedoracleasm-2.6.16.46-0.12-smp-2.0.3-1.x86_64.rpm oracleasm-2.6.16.46-0.12-default-2.0.3-1.x86_64.rpm

###################################################

# ASMLib Configuration

[root@linux1 /]# /etc/init.d/oracleasm configureConfiguring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM librarydriver. The following questions will determine whether the driver isloaded on boot and what permissions it will have. The current valueswill be shown in brackets ('[]'). Hitting without typing ananswer will keep that current value. Ctrl-C will abort.

Default user to own the driver interface []: gridDefault group to own the driver interface []: asmdbaStart Oracle ASM library driver on boot (y/n) [n]: yFix permissions of Oracle ASM disks on boot (y/n) [y]: yWriting Oracle ASM library driver configuration [ OK ]Creating /dev/oracleasm mount point [ OK ]Loading module "oracleasm" [ OK ]Mounting ASMlib driver filesystem [ OK ]Scanning system for ASM disks [ OK ]

Page 210: 11gR2 ASMCMD Commands

###################################################

# Users and Groups Creation

-- groups[root@linux1 /]# /usr/sbin/groupadd -g 1000 oinstall[root@linux1 /]# /usr/sbin/groupadd -g 1001 asmadmin[root@linux1 /]# /usr/sbin/groupadd -g 1002 dba[root@linux1 /]# /usr/sbin/groupadd -g 1003 asmdba[root@linux1 /]# /usr/sbin/groupadd -g 1004 asmoper

-- users[root@linux1 /]# useradd -u 1100 -g oinstall -G asmadmin,asmdba,asmoper grid[root@linux1 /]# useradd -u 1101 -g oinstall -G asmdba,dba oracle

###################################################

# Set resource limits

[root@linux1 /]# vi  /etc/security/limits.conf## Go to the end grid     soft     nproc     2047grid     hard     nproc     16384grid     soft     nofile     1024grid     hard     nofile     65536oracle     soft     nproc     2047oracle     hard     nproc     16384oracle     soft     nofile     1024oracle     hard     nofile     65536

[root@linux1 /]# vi /etc/pam.d/loginsession     required    pam_limits.so

###################################################

# User Profile

[root@linux1 /]# vi to /etc/profile

if [ $USER = "oracle" ] || [ $USER = "grid" ]; then    if [ $SHELL = "/bin/ksh" ]; then        ulimit -p 16384        ulimit -n 65536    else        ulimit -u 16384 -n 65536    fi    umask 022fiif [ $USER = "root" ]; then         umask 022fi

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

Page 211: 11gR2 ASMCMD Commands

Additional checks for user profilesBefore the installation:- Unset any JAVA environment variables like JAVA_HOME. - Unset any ORACLE environment variables like  ORACLE_HOME, PATH, LD_LIBRARY_PATH - Set ORACLE_BASE

After the installation:- Set ORACLE_HOME, and include $ORACLE_HOME/bin at the beginning of the PATH string.

###################################################

# Network configuration

- SCAN Listener component, which needs three IPs registered into the DNS and   belong the same subnet used by the public NICs.-Vip and Private IPs as per example from the /etc/hosts  of one of the node:

10.0.1.10   linux1.emilianofusaglia.net  linux1    10.0.1.11   linux2.emilianofusaglia.net  linux2      10.0.1.12   linux1-vip.emilianofusaglia.net  linux1-vip      10.0.1.13   linux1-vip.emilianofusaglia.net  linux2-vip     

192.168.1.10   linux1-priv192.168.1.11   linux2-priv

###################################################

# Kernel Parameters

# Disable response to broadcasts.# You do not want yourself becoming a Smurf amplifier.net.ipv4.icmp_echo_ignore_broadcasts = 1# enable route verification on all interfacesnet.ipv4.conf.all.rp_filter = 1# enable ipV6 forwarding#net.ipv6.conf.all.forwarding = 1 # Set defaults for BladeFrame# added for Oracle 11gkernel.shmall = physical RAM size / pagesize kernel.shmmax = 1/2 of physical RAM, but not greater than 4GB kernel.shmmni = 4096kernel.sem = 250 32000 100 128fs.file-max = 512 x processes (for example 6815744 for 13312 processes) net.ipv4.ip_local_port_range = 9000 65500

net.ipv4.tcp_wmem = 262144 262144 262144net.ipv4.tcp_rmem = 4194304 4194304 4194304vm.hugetlb_shm_group=64948

#MIN UDP CONFIG to Review according to Interconnect traffic & confignet.core.rmem_default = 262144net.core.rmem_max = 4194304

Page 212: 11gR2 ASMCMD Commands

net.core.wmem_default = 262144net.core.wmem_max = 1048576

###################################################

# Create disk partitions and ASM disks

linux1:/u01 # fdisk -l /dev/sdh  Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1        4700    37747712   83  Linuxlinux1:/u01 # fdisk -l /dev/sdi Disk /dev/sdi: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdi1               1        4700    37747712   83  Linuxlinux1:/u01 # fdisk -l /dev/sdj Disk /dev/sdj: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdj1               1        4699    37744686   83  Linuxlinux1:/u01 # linux1:/u01 # fdisk /dev/sdh  The number of cylinders for this disk is set to 4699.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) Command (m for help): dSelected partition 1 Command (m for help): p Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System Command (m for help): nCommand action   e   extended

Page 213: 11gR2 ASMCMD Commands

   p   primary partition (1-4)p  Partition number (1-4): 1First cylinder (1-4699, default 1): 1Last cylinder or +size or +sizeM or +sizeK (1-4699, default 4699): +1024M Command (m for help): p Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1         125     1004031   83  Linux Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (126-4699, default 126): Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-4699, default 4699): Using default value 4699 Command (m for help): p Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1         125     1004031   83  Linux/dev/sdh2             126        4699    36740655   83  Linux Command (m for help): wThe partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.linux1:/u01 #partprobe

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

Once the disks have been sliced the ASM Disks can be created as showed below in the example

linux1:/u01 # /etc/init.d/oracleasm Usage: /etc/init.d/oracleasm {start|stop|restart|enable|disable|configure|createdisk|deletedisk|querydisk|listdisks|scandisks|status}linux1:/u01 # /etc/init.d/oracleasm createdisk OCR1 /dev/sdh1Marking disk "/dev/sdh1" as an ASM disk:                              donelinux1:/u01 # /etc/init.d/oracleasm createdisk DATA1 /dev/sdh2Marking disk "/dev/sdh2" as an ASM disk:                              done

Page 214: 11gR2 ASMCMD Commands

linux1:/u01 # /etc/init.d/oracleasm scandisksScanning system for ASM disks:                                        donelinux1:/u01 #

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

After having created all the ASM Disks runs the utility scandisks  on all nodes of the cluster, this allows ASM to  discover all the new ASM Disks created.

linux2:/dev/oracleasm/disks # /etc/init.d/oracleasm scandisksScanning system for ASM disks:                                        donelinux2:/dev/oracleasm/disks # /etc/init.d/oracleasm listdisksDATA1DATA2DATA3OCR1OCR2OCR3linux2:/dev/oracleasm/disks #

###################################################

# Create the installation directories

#Grid Homemkdir –p /u01/GRID/11.2chown –R grid:oinstall /u01/GRID/11.2chmod –R 775 /u01/GRID/11.2

#Oracle Basemkdir –p /u01/oraclechown –R oracle:oinstall /u01/oraclechmod –R 775 /u01/oracle

#Oracle Homemkdir –p /u01/oracle/product/11.2chown –R oracle:oinstall /u01/oracle/product/11.2chmod –R 775 /u01/oracle/product/11.2

###################################################

# Run Cluster verify utility

/u01/stage/grid > ./runcluvfy.sh stage -pre crsinst -n linux1,linux2 -verbose

###################################################

# Start the Installation

/u01/stage/grid > ./runInstaller

 

Page 215: 11gR2 ASMCMD Commands

################################################################# How to restore OCR and Voting disk after DiskGroup Corruption on Oracle 11g R2.################################################################

--Location and status of OCR before starting the test:root@host1:/u01/GRID/11.2/cdata # /u01/GRID/11.2/bin/ocrcheck                     Status of Oracle Cluster Registry is as follows :         Version                  :          3         Total space (kbytes)     :     262120         Used space (kbytes)      :       2744         Available space (kbytes) :     259376         ID                       :  401168391         Device/File Name         : +OCRVOTING                                    Device/File integrity check succeeded                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured          Cluster registry integrity check succeeded          Logical corruption check succeeded 

--Check the existency of BACKUPS:root@host1:/root # /u01/GRID/11.2/bin/ocrconfig -showbackup host1     2010/01/21 14:17:54     /u01/GRID/11.2/cdata/cluster01/backup00.ocr host1     2010/01/21 05:58:31     /u01/GRID/11.2/cdata/cluster01/backup01.ocr host1     2010/01/21 01:58:30     /u01/GRID/11.2/cdata/cluster01/backup02.ocr host1     2010/01/20 05:58:21     /u01/GRID/11.2/cdata/cluster01/day.ocr host1     2010/01/14 23:12:07     /u01/GRID/11.2/cdata/cluster01/week.ocrPROT-25: Manual backups for the Oracle Cluster Registry are not available

--Identify all the disks belong the Disk group +OCRVOTING:

NAME                                       PATH

Page 216: 11gR2 ASMCMD Commands

------------------------------ ------------------------------------------------------------OCRVOTING_0000                 /dev/oracle/asm.25.lunOCRVOTING_0001                 /dev/oracle/asm.26.lunOCRVOTING_0002                 /dev/oracle/asm.27.lunOCRVOTING_0003                 /dev/oracle/asm.28.lunOCRVOTING_0004                 /dev/oracle/asm.29.lun 5 rows selected.

--Corrupt tht disks belong the Disk group +OCRVOTING:dd if=/tmp/corrupt_disk of=/dev/oracle/asm.25.lun bs=1024 count=1000dd if=/tmp/corrupt_disk of=/dev/oracle/asm.26.lun bs=1024 count=1000dd if=/tmp/corrupt_disk of=/dev/oracle/asm.27.lun bs=1024 count=1000dd if=/tmp/corrupt_disk of=/dev/oracle/asm.28.lun bs=1024 count=1000dd if=/tmp/corrupt_disk of=/dev/oracle/asm.29.lun bs=1024 count=1000

--OCR Check after Corruption:root@host1:/tmp # /u01/GRID/11.2/bin/ocrcheckStatus of Oracle Cluster Registry is as follows :         Version                  :          3         Total space (kbytes)     :     262120         Used space (kbytes)      :       2712         Available space (kbytes) :     259408         ID                       :  701409037         Device/File Name         : +OCRVOTING                                    Device/File integrity check succeeded                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured          Cluster registry integrity check succeeded          Logical corruption check succeeded

--Stop and Start of database instance after corruptionoracle@host1:/u01/oracle/data $ srvctl stop instance -d DB -i DB1oracle@host1:/u01/oracle/data $ srvctl start instance -d DB -i DB1

--Stop and Start entire Cluster:

Page 217: 11gR2 ASMCMD Commands

-host1:root@host1:/tmp # /u01/GRID/11.2/bin/crsctl stop crsCRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'host1'CRS-2673: Attempting to stop 'ora.crsd' on 'host1'CRS-2790: Starting shutdown of Cluster Ready Services-managed resources on 'host1'CRS-2673: Attempting to stop 'ora.OCRVOTING.dg' on 'host1'CRS-2673: Attempting to stop 'ora.db.db' on 'host1'CRS-2673: Attempting to stop 'ora.LISTENER.lsnr' on 'host1'CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'host1' succeededCRS-2673: Attempting to stop 'ora.host1.vip' on 'host1'CRS-2677: Stop of 'ora.host1.vip' on 'host1' succeededCRS-2677: Stop of 'ora.OCRVOTING.dg' on 'host1' succeededCRS-2673: Attempting to stop 'ora.scan2.vip' on 'host1'CRS-2673: Attempting to stop 'ora.scan3.vip' on 'host1'CRS-2673: Attempting to stop 'ora.host2.vip' on 'host1'CRS-2677: Stop of 'ora.scan2.vip' on 'host1' succeededCRS-2677: Stop of 'ora.scan3.vip' on 'host1' succeededCRS-2677: Stop of 'ora.host2.vip' on 'host1' succeededCRS-2677: Stop of 'ora.db.db' on 'host1' succeededCRS-2673: Attempting to stop 'ora.DATA1.dg' on 'host1'CRS-2673: Attempting to stop 'ora.FRA1.dg' on 'host1'CRS-2677: Stop of 'ora.DATA1.dg' on 'host1' succeededCRS-2677: Stop of 'ora.FRA1.dg' on 'host1' succeededCRS-2673: Attempting to stop 'ora.asm' on 'host1'CRS-2677: Stop of 'ora.asm' on 'host1' succeededCRS-2673: Attempting to stop 'ora.ons' on 'host1'CRS-2673: Attempting to stop 'ora.eons' on 'host1'CRS-2677: Stop of 'ora.ons' on 'host1' succeededCRS-2673: Attempting to stop 'ora.net1.network' on 'host1'CRS-2677: Stop of 'ora.net1.network' on 'host1' succeededCRS-2677: Stop of 'ora.eons' on 'host1' succeededCRS-2792: Shutdown of Cluster Ready Services-managed resources on 'host1' has completedCRS-2677: Stop of 'ora.crsd' on 'host1' succeededCRS-2673: Attempting to stop 'ora.mdnsd' on 'host1'CRS-2673: Attempting to stop 'ora.gpnpd' on 'host1'CRS-2673: Attempting to stop 'ora.cssdmonitor' on 'host1'CRS-2673: Attempting to stop 'ora.ctssd' on 'host1'CRS-2673: Attempting to stop 'ora.evmd' on 'host1'CRS-2673: Attempting to stop 'ora.asm' on 'host1'CRS-2677: Stop of 'ora.cssdmonitor' on 'host1' succeededCRS-2677: Stop of 'ora.mdnsd' on 'host1' succeededCRS-2677: Stop of 'ora.gpnpd' on 'host1' succeededCRS-2677: Stop of 'ora.evmd' on 'host1' succeededCRS-2677: Stop of 'ora.ctssd' on 'host1' succeededCRS-2677: Stop of 'ora.asm' on 'host1' succeeded

Page 218: 11gR2 ASMCMD Commands

CRS-2673: Attempting to stop 'ora.cssd' on 'host1'CRS-2677: Stop of 'ora.cssd' on 'host1' succeededCRS-2673: Attempting to stop 'ora.diskmon' on 'host1'CRS-2673: Attempting to stop 'ora.gipcd' on 'host1'CRS-2677: Stop of 'ora.gipcd' on 'host1' succeededCRS-2677: Stop of 'ora.diskmon' on 'host1' succeededCRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'host1' has completedCRS-4133: Oracle High Availability Services has been stopped.

--host2:root@host2:/root # /u01/GRID/11.2/bin/crsctl stop crsCRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'host2'CRS-2673: Attempting to stop 'ora.crsd' on 'host2'CRS-2790: Starting shutdown of Cluster Ready Services-managed resources on 'host2'CRS-2673: Attempting to stop 'ora.LISTENER_SCAN2.lsnr' on 'host2'CRS-2673: Attempting to stop 'ora.LISTENER_SCAN3.lsnr' on 'host2'CRS-2673: Attempting to stop 'ora.LISTENER.lsnr' on 'host2'CRS-2673: Attempting to stop 'ora.OCRVOTING.dg' on 'host2'CRS-2673: Attempting to stop 'ora.db.db' on 'host2'CRS-2673: Attempting to stop 'ora.LISTENER_SCAN1.lsnr' on 'host2'CRS-2677: Stop of 'ora.LISTENER_SCAN2.lsnr' on 'host2' succeededCRS-2673: Attempting to stop 'ora.scan2.vip' on 'host2'CRS-2677: Stop of 'ora.scan2.vip' on 'host2' succeededCRS-2672: Attempting to start 'ora.scan2.vip' on 'host1'CRS-2677: Stop of 'ora.LISTENER_SCAN3.lsnr' on 'host2' succeededCRS-2673: Attempting to stop 'ora.scan3.vip' on 'host2'CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'host2' succeededCRS-2673: Attempting to stop 'ora.host2.vip' on 'host2'CRS-2677: Stop of 'ora.scan3.vip' on 'host2' succeededCRS-2672: Attempting to start 'ora.scan3.vip' on 'host1'CRS-2677: Stop of 'ora.host2.vip' on 'host2' succeededCRS-2672: Attempting to start 'ora.host2.vip' on 'host1'CRS-2677: Stop of 'ora.LISTENER_SCAN1.lsnr' on 'host2' succeededCRS-2673: Attempting to stop 'ora.scan1.vip' on 'host2'CRS-2677: Stop of 'ora.scan1.vip' on 'host2' succeededCRS-2676: Start of 'ora.scan2.vip' on 'host1' succeededCRS-2676: Start of 'ora.scan3.vip' on 'host1' succeededCRS-2676: Start of 'ora.host2.vip' on 'host1' succeededCRS-2677: Stop of 'ora.OCRVOTING.dg' on 'host2' succeededCRS-2677: Stop of 'ora.db.db' on 'host2' succeededCRS-2673: Attempting to stop 'ora.DATA1.dg' on 'host2'CRS-2673: Attempting to stop 'ora.FRA1.dg' on 'host2'CRS-2677: Stop of 'ora.DATA1.dg' on 'host2' succeededCRS-2677: Stop of 'ora.FRA1.dg' on 'host2' succeededCRS-2673: Attempting to stop 'ora.asm' on 'host2'

Page 219: 11gR2 ASMCMD Commands

CRS-2677: Stop of 'ora.asm' on 'host2' succeededCRS-2673: Attempting to stop 'ora.ons' on 'host2'CRS-2673: Attempting to stop 'ora.eons' on 'host2'CRS-2677: Stop of 'ora.ons' on 'host2' succeededCRS-2673: Attempting to stop 'ora.net1.network' on 'host2'CRS-2677: Stop of 'ora.net1.network' on 'host2' succeededCRS-2677: Stop of 'ora.eons' on 'host2' succeededCRS-2792: Shutdown of Cluster Ready Services-managed resources on 'host2' has completedCRS-2677: Stop of 'ora.crsd' on 'host2' succeededCRS-2673: Attempting to stop 'ora.gpnpd' on 'host2'CRS-2673: Attempting to stop 'ora.cssdmonitor' on 'host2'CRS-2673: Attempting to stop 'ora.ctssd' on 'host2'CRS-2673: Attempting to stop 'ora.evmd' on 'host2'CRS-2673: Attempting to stop 'ora.asm' on 'host2'CRS-2673: Attempting to stop 'ora.mdnsd' on 'host2'CRS-2677: Stop of 'ora.cssdmonitor' on 'host2' succeededCRS-2677: Stop of 'ora.gpnpd' on 'host2' succeededCRS-2677: Stop of 'ora.evmd' on 'host2' succeededCRS-2677: Stop of 'ora.mdnsd' on 'host2' succeededCRS-2677: Stop of 'ora.asm' on 'host2' succeededCRS-2677: Stop of 'ora.ctssd' on 'host2' succeededCRS-2673: Attempting to stop 'ora.cssd' on 'host2'CRS-2677: Stop of 'ora.cssd' on 'host2' succeededCRS-2673: Attempting to stop 'ora.diskmon' on 'host2'CRS-2673: Attempting to stop 'ora.gipcd' on 'host2'CRS-2677: Stop of 'ora.gipcd' on 'host2' succeededCRS-2677: Stop of 'ora.diskmon' on 'host2' succeededCRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'host2' has completedCRS-4133: Oracle High Availability Services has been stopped.

--host1root@host1:/root # /u01/GRID/11.2/bin/crsctl start crsCRS-4123: Oracle High Availability Services has been started.

--host2root@host2:/u01/GRID/11.2/cdata/cluster01 # /u01/GRID/11.2/bin/crsctl start crsCRS-4123: Oracle High Availability Services has been started.

--CRS Alert log: (Start failed because the Diskgroup is not available)2010-01-21 16:29:07.785[cssd(10123)]CRS-1705:Found 0 configured voting files but 1 voting files are required, terminating to ensure data integrity; details at (:CSSNM00065:) in /u01/GRID/11.2/log/host1/cssd/ocssd.log2010-01-21 16:29:07.785

Page 220: 11gR2 ASMCMD Commands

[cssd(10123)]CRS-1603:CSSD on node host1 shutdown by user.2010-01-21 16:29:07.918[ohasd(9931)]CRS-2765:Resource 'ora.cssdmonitor' has failed on server 'host1'.2010-01-21 16:30:05.489[/u01/GRID/11.2/bin/orarootagent.bin(10113)]CRS-5818:Aborted command 'start for resource: ora.diskmon 1 1' for resource 'ora.diskmon'. Details at (:CRSAGF00113:) in /u01/GRID/11.2/log/host1/agent/ohasd/orarootagent_root/orarootagent_root.log.2010-01-21 16:30:09.504[ohasd(9931)]CRS-2757:Command 'Start' timed out waiting for response from the resource 'ora.diskmon'. Details at (:CRSPE00111:) in /u01/GRID/11.2/log/host1/ohasd/ohasd.log.2010-01-21 16:30:20.687[cssd(10622)]CRS-1713:CSSD daemon is started in clustered mode2010-01-21 16:30:21.801[cssd(10622)]CRS-1705:Found 0 configured voting files but 1 voting files are required, terminating to ensure data integrity; details at (:CSSNM00065:) in /u01/GRID/11.2/log/host1/cssd/ocssd.log2010-01-21 16:30:21.801[cssd(10622)]CRS-1603:CSSD on node host1 shutdown by user.

--host1 STOP CRS because due to Voting Disk unavailability is not running properly:root@host1:/tmp # /u01/GRID/11.2/bin/crsctl stop crsCRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'host1'CRS-2673: Attempting to stop 'ora.crsd' on 'host1'CRS-4548: Unable to connect to CRSDCRS-2675: Stop of 'ora.crsd' on 'host1' failedCRS-2679: Attempting to clean 'ora.crsd' on 'host1'CRS-4548: Unable to connect to CRSDCRS-2678: 'ora.crsd' on 'host1' has experienced an unrecoverable failureCRS-0267: Human intervention required to resume its availability.CRS-2795: Shutdown of Oracle High Availability Services-managed resources on 'host1' has failedCRS-4687: Shutdown command has completed with error(s).CRS-4000: Command Stop failed, or completed with errors.

--Because all the processes are not STOPPING, disable the cluster AUTO Start and reboot--the server for cleaning all the pending processes.

root@host1:/tmp # /u01/GRID/11.2/bin/crsctl disable crsCRS-4621: Oracle High Availability Services autostart is disabled.

root@host1:/tmp # reboot

--Start the Cluster in EXLUSIVE Mode in order to recreate ASM Diskgroup:root@host1:/root # /u01/GRID/11.2/bin/crsctl start crs -excl

Page 221: 11gR2 ASMCMD Commands

CRS-4123: Oracle High Availability Services has been started.CRS-2672: Attempting to start 'ora.gipcd' on 'host1'CRS-2672: Attempting to start 'ora.mdnsd' on 'host1'CRS-2676: Start of 'ora.gipcd' on 'host1' succeededCRS-2676: Start of 'ora.mdnsd' on 'host1' succeededCRS-2672: Attempting to start 'ora.gpnpd' on 'host1'CRS-2676: Start of 'ora.gpnpd' on 'host1' succeededCRS-2672: Attempting to start 'ora.cssdmonitor' on 'host1'CRS-2676: Start of 'ora.cssdmonitor' on 'host1' succeededCRS-2672: Attempting to start 'ora.cssd' on 'host1'CRS-2679: Attempting to clean 'ora.diskmon' on 'host1'CRS-2681: Clean of 'ora.diskmon' on 'host1' succeededCRS-2672: Attempting to start 'ora.diskmon' on 'host1'CRS-2676: Start of 'ora.diskmon' on 'host1' succeededCRS-2676: Start of 'ora.cssd' on 'host1' succeededCRS-2672: Attempting to start 'ora.ctssd' on 'host1'CRS-2676: Start of 'ora.ctssd' on 'host1' succeededCRS-2672: Attempting to start 'ora.asm' on 'host1'CRS-2676: Start of 'ora.asm' on 'host1' succeededCRS-2672: Attempting to start 'ora.crsd' on 'host1'CRS-2676: Start of 'ora.crsd' on 'host1' succeeded

--Stop ASM and restart it using a pfile example:*.asm_diskgroups='DATA1','FRA1'*.asm_diskstring='/dev/oracle/asm*'*.diagnostic_dest='/u01/oracle'+ASM1.instance_number=1+ASM2.instance_number=2*.instance_type='asm'*.large_pool_size=12M*.processes=500*.sga_max_size=1G*.sga_target=1G*.shared_pool_size=300M   --Recreate ASM Diskgroup--This command FAILS because asmca is not able to update the OCR:asmca -silent -createDiskGroup -diskGroupName OCRVOTING  -disk '/dev/oracle/asm.25.lun' -disk '/dev/oracle/asm.26.lun'  -disk '/dev/oracle/asm.27.lun'  -disk '/dev/oracle/asm.28.lun'  -disk '/dev/oracle/asm.29.lun'  -redundancy HIGH -compatible.asm '11.2.0.0.0'  -compatible.rdbms '11.2.0.0.0' -compatible.advm '11.2.0.0.0'

--Create the Diskgroup Using SQLPLUS Create Diskgroup and save the ASM spfile inside:create Diskgroup OCRVOTING high redundancy disk '/dev/oracle/asm.25.lun',

Page 222: 11gR2 ASMCMD Commands

'/dev/oracle/asm.26.lun', '/dev/oracle/asm.27.lun','/dev/oracle/asm.28.lun', '/dev/oracle/asm.29.lun'ATTRIBUTE  'compatible.asm'='11.2.0.0.0', 'compatible.rdbms'='11.2.0.0.0';

create spfile='+OCRVOTING' from pfile='/tmp/asm_pfile.ora'; File created. SQL> shut immediateASM diskgroups dismountedASM instance shutdownSQL> startupASM instance started Total System Global Area 1069252608 bytesFixed Size                  2154936 bytesVariable Size            1041931848 bytesASM Cache                  25165824 bytesASM diskgroups mounted

-- Restore OCR from backup:root@host1:/root # /u01/GRID/11.2/bin/ocrconfig -restore /u01/GRID/11.2/cdata/cluster01/backup00.ocr

--Check the OCR status after restore:root@host1:/root # /u01/GRID/11.2/bin/ocrcheck                                                    Status of Oracle Cluster Registry is as follows :         Version                  :          3         Total space (kbytes)     :     262120         Used space (kbytes)      :       2712         Available space (kbytes) :     259408         ID                       :  701409037         Device/File Name         : +OCRVOTING                                    Device/File integrity check succeeded                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured                                     Device/File not configured          Cluster registry integrity check succeeded          Logical corruption check succeeded 

Page 223: 11gR2 ASMCMD Commands

--Restore the Voting Disk:root@host1:/root # /u01/GRID/11.2/bin/crsctl replace votedisk +OCRVOTINGSuccessful addition of voting disk 7s16f9fbf4b64f74bfy0ee8826f15eb4.Successful addition of voting disk 9k6af49d3cd54fc5bf28a2fc3899c8c6.Successful addition of voting disk 876eb99563924ff6bfc1defe6865deeb.Successful addition of voting disk 12230b5ef41f4fc2bf2cae957f765fb0.Successful addition of voting disk 47812b7f6p034f33bf13490e6e136b8b.Successfully replaced voting disk group with +OCRVOTING.CRS-4266: Voting file(s) successfully replaced

--Re-enable CRS auto staruproot@host1:/root # /u01/GRID/11.2/bin/crsctl enable crsCRS-4622: Oracle High Availability Services autostart is enabled.

--Stop CRS on host1root@host1:/root # /u01/GRID/11.2/bin/crsctl stop crs  CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'host1'CRS-2673: Attempting to stop 'ora.crsd' on 'host1'CRS-2677: Stop of 'ora.crsd' on 'host1' succeededCRS-2673: Attempting to stop 'ora.gpnpd' on 'host1'CRS-2673: Attempting to stop 'ora.cssdmonitor' on 'host1'CRS-2673: Attempting to stop 'ora.ctssd' on 'host1'CRS-2673: Attempting to stop 'ora.asm' on 'host1'CRS-2673: Attempting to stop 'ora.mdnsd' on 'host1'CRS-2677: Stop of 'ora.cssdmonitor' on 'host1' succeededCRS-2677: Stop of 'ora.gpnpd' on 'host1' succeededCRS-2677: Stop of 'ora.mdnsd' on 'host1' succeededCRS-2677: Stop of 'ora.ctssd' on 'host1' succeededCRS-2677: Stop of 'ora.asm' on 'host1' succeededCRS-2673: Attempting to stop 'ora.cssd' on 'host1'CRS-2677: Stop of 'ora.cssd' on 'host1' succeededCRS-2673: Attempting to stop 'ora.diskmon' on 'host1'CRS-2673: Attempting to stop 'ora.gipcd' on 'host1'CRS-2677: Stop of 'ora.gipcd' on 'host1' succeededCRS-2677: Stop of 'ora.diskmon' on 'host1' succeededCRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'host1' has completedCRS-4133: Oracle High Availability Services has been stopped.

--Start CRS on host1root@host1:/root # /u01/GRID/11.2/bin/crsctl start crsCRS-4123: Oracle High Availability Services has been started.

--Start CRS on host2

Page 224: 11gR2 ASMCMD Commands

root@host2:/root # /u01/GRID/11.2/bin/crsctl start crs   CRS-4123: Oracle High Availability Services has been started.

--Check if all the Resources are running:root@host1:/root # /u01/GRID/11.2/bin/crsctl stat res -t--------------------------------------------------------------------------------NAME           TARGET  STATE        SERVER                   STATE_DETAILS      --------------------------------------------------------------------------------Local Resources--------------------------------------------------------------------------------ora.DATA1.dg               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.FRA1.dg               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.LISTENER.lsnr               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.OCRVOTING.dg               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.asm               ONLINE  ONLINE       host1                 Started                           ONLINE  ONLINE       host2                 Started            ora.eons               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.gsd               OFFLINE OFFLINE      host1                                                   OFFLINE OFFLINE      host2                                    ora.net1.network               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    ora.ons               ONLINE  ONLINE       host1                                                   ONLINE  ONLINE       host2                                    --------------------------------------------------------------------------------Cluster Resources--------------------------------------------------------------------------------ora.LISTENER_SCAN1.lsnr      1        ONLINE  ONLINE       host1                                    ora.LISTENER_SCAN2.lsnr      1        ONLINE  ONLINE       host2                                    ora.LISTENER_SCAN3.lsnr      1        ONLINE  ONLINE       host2                                    ora.db.db      1        ONLINE  ONLINE       host1                 Open              

Page 225: 11gR2 ASMCMD Commands

      2        ONLINE  ONLINE       host2                 Open               ora.oc4j      1        OFFLINE OFFLINE                                                  ora.scan1.vip      1        ONLINE  ONLINE       host1                                    ora.scan2.vip      1        ONLINE  ONLINE       host2                                    ora.scan3.vip      1        ONLINE  ONLINE       host2                                    ora.host1.vip      1        ONLINE  ONLINE       host1                                    ora.host2.vip      1        ONLINE  ONLINE       host2                  

##################################################################### How to add an Application VIP to Oracle Cluster 11gR2###################################################################

Oracle Clusterware includes the utility appvipcfg which allows to easily create application VIPs; below an example based on a cluster 11.2.0.3.1

[root@lnxcld02 ~]# appvipcfg -hProduction Copyright 2007, 2008, Oracle.All rights reservedUnknown option: h

  Usage: appvipcfg create -network=<network_number> -ip=<ip_address> -vipname=<vipname>                          -user=<user_name>[-group=<group_name>] [-failback=0 | 1]                   delete -vipname=<vipname>

--Example to run as root user:[root@lnxcld02 ~]# appvipcfg create -network=1 -ip=192.168.2.200 -vipname=myappvip -user=grid -group=oinstall

Production Copyright 2007, 2008, Oracle.All rights reserved2012-02-10 14:39:23: Creating Resource Type2012-02-10 14:39:23: Executing /home/GRID_INFRA/product/11.2.0.3/bin/crsctl add type app.appvip_net1.type -basetype ora.cluster_vip_net1.type -file /home/GRID_INFRA/product/11.2.0.3/crs/template/appvip.type2012-02-10 14:39:23: Executing cmd: /home/GRID_INFRA/product/11.2.0.3/bin/crsctl add type app.appvip_net1.type -basetype ora.cluster_vip_net1.type -file /home/GRID_INFRA/product/11.2.0.3/crs/template/appvip.type2012-02-10 14:39:26: Create the Resource2012-02-10 14:39:26: Executing /home/GRID_INFRA/product/11.2.0.3/bin/crsctl add resource myappvip -type app.appvip_net1.type -attr "USR_ORA_VIP=192.168.2.200,START_DEPENDENCIES=hard(ora.net1.network) pullup(ora.net1.network),STOP_DEPENDENCIES=hard(ora.net1.network),ACL='owner:root:rwx,pgrp:root:r-x,other::r--,group:oinstall:r-x,user:grid:r-x',HOSTING_MEMBERS=lnxcld02,APPSVIP_FAILBACK="

Page 226: 11gR2 ASMCMD Commands

2012-02-10 14:39:26: Executing cmd: /home/GRID_INFRA/product/11.2.0.3/bin/crsctl add resource myappvip -type app.appvip_net1.type -attr "USR_ORA_VIP=192.168.2.200,START_DEPENDENCIES=hard(ora.net1.network) pullup(ora.net1.network),STOP_DEPENDENCIES=hard(ora.net1.network),ACL='owner:root:rwx,pgrp:root:r-x,other::r--,group:oinstall:r-x,user:grid:r-x',HOSTING_MEMBERS=lnxcld02,APPSVIP_FAILBACK="

##############################################################################################

[grid@lnxcld02 trace]$ crsctl stat res -t--------------------------------------------------------------------------------NAME           TARGET  STATE        SERVER                   STATE_DETAILS       --------------------------------------------------------------------------------Local Resources--------------------------------------------------------------------------------ora.DATA1.dg               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.FRA1.dg               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.LISTENER.lsnr               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.OCRVOTING.dg               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.asm               ONLINE  ONLINE       lnxcld01                 Started                            ONLINE  ONLINE       lnxcld02                 Started             ora.gsd               OFFLINE OFFLINE      lnxcld01                                                    OFFLINE OFFLINE      lnxcld02                                     ora.net1.network               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.ons               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     ora.registry.acfs               ONLINE  ONLINE       lnxcld01                                                    ONLINE  ONLINE       lnxcld02                                     --------------------------------------------------------------------------------Cluster Resources--------------------------------------------------------------------------------myappvip      1        ONLINE  ONLINE       lnxcld02                                     

Page 227: 11gR2 ASMCMD Commands

ora.LISTENER_SCAN1.lsnr      1        ONLINE  ONLINE       lnxcld02                                     ora.cvu      1        ONLINE  ONLINE       lnxcld02                                     ora.lnxcld01.vip      1        ONLINE  ONLINE       lnxcld01                                     ora.lnxcld02.vip      1        ONLINE  ONLINE       lnxcld02                                     ora.oc4j      1        ONLINE  ONLINE       lnxcld02                                     ora.scan1.vip      1        ONLINE  ONLINE       lnxcld02                                     ora.tpolicy.db      1        ONLINE  ONLINE       lnxcld01                 Open                      2        ONLINE  ONLINE       lnxcld02                 Open                ora.tpolicy.loadbalance_rw.svc      1        ONLINE  ONLINE       lnxcld01                                           2        ONLINE  ONLINE       lnxcld02                                    

##############################################################################################

[grid@lnxcld02 ~]$ crsctl stat res myappvip -pNAME=myappvipTYPE=app.appvip_net1.typeACL=owner:root:rwx,pgrp:root:r-x,other::r--,group:oinstall:r-x,user:grid:r-xACTION_FAILURE_TEMPLATE=ACTION_SCRIPT=ACTIVE_PLACEMENT=1AGENT_FILENAME=%CRS_HOME%/bin/orarootagent%CRS_EXE_SUFFIX%APPSVIP_FAILBACK=0AUTO_START=restoreCARDINALITY=1CHECK_INTERVAL=1CHECK_TIMEOUT=30DEFAULT_TEMPLATE=PROPERTY(RESOURCE_CLASS=vip)DEGREE=1DESCRIPTION=Application VIPENABLED=1FAILOVER_DELAY=0FAILURE_INTERVAL=0FAILURE_THRESHOLD=0GEN_USR_ORA_STATIC_VIP=GEN_USR_ORA_VIP=HOSTING_MEMBERS=lnxcld02LOAD=1LOGGING_LEVEL=1NLS_LANG=

Page 228: 11gR2 ASMCMD Commands

NOT_RESTARTING_TEMPLATE=OFFLINE_CHECK_INTERVAL=0PLACEMENT=balancedPROFILE_CHANGE_TEMPLATE=RESTART_ATTEMPTS=0SCRIPT_TIMEOUT=60SERVER_POOLS=*START_DEPENDENCIES=hard(ora.net1.network) pullup(ora.net1.network)START_TIMEOUT=0STATE_CHANGE_TEMPLATE=STOP_DEPENDENCIES=hard(ora.net1.network)STOP_TIMEOUT=0TYPE_VERSION=2.1UPTIME_THRESHOLD=7dUSR_ORA_ENV=USR_ORA_VIP=192.168.2.200VERSION=11.2.0.3.0

################################################################# Oracle Clusterware Commands release 11.1################################################################Command Description:crs_getperm    Lists the permissions associated with a resource.crs_profile       Creates, validates, deletes, and updates an Oracle Clusterware application profilecrs_register     Registers configuration information for an application with the OCR.crs_relocate    Relocates an application profile to another node.crs_setperm    Sets permissions associated with a resource.crs_stat           Lists the status of an application profile.crs_start          Starts applications that have been registered.crs_stop           Stops an Oracle Clusterware application.crs_unregister  Removes the configuration information for an application profile from the OCR.

#################################################################  S T A R T - S T O P - S T A T U S   O R A C L E  C L U S T E R################################################################--To stop or start oracle clusterware on a node in a managed fashion:-- as root account/etc/init.d/init.crs [stop|start]--or[root@node1 root]# crsctl stop crs

Page 229: 11gR2 ASMCMD Commands

--To disable the oracle cluster so it doesn't attempt to start after a reboot, or--to ensure that it will be started automatically on boot:/etc/init.d/init.crs [disable|enable]--or[root@node1 root] # crsctl enable crs

--As the oracle user on docrac1, check the status of the Oracle Clusterware/crs/bin/crs_stat -t

--Verify that Oracle Clusterware is running on the node[root@node1 root] #crsctl check crs

--Check the status of an individual Oracle Clusterware daemon using the following--syntax, where daemon is crsd, cssd, or evmd:[root@node1 root] # crsctl check daemon

-- Check the existence and the location of Voting Disk[root@node1 root] # crsctl query  css votedisk

##Cluster Verification Utility (CVU) to verify the OCR integrity. Run the--following command, where the -n all argument retrieves a list of all the cluster--nodes that are configured as part of your cluster:[root]# cluvfy comp ocr -n all [-verbose]

##You use the CVU comp nodeapp command to verify the existence of node--applications, namely the virtual IP (VIP), Oracle Notification Services (ONS), and--Global Service Daemon (GSD), on all the nodes.[root]# cluvfy comp nodeapp [ -n node_list] [-verbose]

##To check the settings for the interconnect:--1. In a command window, log in to the operating system as the root user.--2. To verify the accessibility of the cluster nodes, specified by node_list, from the--local node or from any other cluster node, specified by srcnode, use the--component verification command nodereach as follows:[root]# cluvfy comp nodereach -n node_list [ -srcnode node ] [-verbose]

##To verify the connectivity among the nodes through specific network interfaces,[root]# cluvfy comp nodecon -n node_list -i interface_list [-verbose][root]# cluvfy comp nodecon -n docrac1, docrac2, docrac3 -i eth0 -verbose

###Oracle Clusterware Diagnostics Collection Script--The diagnostics provide additional information so that Oracle Support Services--can resolve problems. It displays the status of the Cluster Synchronization--Services (CSS), Event Manager (EVM), and the Cluster Ready Services (CRS) daemons

Page 230: 11gR2 ASMCMD Commands

[root@node1 root] # CRS_home/bin/diagcollection.pl --collect

#################################################################  DEBUGGING OF ORACLE CLUSTERWARE COMPONENTS################################################################--1. In a command window, log in to the operating system as the root user.--2. Use the following command to obtain the module names for a component, where--component_name is crs, evm, css or the name of the component for which you--want to enable debugging:# crsctl lsmodules component_name

--For example, viewing the modules of the css component might return the following results:# crsctl lsmodules cssThe following are the CSS modules ::CSSDCOMMCRSCOMMNS

--3. Use CRSCTL as follows, where component_name is the name of the Oracle--Clusterware component for which you want to enable debugging, module is the--name of module, and debugging_level is a number from 1 to 5:# crsctl debug log component module:debugging_level

For example, to enable the lowest level of tracing for the CSSD module of the csscomponent, you would use the following command:# crsctl debug log css CSSD:1

--4. After you have obtained the needed trace information, disable debugging by--setting the debugging_level to 0 for the module, as shown in the followingexample.# crsctl debug log css CSSD:0

################################################################# OLSNODES and OIFCFG utility################################################################--The OLSNODES command provides the list of nodes and other information--for all nodes participating in the cluster

olsnodes [-n] [-i] [-l] [-v] [-g] [-p]

-g Logs cluster verification information with more details.-i Lists all nodes participating in the cluster and includes the Virtual InternetProtocol (VIP) address assigned to each node.-l Displays the local node name.

Page 231: 11gR2 ASMCMD Commands

-n Lists al nodes participating in the cluster and includes the assigned nodenumbers.-p Lists all nodes participating in the cluster and includes the private interconnectassigned to each node.-v Logs cluster verification information in verbose mode.

-------------------------------------------------------------------------------------Before you invoke OIFCFG, ensure that you have started Oracle Clusterware on at--least the local node and preferably on all nodes if you intend to include the -global--option on the command.

OIFCFG

################################################################# SRVCTL Utility for OCR management################################################################--Using srvctl the standard tool for stopping and starting services.  The most used commands aresrvctl [stop|start] database -d DBNAMEsrvctl [stop|start] instance -d DBNAME -i SIDsrcvtl [stop|start] nodeapps -n HOSTNAME

--example./srvctl status asm -n docrac1ASM instance +ASM1 is running on node docrac1.   --Stop all the node applications running in a Oracle Clusterware: ASM instance, RAC instances--node_name is the name of the node:$ CRS_home/crs/bin/srvctl stop nodeapps -n node_name  

--Stop Oracle Clusterware using[root]# CRS_home/bin/crsctl stop crs

#################################################################                   V O T I N G  -  D I S K S################################################################

#################################Backup / Restore VOTING Disk################################

dd if=voting_disk_name of=backup_file_name

Page 232: 11gR2 ASMCMD Commands

--Backup Example Using RAW Devicesdd if=/dev/sdd1 of=/tmp/voting.dmp

--Restore Example Using RAW Devicesdd if=backup_file_name of=voting_disk_name

-- P.S.--When you use the dd command for making backups of the voting disk, the backup can--be performed while the Cluster Ready Services (CRS) process is active; you do not--need to stop the crsd.bin process before taking a backup of the voting disk.

################################################################

################################# Adding/Removing Voting Disk using: crsctl################################

--Adding Voting Diskscrsctl add css votedisk path

-Removing Voting Diskscrsctl delete css votedisk path

--P.S.--You can dynamically add and remove voting disks after installing Oracle RAC.--If your cluster is down, then you can use the -force option to--modify the voting disk configuration when using either of these--commands without interacting with active Oracle Clusterware--daemons. However, you may corrupt your cluster configuration if--you use the -force option while a cluster node is active.

#################################################################                 O R A C L E  C L U S T E R  R E G I S T R Y################################################################

--Oracle RAC environments do not support--more than two OCRs, a primary OCR and a secondary OCR.

#####################################Viewing Available OCR and Backups####################################

Page 233: 11gR2 ASMCMD Commands

--Show the availability of Primary and Secondary OCR filesocrcheck

--Show the availability of backup copiesocrconfig -showbackup

#################################Backup / Restore OCR File################################

--------------##Backup OCR----------------Oracle Clusterware automatically creates OCR backups every 4 hours.--The default location for generating backups on Red Hat Linux--systems is CRS_home/cdata/cluster_name

--Export the dump file of OCR[root]# ocrconfig -export backup_file_name

--Check the status of the OCR:ocrcheck

--P.S.--If this command does not display the message 'Device/File integrity check succeeded'-- for at least one copy of the OCR, then both the primary OCR and the-- OCR mirror have failed. You must restore the OCR from a backup.

-------------------------------------------##Restore OCR using automated Backup file---------------------------------------------1. list the available backup files[root]# ocrconfig -showbackup

--2. Review the contents of the backup using ocrdump command, where--file_name is the name of the OCR backup file:[root]# ocrdump -backupfile file_name

--3. As the root user, stop Oracle Clusterware on all the nodes in your Oracle RAC cluster--Repeat this command on each node in your Oracle RAC cluster![root]# crsctl stop crs

--4. As the root user, restore the OCR by applying an OCR backup file that you--identified in Step 1[root]# ocrconfig -restore file_name

Page 234: 11gR2 ASMCMD Commands

--5. Restart Oracle Clusterware on all the nodes in your cluster by--restarting each node, or by running the following command:[root]# crsctl start crs

--6. Use the Cluster Verification Utility (CVU) to verify the OCR integrity. Run the--following command, where the -n all argument retrieves a list of all the cluster--nodes that are configured as part of your cluster:[root]# cluvfy comp ocr -n all [-verbose]

-------------------------------------------##Restore OCR using Export file---------------------------------------------1. As the root user, stop Oracle Clusterware on all the nodes in your Oracle RAC cluster--Repeat this command on each node in your Oracle RAC cluster![root]# crsctl stop crs

--2. As the root user, restore the OCR data by importing the contents of the OCR export file[root]# ocrconfig -import file_name

--3. Restart Oracle Clusterware on all the nodes in your cluster by--restarting each node, or by running the following command:[root]# crsctl start crs

--4. se the Cluster Verification Utility (CVU) to verify the OCR integrity. Run the--following command, where the -n all argument retrieves a list of all the cluster--nodes that are configured as part of your cluster:[root]# cluvfy comp ocr -n all [-verbose]

################################################# To add a primary or secondary OCR location################################################

--1. Use the following command to verify that Oracle Clusterware is running on the--node on which the you are going to perform the replace operation:crsctl check crs

--2. Run the following command as root using either destination_file or disk to--designate the target location of the primary OCR:ocrconfig -replace ocr destination_fileocrconfig -replace ocr disk

--3. Run the following command as root using either destination_file or disk to--designate the target location of the secondary OCR:ocrconfig -replace ocrmirror destination_fileocrconfig -replace ocrmirror disk

Page 235: 11gR2 ASMCMD Commands

--4. If any node that is part of your current Oracle RAC cluster is shut down, then run--the following command on the stopped node to let that node rejoin the cluster--after the node is restarted:ocrconfig -repair ocr [device_name]

######################### Removing an OCR########################

--To remove an OCR location, at least one OCR must be online. You can remove an OCR--location to reduce OCR-related overhead or to stop mirroring your OCR because you--moved the OCR to a redundant storage system, such as a redundant array of--independent disks (RAID).--To remove an OCR location from your Oracle RAC cluster:

--1. Use the OCRCHECK utility to ensure that at least one OCR other than the OCR--that you are removing is online.ocrcheck

--2. Run the following command on any node in the cluster to remove one copy of the OCR:ocrconfig -replace ocr

################################################################# How to install and setup ASMLib packages################################################################

###### List of Platform depenfent but Kernel independent packages ###### oracleasm-support-2.1.3-1.<distro>.x86_64.rpm oracleasmlib-2.0.4-1.<distro>.x86_64.rpm

###### List of Platform and Kernel dependent packages ###### oracleasm-2.6.16.46-0.12-smp-2.0.3-1.x86_64.rpm oracleasm-2.6.16.46-0.12-default-2.0.3-1.x86_64.rpm

-- Install the packages using the command rpm –ivh on all the nodes

###### ASMLib Configuration (to repeat on all nodes of the cluster)  ###### [root@lrh-node1 /]# /etc/init.d/oracleasm configureConfiguring the Oracle ASM library driver.

This will configure the on-boot properties of the Oracle ASM librarydriver. The following questions will determine whether the driver isloaded on boot and what permissions it will have. The current values

Page 236: 11gR2 ASMCMD Commands

will be shown in brackets ('[]'). Hitting without typing ananswer will keep that current value. Ctrl-C will abort.

Default user to own the driver interface []: gridDefault group to own the driver interface []: asmdbaStart Oracle ASM library driver on boot (y/n) [n]: yFix permissions of Oracle ASM disks on boot (y/n) [y]: yWriting Oracle ASM library driver configuration [ OK ]Creating /dev/oracleasm mount point [ OK ]Loading module "oracleasm" [ OK ]Mounting ASMlib driver filesystem [ OK ]Scanning system for ASM disks [ OK ]

###### Create disk partitions and  ASM disks (from one of the nodes of the cluster) ###### -- Having a list of devices dedicated to ASM create one primary partition per disk or LUN using fdisk -- command and than use ASMLib utility to implement one ASM Disk per device.

lrh-node1:/u01 # fdisk -l /dev/sdh  Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1        4700    37747712   83  Linuxlrh-node1:/u01 # fdisk -l /dev/sdi Disk /dev/sdi: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdi1               1        4700    37747712   83  Linuxlrh-node1:/u01 # fdisk -l /dev/sdj Disk /dev/sdj: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdj1               1        4699    37744686   83  Linuxlrh-node1:/u01 # lrh-node1:/u01 # fdisk /dev/sdh  The number of cylinders for this disk is set to 4699.

Page 237: 11gR2 ASMCMD Commands

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) Command (m for help): dSelected partition 1 Command (m for help): p Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System Command (m for help): nCommand action   e   extended   p   primary partition (1-4)p  Partition number (1-4): 1First cylinder (1-4699, default 1): 1Last cylinder or +size or +sizeM or +sizeK (1-4699, default 4699): +1024M Command (m for help): p Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1         125     1004031   83  Linux Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (126-4699, default 126): Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-4699, default 4699): Using default value 4699 Command (m for help): p 

Page 238: 11gR2 ASMCMD Commands

Disk /dev/sdh: 38.6 GB, 38654705664 bytes255 heads, 63 sectors/track, 4699 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id  System/dev/sdh1               1         125     1004031   83  Linux/dev/sdh2             126        4699    36740655   83  Linux Command (m for help): wThe partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.lrh-node1:/u01 #partprobe

######  Once the disks have been sliced the ASM Disks can be created ###### lrh-node1:/u01 # /etc/init.d/oracleasm Usage: /etc/init.d/oracleasm {start|stop|restart|enable|disable|configure|createdisk|deletedisk|querydisk|listdisks|scandisks|status}lrh-node1:/u01 # /etc/init.d/oracleasm createdisk OCR1 /dev/sdh1Marking disk "/dev/sdh1" as an ASM disk:                              donelrh-node1:/u01 # /etc/init.d/oracleasm createdisk DATA1 /dev/sdh2Marking disk "/dev/sdh2" as an ASM disk:                              donelrh-node1:/u01 # /etc/init.d/oracleasm scandisksScanning system for ASM disks:                                           donelrh-node1:/u01 #

--  After having created all the ASM Disks runs the utility scandisks  on all nodes of the cluster, --  this allows ASM to discover all the new ASM Disks created.

lrh-node2:/dev/oracleasm/disks # /etc/init.d/oracleasm scandisksScanning system for ASM disks:                                          donelrh-node2:/dev/oracleasm/disks # /etc/init.d/oracleasm listdisksDATA1DATA2DATA3OCR1OCR2OCR3

######  ASM diskstring and diskgroup parameters ######  *.asm_diskstring='ORCL:*'*.asm_diskgroups='OCR_VOT','DATA1','FRA1'

Page 239: 11gR2 ASMCMD Commands

################################################################# M A N A G E   O R A C L E  R A C   D A T A B A S E   U S I N G   SRVCLT################################################################

########################## Display the Current Policy#########################

--The following command display the current status of the databasesrvctl config database -d <db_name>  -a

################################### Change the Current Policy to Another Policy##################################

--Use the following SRVCTL command to change the policy srvctl modify database -d <db_name>  -y policy_name

################################################################# Other SRVCTL and SERVICES Management################################################################

##Ho to obtain the Statuses of Services with SRVCTL--The following command returns the status of the service running on the database:srvctl status service -d <db_name> -s <service_name>

##How to Start and Stop Services with SRVCTL--Enter the following SRVCTL syntax from the command line:srvctl start service -d database_unique_name [-s service_name_list] [-i inst_name][-o start_options]srvctl stop service -d database_unique_name -s service_name_list [-i inst_name][-o start_options]

### Remove and Add Database and Instance to the CRSsrvctl remove database -d <db_name> srvctl add database -d <db_name>  -o $ORACLE_HOMEsrvctl add instance -d <db_name>  -i <instance_name> -n <hostname>

##Add service to a database with preferred instance  RAC01srvctl add service -d <db_name>  -s <service_name> -r RAC1 -a RAC2, RAC3

Page 240: 11gR2 ASMCMD Commands

##Enabling and Disabling Services with SRVCTL--Use the following SRVCTL syntax from the command line to enable and disable services:srvctl enable service -d <db_name>  -s <service_name>  [-i inst_name]srvctl disable service -d <db_name>  -s <service_name>  [-i inst_name]

## How to relocate service from instance 1 to instance 3:srvctl relocate service -d <db_name>  -s <service_name> -i instance1 -t instace3

--Stop/Sart Listener srvctl stop listener -n <hostname>  [-l listener_name]  --Stop/Start Instance srvctl start instance -d <db_name>  -i <instance_name> 

############################################################################  How to establish remote connection to a database in restricted or NO MOUNT mode############################################################################

Connections via listener to an instance that is in RESTRICTED status or in NO MOUNT status fail withTNS-12526, TNS-12527 or TNS-12528 even when supplying the credentials for a privileged account.     The lsnrctl services output will show that the service handler for this instance is in state: BLOCKED or RESTRICTED.

 DBTEST_PRIV =     (DESCRIPTION =       (ADDRESS_LIST =            (ADDRESS = (PROTOCOL = TCP)(HOST = rm01it.emilianofusaglia.net)(PORT = 1522)))

      (CONNECT_DATA =            (UR=A)            (SERVICE_NAME = dbtest.emilianofusaglia.net)         )       )   

Page 241: 11gR2 ASMCMD Commands

 Note that the (UR=A) clause is intended to work with a dynamically registered handler  so the use of SERVICE_NAME versus SID is preferred.  SID may connect to a statically configured handler.

 #############################################################        ########### Duplicate database on 11g from active database  #######################################################################

-- Source database     = TRAC-- Duplicate database = TDUP10

################################ PREREQUISITES for Cloning##############################

## Create the diag structuremkdir -p <diag_directory_DB_Name>

## Generate the PFILE from the Original DB and copy to the target host:alter system create pfile'/tmp/pfile.ora' from spfile;scp /tmp/pfile.ora lclus01:/tmp

## Adjust the following pfile parameters:DB_NAMELOG_FILE_NAME_CONVERTDB_FILE_NAME_CONVERTDB_CREATE_FILE_DEST

##Statup nomount and create the spfile:alter system create spfile='+DATA/TDUP10/spfile_TDUP10.ora' from pfile'/tmp/pfile.ora';

#############################################################

##############################Network Configuration ##############################

##Listener Static Entry:SID_LIST_LISTENER =   (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.2.0.1)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = TDUP10.emilianofusaglia.net)

Page 242: 11gR2 ASMCMD Commands

      (ORACLE_HOME = /u01/oracle/product/11.2.0.1)      (sid_name = TDUP11)    )  )

##TNS entryTDUP10.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = loraclu-scan.emilianofusaglia.net)(PORT = 1526))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = TDUP10.emilianofusaglia.net)    )  )

#############################################################

################################RMAN Duplicate##############################

#rmanconnect target /connect auxiliary sys/[email protected] target database    to TDUP10    from active database    DB_FILE_NAME_CONVERT 'TRAC','TDUP10'    skip tablespace POR_READONLY;

##Register the database into the Grid Infrastructuresrvctl add database -d TDUP10 -o $ORACLE_HOME srvctl add instance -d TDUP10 -i TDUP11 -n lclus01srvctl add instance -d TDUP10 -i TDUP12 -n lclus02

##Create the password file on each node using the utility orapwd.#cd $ORACLE_HOME/dbs#orapwd file=<password_file_name> password=<sys_password> entries=n

## Add oratab entry<DB_NAME>:<ORACLE_HOME>:N

 ########################################################################### How to implement Oracle Resource Manager granting the CONSUMER GROUPS to Clusterware services ###########################################################################

Page 243: 11gR2 ASMCMD Commands

--Create a service for OLTP sessionssrvctl add service -d dbrac10 -s DBRAC10_OLTP -r dbrac11,dbrac12,dbrac13srvctl start service -d dbrac10 -s DBRAC10_OLTP

--Create a service for BATCH sessionssrvctl add service -d dbrac10 -s DBRAC10_BATCH -r dbrac11,dbrac12,dbrac13srvctl start service -d dbrac10 -s DBRAC10_BATCH

##################################################################### Resource Plan Design:## MGMT_P1=75% SYS_GROUP,  MGMT_P2=80% OLTP, MGMT_P2=10% BATCH, MGMT_P2=5% ## ORA$AUTOTASK_SUB_PLAN,  MGMT_P2=5% ORA$DIAGNOSTICS, MGMT_P3=70% OTHER_GROUPS            ###################################################################       

## Resource Plan Implementation:BEGINDBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'REAL_TIME_PLAN', COMMENT => 'Respurce Plan for OLTP database');DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP (CONSUMER_GROUP => 'OLTP',CATEGORY => 'INTERACTIVE', COMMENT => 'OLTP sessions');DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP (CONSUMER_GROUP => 'BATCH', CATEGORY => 'BATCH', COMMENT => 'BATCH sessions');DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN', GROUP_OR_SUBPLAN => 'OLTP', COMMENT => 'OLTP group', MGMT_P2 => 80);DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN', GROUP_OR_SUBPLAN => 'BATCH', COMMENT => 'BATCH group',MGMT_P3 => 70, PARALLEL_DEGREE_LIMIT_P1 => 6, ACTIVE_SESS_POOL_P1 => 4, MAX_IDLE_TIME => 240);DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN', GROUP_OR_SUBPLAN => 'SYS_GROUP', COMMENT => 'SYS group', MGMT_P1 => 70);DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'OTHER group', MGMT_P4 => 50);DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN',GROUP_OR_SUBPLAN => 'ORA$AUTOTASK_SUB_PLAN', COMMENT => 'ORA$AUTOTASK_SUB_PLAN group', MGMT_P3 => 20);DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (PLAN => 'REAL_TIME_PLAN', GROUP_OR_SUBPLAN => 'ORA$DIAGNOSTICS', COMMENT => 'ORA$DIAGNOSTICS group', MGMT_P3 => 10);DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING (DBMS_RESOURCE_MANAGER.SERVICE_NAME, 'DBRAC10_OLTP', 'OLTP'); DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING(DBMS_RESOURCE_MANAGER.SERVICE_NAME, 'DBRAC10_BATCH', 'BATCH');DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();

Page 244: 11gR2 ASMCMD Commands

DBMS_RESOURCE_MANAGER.CLEAR_PENDING_AREA();END;/

###################################################################

## Grant the Switch to the UsersBEGINDBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();    dbms_resource_manager_privs.grant_switch_consumer_group ('PERF_TEST','OLTP',FALSE);  dbms_resource_manager_privs.grant_switch_consumer_group ('PERF_TEST','BATCH',FALSE);  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();DBMS_RESOURCE_MANAGER.CLEAR_PENDING_AREA();END;/

###################################################################        ## Enable the Resource plan with the FORCE Option to avoid the Scheduler window to ## activate a different plan during the job execution.ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'FORCE:REAL_TIME_PLAN';###################################################################       

## Example of Group and Plan Deletion:

BEGINDBMS_RESOURCE_MANAGER.DELETE_PLAN (PLAN => 'REAL_TIME_PLAN');END;/

BEGINDBMS_RESOURCE_MANAGER.DELETE_CONSUMER_GROUP(CONSUMER_GROUP => 'OLTP');END;/

BEGINDBMS_RESOURCE_MANAGER.DELETE_CONSUMER_GROUP(CONSUMER_GROUP => 'BATCH');END;/

##################################################################### SQL Queries for monitoring Resource Manager  utilization:###################################################################

Page 245: 11gR2 ASMCMD Commands

## Check the service name used by each sessionselect inst_id, username, SERVICE_NAME, count(*) from gv$session where SERVICE_NAME <>'SYS$BACKGROUND' group by inst_id, username, SERVICE_NAME order by  order by 2,3,1;

## List the Active Resource Consumer Groups:select INST_ID, NAME, ACTIVE_SESSIONS, EXECUTION_WAITERS, REQUESTS, CPU_WAIT_TIME, CPU_WAITS, CONSUMED_CPU_TIME, YIELDS, QUEUE_LENGTH, ACTIVE_SESSION_LIMIT_HIT from gV$RSRC_CONSUMER_GROUP where name in ('SYS_GROUP','BATCH','OLTP','OTHER_GROUPS') order by 2,1;

#############################################################                    How to implement Oracle Instance Caging  ###########################################################

Instance Caging allows to dynamically limit the amount of CPUs used by each database instance.  This option is specifically thought for shared environments where the database administrator has to guarantee resources to all the instances running on the same hardware.

-- Enable Resource Manager:

ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'REAL_TIME_PLAN';

--or

ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'FORCE:REAL_TIME_PLAN';

FORCE option prevents that the scheduler window activates a different plan during the job execution.

(for more info about Resource Manager visit ResourceManager)

-- Enable Instance Caging:

ALTER SYSTEM SET CPU_COUNT=4 SCOPE=BOTH SID='*';

#############################################################                    Instance Caging Test###########################################################

Page 246: 11gR2 ASMCMD Commands

Hardware SUN 8 Cores 64 ThreadsOne test database capped to 16 CPU - 25% of total hardware capacity.

ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'default_plan';ALTER SYSTEM SET cpu_count=16 scope=both sid='*';

The load generator opens 70 sessions producing intencive CPU activity, which as shown by the reports belowdo not exceed the 25% od the total server capacity (%Usr column).

     Core Utilization for Integer pipelineCore,Int-pipe    %Usr     %Sys   %Usr+Sys-------------        ------     ------    --------     0,0              21.92      3.99     25.91     0,1              24.58      2.08     26.66     1,0              23.16      2.27     25.43     1,1              24.06      2.64     26.71     2,0              22.73      3.03     25.76     2,1              23.47      3.02     26.49     3,0              23.56      2.86     26.42     3,1              24.71      2.87     27.58     4,0              23.53      2.07     25.60     4,1              24.87      2.92     26.79     5,0              24.98      2.87     27.85     5,1              24.76      3.81     28.57     6,0              23.53      4.11     27.64     6,1              23.99      3.14     27.13     7,0              24.72      3.55     28.26     7,1              22.62      3.59     26.21-------------       ------      ------    ------    Avg             22.36       3.05     25.41

If on the Wait Events is present "resmgr:cpu quantum", it means that Instance Caging throttled the amount of CPUs available to the system.

INST_ID  SID      SQL_ADDR                       EVENT           WAIT_CLASS              STATE                 WAIT_MICRO    REMAING   TOT_TIME  LAST_WAIT-------       ------      ----------------               ------------------------------ ---------------                     ------------------                     ----------            ----------          ----------        ----------      1       676      000000047ECC5BD0   resmgr:cpu quantum     Scheduler       WAITED KNOWN TIME       11599                     11599      43834      2       624      000000047D7D38D0    resmgr:cpu quantum     Scheduler       WAITED KNOWN TIME       11599                11599      43834      2       395      000000047BCA97A8   resmgr:cpu quantum     Scheduler       WAITING                            11669                     -1         11668          0      1       300      000000047C8D6B38    resmgr:cpu quantum     Scheduler       WAITED KNOWN TIME       11677                                 11677        589      2       317      00                                 resmgr:cpu quantum     Scheduler       WAITED KNOWN TIME       11677                                  11677        589      1       649      000000047ECC5BD0   resmgr:cpu quantum     Scheduler       WAITING                            14445                     -1          14444          0      2       676      000000047D7D38D0    resmgr:cpu quantum     Scheduler       WAITING                            14445                     -1          14444          0      1       148      000000047C8D6B38    resmgr:cpu quantum     Scheduler       WAITING                             14827                     -1          14826          0      2     1413      000000047D7D36E0    resmgr:cpu quantum      Scheduler       WAITED KNOWN TIME      

Page 247: 11gR2 ASMCMD Commands

18824                                  18824      98023      1      148      000000047ECC4010     resmgr:cpu quantum      Scheduler       WAITED KNOWN TIME       18824                                  18824      98023      1       149     000000047C8D6B38    resmgr:cpu quantum       Scheduler       WAITING                             19122                     -1          19121          0      1        69      000000047C8D6B38    resmgr:cpu quantum       Scheduler       WAITING                             19177                     -1          19176          0      2        51      000000047BCA97A8   resmgr:cpu quantum        Scheduler       WAITING                             19177                     -1           19176          0      2     1106     000000047BCA97A8   PX Deq: Signal ACK RSG    Other        WAITING                              112660                  7340         120000          0

##################################################################                        RMAN Setup, Backup and Restore Test                               ################################################################

--Basic tips for Disk & Tape Backup/Recovery strategy.

--To be able to efficiently perform incremental backup check if "Change Block Tracking" is enable:SELECT * FROM V$BLOCK_CHANGE_TRACKING;

--If it doesn't exist create it:alter database enable block change tracking using file '+FRA1';

############################ RMAN Format Description ###########################

%a Current database activation id

%A Zero-filled activation ID

%c The copy number of the backup piece within a set of duplexed backup pieces.bMaximum value is 256

%d Database name

%D Current day of the month from the Gregorian calendar in format DD

%e Archived log sequence number

%f Absolute file number

%F Combines the DBID, day, month, year, and sequence into a unique and repeatable generated name

Page 248: 11gR2 ASMCMD Commands

%h Archived redo log thread number

%I DBID

%M Month in the Gregorian calendar in the format MM

%n Database name, padded on the right with x characters to a total length of eight characters

%N Tablespace name. Only valid when backing up datafiles as image copies.

%p Piece number within the backup set. This value starts at 1 for each backup set and is incremented by 1  for each backup piece created. If a PROXY is specified, the %p variable must be included in the FORMAT  string either explicitly or implicitly within %U.

%r Resetlogs ID

%s Backup set number. This number is a counter in the control file that is incremented for each backup set.  The counter value starts at 1 and is unique for the lifetime of the control file. If you restore a backup  control file, then duplicate values can result. CREATE CONTROLFILE initializes the counter at 1.

%S Zero-filled sequence number

%t Backup set time stamp, a 4-byte value derived as the number of seconds elapsed since a fixed reference time.    The combination of %s and %t can be used to form a unique name for the backup set.

%T Year, month, and day in the Gregorian calendar in the format: YYYYMMDD

%u An 8-character name constituted by compressed representations of the backup set or image copy number and the    time the backup set or image copy was created

%U A system-generated unique filename (default). %U is different for image copies and backup pieces.    For a backup piece, %U is a shorthend for %u_%p_%c and guarantees uniqueness in generated backup filenames.    For an image copy of a datafile, %U means the following: data-D-%d_id-%I_TS-%N_FNO-%f_%u   %Y Year in this format: YYYY

%% Percent (%) character. For example, %%Y translates to the string %Y

Page 249: 11gR2 ASMCMD Commands

################################################################

####################### RMAN STEUP#####################

connect target /connect catalog  usr_catalog/xxxxxx@RMAN_Catalog.emilianofusaglia.net

REGISTER DATABASE;

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;CONFIGURE BACKUP OPTIMIZATION ON;CONFIGURE DEFAULT DEVICE TYPE TO 'SBT_TAPE';CONFIGURE CONTROLFILE AUTOBACKUP ON;CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '+FRA1/%F';CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET;CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' RATE 200M PARMS 'ENV=(NB_ORA_POLICY=ora_monthly)' FORMAT 'backup_%d_%T_%U';CONFIGURE CHANNEL DEVICE TYPE DISK RATE 200M FORMAT '+BACKUP/%d_%T_%U';CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO 'SBT_TAPE';CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+FRA1/snapcf_dbrm07.cf';

--Full Database backupBACKUP INCREMENTAL LEVEL = 0 DATABASE PLUS ARCHIVELOG NOT BACKED UP 1 TIMES;

--Incremental Database backupBACKUP INCREMENTAL LEVEL = 1 DATABASE PLUS ARCHIVELOG NOT BACKED UP 1 TIMES;

--RMAN Catalog Maintenance and Backup ValidationSHOW ALL;run{ALLOCATE CHANNEL disk1 DEVICE TYPE DISK;allocate channel tape1 type 'SBT_TAPE' PARMS 'ENV=(NB_ORA_CLIENT=lxrm01.emilianofusaglia.net)';crosscheck backup completed before "sysdate-30";delete noprompt expired backup;delete noprompt obsolete;}

--Rman basic Backup ReportSHOW all;list backup summary;

Page 250: 11gR2 ASMCMD Commands

##################################################################                                        RESTORE TESTS                                         ################################################################

--Restore Datafile from TAPE

SQL> startup mountORACLE instance started.

Total System Global Area 4277059584 bytesFixed Size                  2154936 bytesVariable Size            2499812936 bytesDatabase Buffers         1728053248 bytesRedo Buffers               47038464 bytesDatabase mounted.SQL> SQL> SQL> select * from v$recover_file;

     FILE# ONLINE  ONLINE_  ERROR                       CHANGE#    TIME---------- ------- -------  -------------------------- ----------  --------         9 ONLINE  ONLINE   FILE NOT FOUND                     0

RMAN> connect target /

connected to target database: DBRM07 (DBID=3653795552, not open)

RMAN> connect catalog  usr_catalog/xxxxxx@RMAN_Catalog.emilianofusaglia.net

connected to recovery catalog database

RMAN> restore datafile 9;

Starting restore at 07.04.11starting full resync of recovery catalogfull resync completeallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=1393 instance=DBRM071 device type=DISKallocated channel: ORA_DISK_2channel ORA_DISK_2: SID=1422 instance=DBRM071 device type=DISKallocated channel: ORA_DISK_3

Page 251: 11gR2 ASMCMD Commands

channel ORA_DISK_3: SID=1451 instance=DBRM071 device type=DISKallocated channel: ORA_DISK_4channel ORA_DISK_4: SID=1480 instance=DBRM071 device type=DISKallocated channel: ORA_DISK_5channel ORA_DISK_5: SID=1509 instance=DBRM071 device type=DISKallocated channel: ORA_SBT_TAPE_1channel ORA_SBT_TAPE_1: SID=1538 instance=DBRM071 device type=SBT_TAPEchannel ORA_SBT_TAPE_1: Veritas NetBackup for Oracle - Release 6.5 (2010120208)

channel ORA_SBT_TAPE_1: starting datafile backup set restorechannel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup setchannel ORA_SBT_TAPE_1: restoring datafile 00009 to +DATA1/dbtr07/datafile/indxtbs.562.717369571channel ORA_SBT_TAPE_1: reading from backup piece 13ld31mb_1_2channel ORA_SBT_TAPE_1: piece handle=13ld30mb_1_2 tag=TAG20110406T121258channel ORA_SBT_TAPE_1: restored backup piece 1channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:04:16Finished restore at 07.04.11starting full resync of recovery catalogfull resync complete

RMAN> recover datafile 9;

Starting recover at 07.04.11using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4using channel ORA_DISK_5using channel ORA_SBT_TAPE_1channel ORA_SBT_TAPE_1: starting incremental datafile backup set restorechannel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup setdestination for restore of datafile 00009: +DATA1/dbtr07/datafile/indxtbs.562.717369571channel ORA_SBT_TAPE_1: reading from backup piece 1eld30qo_1_2channel ORA_SBT_TAPE_1: piece handle=1eld30qo_1_2 tag=TAG20110406T121520channel ORA_SBT_TAPE_1: restored backup piece 1channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:04:25

starting media recovery

archived log for thread 1 with sequence 162 is already on disk as file +FRA1/dbtr07/archivelog/2011_04_06/thread_1_seq_162.16655.718385527archived log for thread 1 with sequence 163 is already on disk as file +FRA1/dbtr07/archivelog/2011_04_06/thread_1_seq_163.8452.718385527archived log for thread 2 with sequence 141 is already on disk as file +FRA1/dbtr07/archivelog/2011_04_06/thread_2_seq_141.4677.718385531archived log for thread 3 with sequence 132 is already on disk as file +FRA1/dbtr07/archivelog/2011_04_06/thread_3_seq_132.5466.718385525

Page 252: 11gR2 ASMCMD Commands

archived log for thread 3 with sequence 133 is already on disk as file +FRA1/dbtr07/archivelog/2011_04_06/thread_3_seq_133.1479.718385525channel ORA_SBT_TAPE_1: starting archived log restore to default destinationchannel ORA_SBT_TAPE_1: restoring archived logarchived log thread=3 sequence=131channel ORA_SBT_TAPE_1: reading from backup piece 1hld30r8_1_2channel ORA_SBT_TAPE_1: piece handle=1hld30r8_1_2 tag=TAG20100507T121535channel ORA_SBT_TAPE_1: restored backup piece 1channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:02:15archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_3_seq_131.16592.718387087 thread=3 sequence=131channel ORA_SBT_TAPE_1: starting archived log restore to default destinationchannel ORA_SBT_TAPE_1: restoring archived logarchived log thread=1 sequence=161channel ORA_SBT_TAPE_1: reading from backup piece 1ild30r8_1_2channel ORA_SBT_TAPE_1: piece handle=1ild30r8_1_2 tag=TAG20100507T121535channel ORA_SBT_TAPE_1: restored backup piece 1channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:01:58archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_1_seq_161.13854.718387211 thread=1 sequence=161channel ORA_SBT_TAPE_1: starting archived log restore to default destinationchannel ORA_SBT_TAPE_1: restoring archived logarchived log thread=2 sequence=140channel ORA_SBT_TAPE_1: reading from backup piece 1jld30r8_1_2channel ORA_SBT_TAPE_1: piece handle=1jld30r8_1_2 tag=TAG20100507T121535channel ORA_SBT_TAPE_1: restored backup piece 1channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:01:55archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_2_seq_140.1819.718387319 thread=2 sequence=140channel default: deleting archived log(s)archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_1_seq_161.13854.718387211 RECID=824 STAMP=718387211channel default: deleting archived log(s)archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_2_seq_140.1819.718387319 RECID=825 STAMP=718387319channel default: deleting archived log(s)archived log file name=+FRA1/dbtr07/archivelog/2011_04_06/thread_3_seq_131.16592.718387087 RECID=823 STAMP=718387086media recovery complete, elapsed time: 00:00:02Finished recover at 07.04.11 

Page 253: 11gR2 ASMCMD Commands

   

Data Guard Architecture

Below an example of Active Data Guard architecture diagram based on 11g R2, where primary and physical standby are running in RAC.

Page 254: 11gR2 ASMCMD Commands
Page 255: 11gR2 ASMCMD Commands

############################################################## DATA GUARD IMPLEMENTATION on 11g R1 RAC ##############################################################

--Primary DB: USA10--Standby DB: EURO10

############################--From the Primary Database:alter database force logging;

alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;

select * from v$standby_log;

 alter system set parallel_execution_message_size=8192 scope=spfile; alter system set fast_start_mttr_target=3600; ############################--From the Standby Site:

--Dump the pfile and change the following parameters for the Standby:*.control_files='+DATA1/EURO10/CONTROLFILE/CURRENT01.CTR','+FRA1/EURO10/CONTROLFILE/CURRENT02.CTR'*.db_file_name_convert='/USA10/','/EURO10/'*.log_file_name_convert='/USA10/','/EURO10/'*.db_unique_name='EURO10'--AS this is a single instance RAC_disable_interface_checking = TRUE

LISTENER =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01.emilianofusaglia.net)(PORT = 1526))  )

alter system set local_listener='LISTENER' scope=spfile sid='EURO11';---

Page 256: 11gR2 ASMCMD Commands

mkdir -p /u01/oracle/admin/EURO10/adumpmkdir -p /u01/oracle/diag/rdbms/euro10/EURO11/cdump

###################################################################### ################## #Network Congiguration ##############################################################################################

############################################ Static Listener Entries:##########################################

--Primary Cluster Node 1SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )  )

--Primary Cluster Node 2SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)

Page 257: 11gR2 ASMCMD Commands

    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )  )

--Primary Cluster Node 3SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )  )

--Standby Cluster Node 1SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)

Page 258: 11gR2 ASMCMD Commands

      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = EURO10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )    (SID_DESC =      (global_dbname = EURO10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )    (SID_DESC =      (global_dbname = EURO10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )  )

############################################TNS Entries Primary & Standby Cluster##########################################EURO11.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01-vip.emilianofusaglia.net)(PORT = 1526))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = EURO10.emilianofusaglia.net)      (INSTANCE_NAME = EURO11)    )  )

EURO10.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01-vip.emilianofusaglia.net)(PORT = 1526))      (FAILOVER = on)      (LOAD_BALANCE = on)    )    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = EURO10.emilianofusaglia.net)    )  )

Page 259: 11gR2 ASMCMD Commands

USA10.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan01-vip.emilianofusaglia.net)(PORT = 1526))      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan02-vip.emilianofusaglia.net)(PORT = 1526))      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan03-vip.emilianofusaglia.net)(PORT = 1526))      (FAILOVER = on)      (LOAD_BALANCE = on)    )    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = USA10.emilianofusaglia.net)    )  )

############################################ Standby Controlfile Setup ############################################

alter database create standby controlfile as '/u01/oracle/emiliano/USA10.stby.ctl';

# scp  /u01/oracle/emiliano/USA10.stby.ctl lneuron01:/tmp

### Execute the following steps:Startup nomount pfile='/u01/oracle/emiliano/PFILES/EURO10_for_GD.ora';Create the spfile on ASMStartup nomount exclusive;

## Do not RESTORE the Controlfile automatically DONE by the CLONE Procedure## Which update also Contro_file parameter into SPFIE!!!!rman target /RMAN> restore controlfile from '/u01/oracle/emiliano/USA10.stby.ctl';

---############################################ Duplicate the Database##########################################

##From Primary DB Restore the DB to the Standby Side:rman connect target sys/xxxxxxx@USA10                             ----PS No domain for Target

Page 260: 11gR2 ASMCMD Commands

connect auxiliary sys/[email protected]      ----PS Use domain for Auxiliary

run {   allocate channel p1 type disk;   allocate auxiliary channel s1 type disk;   duplicate target database for standby from active database   dorecover;    }

--or

run {   allocate channel p1 type disk;   allocate channel p2 type disk;   allocate channel p3 type disk;   allocate channel p4 type disk;   allocate auxiliary channel s1 type disk;   allocate auxiliary channel s2 type disk;   allocate auxiliary channel s3 type disk;   allocate auxiliary channel s4 type disk;   duplicate target database for standby from active database   dorecover;    }

############################################ Register the Standby Database to CRS##########################################

srvctl add database -d EURO10 -o $ORACLE_HOMEsrvctl add instance -d EURO10 -i EURO11 -n lneuron01

############################################ Data Guard Broker Configuration##########################################

--Primaryalter system set dg_broker_config_file1 = '+DATA1/USA10/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 = '+DATA1/USA10/DATAGUARDCONFIG/brokerconfig02.dat';

--Standbyalter system set dg_broker_config_file1 = '+DATA1/EURO10/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 = '+DATA1/EURO10/DATAGUARDCONFIG/brokerconfig02.dat';

Page 261: 11gR2 ASMCMD Commands

--on both databasesalter system set dg_broker_start=true;

--From a primary node connect to the broker and create the configuration

#dgmgrl

DGMGRL> connect sys/[email protected].

create configuration 'CONFDG10' as primary database is 'USA10' connect identifier is USA10.emilianofusaglia.net;    add database 'EURO10' as connect identifier is EURO10.emilianofusaglia.net;

edit database 'USA10' set property 'LogXptMode' = 'SYNC';edit database 'EURO10' set property 'LogXptMode' = 'SYNC';

edit database 'USA10' set property 'LogXptMode' = 'ASYNC';edit database 'EURO10' set property 'LogXptMode' = 'ASYNC';

--edit configuration set protection mode as maxavailability;edit configuration set protection mode as maxprotection;--edit configuration set protection mode as maxavailability;--edit configuration set protection mode as maxperformance;enable configuration;

edit database 'USA10' set property 'NetTimeout' = '20';edit database 'EURO10' set property 'NetTimeout' = '20';

exit;

DGMGRL> SWITCHOVER to "EURO10";

--Stop Recoveryedit database 'EURO10' set state = 'APPLY-OFF';--Start Recoveryedit database 'EURO10' set state = 'APPLY-ON';

--Enabling ArchiveLog Tracing on Primary and Standby Good for Troubleshooting!!edit instance 'USA11' on database 'USA10' set property 'LogArchiveTrace' = '1';    edit instance 'USA12' on database 'USA10' set property 'LogArchiveTrace' = '1';    edit instance 'USA13' on database 'USA10' set property 'LogArchiveTrace' = '1';    

edit instance 'EURO11' on database 'EURO10' set property 'LogArchiveTrace' = '6345';    

##############################################################################

Page 262: 11gR2 ASMCMD Commands

#####################################################           How to configure DATA GUARD BROKER###################################################

# Create the data guard broker files

--Primaryalter system set dg_broker_config_file1 = '+DATA1/TEFOXTR/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 = '+FRA1/TEFOXTR/DATAGUARDCONFIG/brokerconfig02.dat';

--Standbyalter system set dg_broker_config_file1 = '+DATA1/TEFOXZH/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 = '+FRA1/TEFOXZH/DATAGUARDCONFIG/brokerconfig02.dat';

--Start the broker on both databasesalter system set dg_broker_start=true;

--From the primary database connect to the broker and create the configuration#dgmgrl

DGMGRL> connect sys/[email protected]

--Create the configuration for primary databasecreate configuration 'BRKTEFOX' as primary database is 'TEFOXTR' connect identifier is TEFOXTR_DGBHA.emilianofusaglia.net;

--Add standby databaseadd database 'TEFOXZH' as connect identifier is TEFOXZH_DGBHA.emilianofusaglia.net;

--Setup the propertiesedit database 'TEFOXTR' set property 'LogXptMode' = 'SYNC';edit database 'TEFOXZH' set property 'LogXptMode' = 'SYNC';--oredit database 'TEFOXTR' set property 'LogXptMode' = 'ASYNC';edit database 'TEFOXZH' set property 'LogXptMode' = 'ASYNC';

edit configuration set protection mode as maxprotection;--oredit configuration set protection mode as maxavailability;--oredit configuration set protection mode as maxperformance;

Page 263: 11gR2 ASMCMD Commands

edit database 'TEFOXTR' set property 'NetTimeout' = '20';edit database 'TEFOXZH' set property 'NetTimeout' = '20';

edit database 'TEFOXTR' set property 'Binding' = 'MANDATORY';edit database 'TEFOXZH' set property 'Binding' = 'MANDATORY';

enable configuration;

-- Switchover command:DGMGRL> SWITCHOVER to "TEFOXZH";

--Stop Recoveryedit database 'TEFOXZH' set state = 'APPLY-OFF';--Start Recoveryedit database 'TEFOXZH' set state = 'APPLY-ON';edit database 'TEFOXZH' set state = 'APPLY-ON' WITH APPLY INSTANCE ='TEFOXZH1';

--Enable ArchiveLog Tracing on Primary and Standby for Troubleshootingedit instance 'TEFOXTR1' on database 'TEFOXTR' set property 'LogArchiveTrace' = '1';    edit instance 'TEFOXZH1' on database 'TEFOXZH' set property 'LogArchiveTrace' = '6345';     

########################################################### How to display Oracle Cluster name#########################################################

Oracle Clusterware includes the utility cemutlo which provides cluster name and version.

[grid@lnxcld01 ~]$ cemutlo -hUsage: /GRID_INFRA/product/11.2.0.3/bin/cemutlo.bin [-n] [-w]        where:        -n prints the cluster name        -w prints the clusterware version in the following format:                 <major_version>:<minor_version>:<vendor_info>

--Cluster Name[grid@lnxcld01 ~]$ cemutlo -ncloud01

--Cluster Version[grid@lnxcld01 ~]$ cemutlo -w2:1:

 

Page 264: 11gR2 ASMCMD Commands

############################################################## DATA GUARD IMPLEMENTATION on 11g R1 RAC ##############################################################

--Primary DB: USA10--Standby DB: EURO10

############################--From the Primary Database:alter database force logging;

alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;alter database add standby logfile  size 1G;

select * from v$standby_log;

 alter system set parallel_execution_message_size=8192 scope=spfile; alter system set fast_start_mttr_target=3600; ############################--From the Standby Site:

--Dump the pfile and change the following parameters for the Standby:*.control_files='+DATA1/EURO10/CONTROLFILE/CURRENT01.CTR','+FRA1/EURO10/CONTROLFILE/CURRENT02.CTR'*.db_file_name_convert='/USA10/','/EURO10/'*.log_file_name_convert='/USA10/','/EURO10/'*.db_unique_name='EURO10'--AS this is a single instance RAC_disable_interface_checking = TRUE

LISTENER =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01.emilianofusaglia.net)(PORT = 1526))  )

Page 265: 11gR2 ASMCMD Commands

alter system set local_listener='LISTENER' scope=spfile sid='EURO11';---mkdir -p /u01/oracle/admin/EURO10/adumpmkdir -p /u01/oracle/diag/rdbms/euro10/EURO11/cdump

###################################################################### ################## #Network Congiguration ##############################################################################################

############################################ Static Listener Entries:##########################################

--Primary Cluster Node 1SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA11)    )  )

--Primary Cluster Node 2SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)

Page 266: 11gR2 ASMCMD Commands

      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA12)    )  )

--Primary Cluster Node 3SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = USA10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )    (SID_DESC =      (global_dbname = USA10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )    (SID_DESC =      (global_dbname = USA10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = USA13)    )  )

--Standby Cluster Node 1SID_LIST_LISTENER =  (SID_LIST =

Page 267: 11gR2 ASMCMD Commands

    (SID_DESC =      (SID_NAME = PLSExtProc)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (PROGRAM = extproc)    )    (SID_DESC =      (global_dbname = EURO10_DGMGRL.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )    (SID_DESC =      (global_dbname = EURO10_DGB.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )    (SID_DESC =      (global_dbname = EURO10.emilianofusaglia.net)      (ORACLE_HOME = /u01/oracle/product/11.1.0.7)      (sid_name = EURO11)    )  )

############################################TNS Entries Primary & Standby Cluster##########################################EURO11.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01-vip.emilianofusaglia.net)(PORT = 1526))    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = EURO10.emilianofusaglia.net)      (INSTANCE_NAME = EURO11)    )  )

EURO10.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = lneuron01-vip.emilianofusaglia.net)(PORT = 1526))      (FAILOVER = on)      (LOAD_BALANCE = on)    )    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = EURO10.emilianofusaglia.net)

Page 268: 11gR2 ASMCMD Commands

    )  )

USA10.emilianofusaglia.net =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan01-vip.emilianofusaglia.net)(PORT = 1526))      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan02-vip.emilianofusaglia.net)(PORT = 1526))      (ADDRESS = (PROTOCOL = TCP)(HOST = lnusan03-vip.emilianofusaglia.net)(PORT = 1526))      (FAILOVER = on)      (LOAD_BALANCE = on)    )    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = USA10.emilianofusaglia.net)    )  )

############################################ Standby Controlfile Setup ############################################

alter database create standby controlfile as '/u01/oracle/emiliano/USA10.stby.ctl';

# scp  /u01/oracle/emiliano/USA10.stby.ctl lneuron01:/tmp

### Execute the following steps:Startup nomount pfile='/u01/oracle/emiliano/PFILES/EURO10_for_GD.ora';Create the spfile on ASMStartup nomount exclusive;

## Do not RESTORE the Controlfile automatically DONE by the CLONE Procedure## Which update also Contro_file parameter into SPFIE!!!!rman target /RMAN> restore controlfile from '/u01/oracle/emiliano/USA10.stby.ctl';

---############################################ Duplicate the Database##########################################

##From Primary DB Restore the DB to the Standby Side:

Page 269: 11gR2 ASMCMD Commands

rman connect target sys/xxxxxxx@USA10                             ----PS No domain for Targetconnect auxiliary sys/[email protected]      ----PS Use domain for Auxiliary

run {   allocate channel p1 type disk;   allocate auxiliary channel s1 type disk;   duplicate target database for standby from active database   dorecover;    }

--or

run {   allocate channel p1 type disk;   allocate channel p2 type disk;   allocate channel p3 type disk;   allocate channel p4 type disk;   allocate auxiliary channel s1 type disk;   allocate auxiliary channel s2 type disk;   allocate auxiliary channel s3 type disk;   allocate auxiliary channel s4 type disk;   duplicate target database for standby from active database   dorecover;    }

############################################ Register the Standby Database to CRS##########################################

srvctl add database -d EURO10 -o $ORACLE_HOMEsrvctl add instance -d EURO10 -i EURO11 -n lneuron01

############################################ Data Guard Broker Configuration##########################################

--Primaryalter system set dg_broker_config_file1 = '+DATA1/USA10/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 = '+DATA1/USA10/DATAGUARDCONFIG/brokerconfig02.dat';

--Standbyalter system set dg_broker_config_file1 = '+DATA1/EURO10/DATAGUARDCONFIG/brokerconfig01.dat';alter system set dg_broker_config_file2 =

Page 270: 11gR2 ASMCMD Commands

'+DATA1/EURO10/DATAGUARDCONFIG/brokerconfig02.dat';

--on both databasesalter system set dg_broker_start=true;

--From a primary node connect to the broker and create the configuration

#dgmgrl

DGMGRL> connect sys/[email protected].

create configuration 'CONFDG10' as primary database is 'USA10' connect identifier is USA10.emilianofusaglia.net;    add database 'EURO10' as connect identifier is EURO10.emilianofusaglia.net;

edit database 'USA10' set property 'LogXptMode' = 'SYNC';edit database 'EURO10' set property 'LogXptMode' = 'SYNC';

edit database 'USA10' set property 'LogXptMode' = 'ASYNC';edit database 'EURO10' set property 'LogXptMode' = 'ASYNC';

--edit configuration set protection mode as maxavailability;edit configuration set protection mode as maxprotection;--edit configuration set protection mode as maxavailability;--edit configuration set protection mode as maxperformance;enable configuration;

edit database 'USA10' set property 'NetTimeout' = '20';edit database 'EURO10' set property 'NetTimeout' = '20';

exit;

DGMGRL> SWITCHOVER to "EURO10";

--Stop Recoveryedit database 'EURO10' set state = 'APPLY-OFF';--Start Recoveryedit database 'EURO10' set state = 'APPLY-ON';

--Enabling ArchiveLog Tracing on Primary and Standby Good for Troubleshooting!!edit instance 'USA11' on database 'USA10' set property 'LogArchiveTrace' = '1';    edit instance 'USA12' on database 'USA10' set property 'LogArchiveTrace' = '1';    edit instance 'USA13' on database 'USA10' set property 'LogArchiveTrace' = '1';    

edit instance 'EURO11' on database 'EURO10' set property 'LogArchiveTrace' = '6345';    

Page 271: 11gR2 ASMCMD Commands

##############################################################################

Oracle ASM 11g: Does the ASMCMD cp Command Really Work?Posted by Alex Gorbachev on Apr 8, 2008 

Update 21-Sep-2011: It’s definitely was a bug in an early 11g release. As cp command does work in the latest release. Nevertheless, triple check the results if you are using it as part of your backup strategy. Don’t forget to test regularly!

Since the introduction of ASM in Oracle 10g Release 1, every ASM administrator has been dreaming of a simple command line tool to copy files between ASM diskgroups and other filesystems. Oracle ASM 10g Release 2 added the handy asmcmd utility, but even though everyone expected a copy command there, it had not been implemented.

The only way to copy files to or from an ASM diskgroup was either to use RMAN, to configure XDB for FTP access, or use the DBMS_FILE_TRANSFER package. No wonder that the cp command is the most popular addition to asmcmd tool in Oracle ASM 11g: the hardest barrier to convincing my customers to use ASM has been the inability to access the files and copy them to the OS filesystem using the command-line copy command. Customers wanted to “feel” the files and be able to easily manipulate them.

While working on a Collaborate 08 presentation on Oracle 11g new features out-of-the-box, I was verifying new commands in Oracle ASM 11g’s asmcmd utility. It turned our that copying files from or to ASM is still a problem.

First, I tried to copy a single text file to an ASM diskgroup:

ASMCMD> cp /home/oracle/.bash_profile +dg2/test.filesource /home/oracle/.bash_profiletarget +dg2/test.fileASMCMD-08012: can not determine file type for file->'/home/oracle/.bash_profile'ORA-15056: additional error messageORA-17503: ksfdopn:DGGetFileAttr15 Failed to open file /home/oracle/.bash_profileORA-27046: file size is not a multiple of logical block sizeAdditional information: 1ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 207ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

Hmm . . . Okay. Let’s try to do it in multiples of diskgroup blocks:

ASMCMD> lsdgState Type Rebal Sector Block AU Total_MB...MOUNTED EXTERN N 512 4096 1048576 2048...MOUNTED NORMAL N 512 4096 2097152 200...ASMCMD> exit[oracle@lh8 ~]$ dd if=/dev/zero of=/home/oracle/test2.file bs=4k count=10

Page 272: 11gR2 ASMCMD Commands

10+0 records in10+0 records out[oracle@lh8 ~]$ asmcmdASMCMD> cp /home/oracle/test2.file +DG2source /home/oracle/test2.filetarget +DG2/test2.fileASMCMD-08012: can not determine file type for file->'/home/oracle/test2.file'ORA-15056: additional error messageORA-19762: invalid file type DGGetFileAttr20ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 207ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

Oops. It seems I can’t put any file to ASM. Not that I’m very surprised — I expected that ASM would “automagically” try to place all files based on OMF standards and templates. There are, however, only templates and rules for database files in 11g.

Right, let me try to backup a controlfile to a filesystem and copy it to ASM:

RMAN> backup format '/tmp/backup.ctl' current controlfile;...channel ORA_DISK_1: finished piece 1 at 06-APR-08piece handle=/tmp/backup.ctl tag=TAG20080406T202034 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:03...ASMCMD> cp /tmp/backup.ctl +dg2/backup.ctlsource /tmp/backup.ctltarget +dg2/backup.ctlcopying file(s)...file, +DG2/backup.ctl, copy committed.ASMCMD> ls -l +dg2/backup.ctlType Redund Striped Time Sys Name N backup.ctl => +DG2/ASMTESTING/BACKUPSET/TESTING.256.651356493

Alright. That seems to work, except that ASM chose a bizarre location. For some reason, I’m not surprised again — I kind of expected it to place it somewhere into DB_UNKNOWN like RMAN does when recovering SPFILE from autobackup. In the best Oracle traditions of keeping things consistent, ASMTESTING seems to be reasonable. Was it a hard-coded leftover from the test implementation of the cp command? I wouldn’t be surprised, it’s deja-vu.

We can be patient and forgive this for the first release. Let’s try to copy it to a filesystem and back:

ASMCMD> cp +dg2/backup.ctl /tmp/backup.ctl2source +dg2/backup.ctltarget /tmp/backup.ctl2copying file(s)...file, /tmp/backup.ctl2, copy committed.ASMCMD> cp /tmp/backup.ctl2 +dg2/backup.ctl2source /tmp/backup.ctl2target +dg2/backup.ctl2ASMCMD-08012: can not determine file type for file->'/tmp/backup.ctl2'ORA-15056: additional error message

Page 273: 11gR2 ASMCMD Commands

ORA-19762: invalid file type DGGetFileAttr20ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 207ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

Now, that is odd. Perhaps I need to register this file with the database (i.e. in the controlfile)? Let’s ask RMAN to catalog this file:

[oracle@lh8 ~]$ ls -l /tmp/backup.ctl*-rw-r----- 1 oracle dba 9797632 Apr 6 20:20 /tmp/backup.ctl-rw-r----- 1 oracle dba 9797632 Apr 6 20:22 /tmp/backup.ctl2...RMAN> catalog start with '/tmp/backup.ctl2';...List of Files Which Where Not Cataloged=======================================File Name: /tmp/backup.ctl2 RMAN-07517: Reason: The file header is corrupted

So the file got corrupted while copying from ASM to a filesystem? Okay. Let’s try an ASM -> ASM copy:

ASMCMD> cp +dg2/backup.ctl +dg2/backup.ctl3source +dg2/backup.ctltarget +dg2/backup.ctl3copying file(s)...file, +DG2/backup.ctl3, copy committed....RMAN> catalog start with '+dg2';...List of Files Which Where Not Cataloged=======================================File Name: +dg2/backup.ctl RMAN-07517: Reason: The file header is corruptedFile Name: +dg2/backup.ctl3 RMAN-07517: Reason: The file header is corrupted

Hey, both files are actually corrupted, so the corruption occurred in the first copy, from the filesystem to ASM. Alright. Let’s try to simply copy a current controlfile within ASM:

ASMCMD> cp +dg1/db11g/controlfile/Current.256.651275203 +dg2/asm_copysource +dg1/db11g/controlfile/Current.256.651275203target +dg2/asm_copycopying file(s)...file, +DG2/asm_copy, copy committed.

ASMCMD> ls -l +dg2/asm_copyType Redund Striped Time Sys Name N asm_copy => +DG2/ASMTESTING/CONTROLFILE/TESTING.258.651358725...RMAN> catalog start with '+dg2';...List of Files Which Where Not Cataloged=======================================

Page 274: 11gR2 ASMCMD Commands

File Name: +dg2/asm_copy RMAN-07517: Reason: The file header is corrupted

These results are disappointing — I couldn’t make the cp command work even a single time.

I should note that I did ask my old good friends, Metalink and Google, about ASMCMD-08012 and the like, but they came back empty.

If anyone has been able to test the ASMCMD cp command in 11g, please share your experience.