Wednesday, July 30, 2014

RMAN List Command in Oracle

RMAN List Command in Oracle


RMAN> LIST ARCHIVELOG ALL;
RMAN> LIST BACKUP OF ARCHIVELOG ALL;
RMAN> LIST BACKUP;
RMAN> LIST BACKUP OF DATABASE;
RMAN> LIST BACKUP OF DATAFILE 1;
RMAN> LIST BACKUP SUMMARY;
RMAN> LIST INCARNATION;
RMAN> LIST BACKUP BY FILE;
RMAN> LIST COPY OF DATABASE ARCHIVELOG ALL;
RMAN> LIST COPY OF DATAFILE 1, 2, 3;
RMAN> LIST BACKUP OF DATAFILE 11 SUMMARY;
RMAN> LIST expired Backup of archivelog all summary;
RMAN> LIST Backup of tablespace Test summary;
RMAN> LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 1437;
RMAN> LIST CONTROLFILECOPY “/tmp/cntrlfile.copy”;
RMAN> LIST BACKUPSET OF DATAFILE 1;
RMAN> LIST FAILURE;
RMAN> LIST FAILURE 641231 detail;
RMAN> LIST Backup of Controlfile;
RMAN> LIST Backup of Spfile;
RMAN> LIST Backup of Tablespace Test;
RMAN> LIST expired Backup;
RMAN> LIST expired Backup summary;
RMAN> LIST expired Backup of Archivelog all;
RMAN> LIST expired Backup of datafile 10;
RMAN> LIST recoverable backup;

Monday, July 28, 2014

How to STOP and START processes in Oracle RAC and Log Directory Structure

How to STOP and START processes in Oracle RAC and Log Directory Structure

You need to follow the below steps to Stop and Start processes in Oracle RAC

Shutdown RAC Database
You need to Shutdown Database instances on each node. You can either use Oracle Enterprise Manager or SVRCTL to shutdown the instances. If you are using EM Grid control then set a blackout in Grid control for processes that you intend to shutdown. So that records for these processes indicate that the shutdown was planned.
Use below command to stop Enterprise Manager/Grid Control
$ORACLE_HOME/bin/emctl stop dbconsole

Use below command to shutdown all oracle RAC instances on all nodes.
$ ORACLE_HOME/bin/srvctl stop database -d db_name

If you want to stop specific database instances use below command
$ ORACLE_HOME/bin/srvctl stop database -d db_name –i instance_name

Shutdown Oracle ASM Instance
Once the database is stopped, proceed with ASM Instance shutdown. 
Use below command to shutdown ASM instances on all nodes
$ORACLE_HOME/bin/bin/srvctl stop asm -n node

Shutdown Node applications
Use below command to shutdown node apps on all RAC nodes
$ORACLE_HOME/bin/bin/srvctl stop nodeapps -n node

Shutdown Oracle Clusterware
You need to Shutdown oracle clusterware or CRS as root and run below command on each node in the cluster.
#crsctl stop crs

Please note that using above command will stop Oracle High availability services (OHAS) and Clustware stack in a single command

From 11g R2, you can do this in two steps

1. Stop Clustwerware stack on local node
#crsctl stop cluster

You can stop the clusterware stack on all nodes in the cluster 
# Crsctl stop cluster –all

Where
-all Start clusterware on all nodes
-n Start clusterware on particular nodes

2. Stop Oracle High availability service demon on each node in the cluster.
# crsctl stop has

Check the Status of Cluster
Once all process stopped run the below command to check the status of CRSD,CSSD,EVMD process.
# crsctl check crs

If you see any process failed to stop then you can also use Force option to terminate the processes unconditionally.
$ crsctl stop crs –all –f

Start processes in Oracle RAC
Follow the reverse sequence to start all processes in oracle RAC
# crsctl start crs
$ORACLE_HOME/bin/bin/srvctl start nodeapps -n node
$ORACLE_HOME/bin/bin/srvctl start asm -n node
$ORACLE_HOME/bin/srvctl start database -d db_name

If you come across any issues during startup orshutdown, check the Oracle Clusterware Component Log Files.

Oracle Clusterware Log Directory Structure

CRS_HOME/log/hostname/crsd/ - The log files for the CRS daemon CRS_HOME/log/hostname/cssd/ - The log files for the CSS daemon 
CRS_HOME/log/hostname/evmd/ - The log files for the EVM daemon
CRS_HOME/log/hostname/client/ - The log files for the Oracle Cluster Registry (OCR) 
CRS_HOME/log/hostname/racg/ - The log files for the Oracle RAC high availability component
CRS_HOME/log/hostname/racg/ - The log files for the Oracle RAC high availability component
CRS_HOME/log/hostanme/alert.log – The alert.log for Clusterware issues.

Please note that the CRS_HOME is the directory in which the Oracle Clusterware software was installed and hostname is the name of the node

ORACLE 11g R2 RAC Clusterware Startup

ORACLE 11g R2 RAC Clusterware Startup


The restart of a UNIX server call initialization scripts to start processes and daemons. Every platform has a unique directory structure and follows a method to implement server startup sequence. In Linux platform (prior to Linux 6), initialization scripts are started by calling scripts in the /etc/rcX.d directories, where X denotes the run level of the UNIX server. Typically, Clusterware is started at run level 3. For example, ohasd daemon started by /etc/rc3.d/S96ohasd file by supplying start as an argument. File S96ohasd is linked to /etc/init.d/ohasd.
S96ohasd -> /etc/init.d/ohasd

/etc/rc3.d/S96ohasd start  # init daemon starting ohasd.

Similarly, a server shutdown will call scripts in rcX.d directories, for example, ohasd is shut down by calling K15ohasd script:
K15ohasd -> /etc/init.d/ohasd
/etc/rc3.d/K15ohasd stop  #UNIX daemons stopping ohasd

In Summary, server startup will call files matching the pattern of S* in the /etc/rcX.d directories. Calling sequence of the scripts is in the lexical order of script name. For example, S10cscape will be called prior to S96ohasd, as the script S10cscape occurs earlier in the lexical sequence.
Google if you want to learn further about RC startup sequence. Of course, Linux 6 introduces Upstart feature and the mechanism is a little different: http://en.wikipedia.org/wiki/Upstart
That’s not the whole story!
Have you ever thought why the ‘crsctl start crs’ returns immediately? You can guess that Clusterware is started in the background as the command returns to UNIX prompt almost immediately. Executing the crsctl command just modifies the ohasdrun file content to ‘restart’. It doesn’t actually perform the task of starting the clusterware. Daemon init.ohasd reads the ohasdrun file every few seconds and starts the Clusterware if the file content is changed to ‘restart’.
# cat /etc/oracle/scls_scr/oel6rac1/root/ohasdrun
restart
If you stop has using ‘crsctl stop has’ , then the ohasdstr file content is modified to stop and so, init.ohasd daemon will not restart Clusterware. However, stop command is synchronous and executes the stop of clusterware too.
# crsctl stop has
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'oel6rac1'
CRS-2673: Attempting to stop 'ora.crsd' on 'oel6rac1'
..
The content of ohasdrun is modified to stop:
# cat  /etc/oracle/scls_scr/oel6rac1/root/ohasdrun
stop # 
In a nutshell, init.ohasd daemon is monitoring the ohasdrun file and starts the Clusterware stack if the value in the file is modified to restart.
Inittab
Init.ohasd daemon is an essential daemon for Clusterware startup. Even if the Clusterware is not running on a node, you can start the Clusterware from a different node. How does that work? Init.ohasd is the reason.
The init.ohasd daemon is started from /etc/inittab. Entries in the inittab is monitored by the init daemon (pid=1) and init daemon will react if the inittab file is modified. The init daemon monitors all processes listed in the inittab file and reacts according to the configuration in the inittab file. For example, if init.ohasd fails for some reason, it is immediately restarted by init daemon.
Following is an example entry in the inittab file. Fields are separated a colon, second field indicates that init.ohasd will be started in run level 3, and the third field indicates an action field. Restart in the action field means that, if the target process exist, just continue scanning inittab file; if the target process does not exist, then restart the process.
#cat /etc/inittab
…
h1:3:respawn:/etc/init.d/init.ohasd run >/dev/null 2>&1 
If you issue a clusterware startup command from a remote node, that a message sent to init.ohasd daemon in the target node, and the daemon initates the clusterware startup. So, init.ohasd will be always running irrespective of whether the Clusterware is running or not.
You can use strace on init.ohasd to verify this behavior. Following are a few relevant lines from the output of strace command of init.ohasd process:
…
5641  1369083862.828494 open("/etc/oracle/scls_scr/oel6rac1/root/ohasdrun", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
5641  1369083862.828581 dup2(3, 1)      = 1
5641  1369083862.828606 close(3)        = 0
5641  1369083862.828631 execve("/bin/echo", ["/bin/echo", "restart"], [/* 12 vars */]) = 0
…
Just for fun!
So, what happens if I manually modify that ohasdrun to restart? I copied the ohasdrun to a temporary file (/tmp/a1.lst) and stopped the clusterware.
cp /etc/oracle/scls_scr/oel6rac1/root/ohasdrun /tmp/a1.lst 
# crsctl stop has
I verified that Clusterware is completely stopped. Now, I will copy the file again overlaying ohasdrun:
# cat /tmp/a1.lst
restart
# cp /tmp/a1.lst  /etc/oracle/scls_scr/oel6rac1/root/ohasdrun
After a minute or so, I see that Clusterware processes are started. Not that, you would use this type of hack in a Production cluster, but this test proves my point.
It’s also important not to remove the files in the scls_scr directories. Any removal of the files underneath the scls_scr directory structure can lead to an invalid configuration.
There are also two more files in the scls_scr directory structure. Ohasdstr file decides if the HAS daemon should be started automatically or not. For example, if you execute ‘crsctl disable has’, that command modifies ohasdstr file contents to ‘disable’. Similarly, crsstart file controls CRS daemon startup. Again, you should use recommended commands to control the startup, rather than modifying any of these files directly.
11.2.0.1 and HugePages
If you tried to configure hugepages in 11.2.0.1 clusterware, by increasing memlock kernel parameter for GRID and database owner, you would have realized that database doesn’t use hugepages if started by the clusterware. Database startup using sqlplus will use hugepages, but the database startup using srvctl may not use hugepages.
As the new processes are cloned from the init.ohasd daemon, until init.ohasd is restarted, user level memlock limit changes are not correctly reflected in an already running process. Only recommended way to resolve the problem is to restart the node completely (not just the clusterware), as init.ohasd daemon must be restarted to reflect the user level limits.
Version 11.2.0.2 fixes this issue by explicitly calling ulimit command from /etc/init.d/ohasd files.

Summary 

In Summary, init.ohasd process is an important process. Files underneath scls_scr directory is controlling the startup behavior. This also means that if a server is restarted, you don’t need to explicitly stop the Clusterware. You can let the server startup to restart the Clusterware.

Thursday, July 24, 2014

Oracle ASM disks Demystfied

Oracle ASM disks Demystfied

When asm disks are created using

oracleasm create disk

oracleasm create disk 'DISK1' /dev/sdb --> This info is stored in header of raw/block device.
ASM Label information is stored in each disk header and can be viewed with kfed read

oracleasm-discover gives the listing of disks along with label names

oracleasm driver scans the devices as mentioned in below files in ORACLEASM_SCANORDER
"dm" --> devices starting with /dev

[oracle@DBRAC01 sysconfig]$ file oracleasm-_dev_oracleasm
oracleasm-_dev_oracleasm: ASCII English text
[oracle@DBRAC01 sysconfig]$ cat oracleasm-_dev_oracleasm
#
# This is a configuration file for automatic loading of the Oracle
# Automatic Storage Management library kernel driver.  It is generated
# By running /etc/init.d/oracleasm configure.  Please use that method
# to modify this file
#

# ORACLEASM_ENABELED: 'true' means to load the driver on boot.
ORACLEASM_ENABLED=true

# ORACLEASM_UID: Default user owning the /dev/oracleasm mount point.
ORACLEASM_UID=oracle

# ORACLEASM_GID: Default group owning the /dev/oracleasm mount point.
ORACLEASM_GID=dba

# ORACLEASM_SCANBOOT: 'true' means scan for ASM disks on boot.
ORACLEASM_SCANBOOT=true

# ORACLEASM_SCANORDER: Matching patterns to order disk scanning
ORACLEASM_SCANORDER="dm"

# ORACLEASM_SCANEXCLUDE: Matching patterns to exclude disks from scan
ORACLEASM_SCANEXCLUDE="sd"

[oracle@DBRAC01 sysconfig]$ cd /dev/oracleasm/disks
[oracle@DBRAC01 disks]$ ls -ltr
total 0
brw-rw---- 1 oracle dba 253, 11 Jul 23 14:09 DISK4
brw-rw---- 1 oracle dba 253, 12 Jul 23 14:09 DISK3
brw-rw---- 1 oracle dba 253, 13 Jul 23 14:09 DISK2
brw-rw---- 1 oracle dba 253, 14 Jul 23 14:09 DISK1
brw-rw---- 1 oracle dba 253, 15 Jul 23 14:09 DISK5
[oracle@DBRAC01 disks]$ df -ha
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       97G   66G   27G  72% /
proc                     0     0     0   -  /proc
sysfs                    0     0     0   -  /sys
devpts                   0     0     0   -  /dev/pts
/dev/mapper/VolGroup00-LogVol02
                      9.7G  927M  8.3G  10% /var
/dev/mapper/VolGroup00-LogVol03
                      4.9G  1.5G  3.2G  32% /home
/dev/mapper/VolGroup00-LogVol04
                       40G   31G  9.3G  77% /u01
/dev/cciss/c0d0p1     244M   37M  195M  16% /boot
tmpfs                  19G  324M   19G   2% /dev/shm
/dev/mapper/VolGroup00-var--crash_lv
                       40G  177M   40G   1% /var/crash
none                     0     0     0   -  /proc/sys/fs/binfmt_misc
sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
oracleasmfs              0     0     0   -  /dev/oracleasm
nfsd                     0     0     0   -  /proc/fs/nfsd

[oracle@DBRAC01 disks]$ /usr/sbin/oracleasm-discover
Using ASMLib from /opt/oracle/extapi/64/asm/orcl/1/libasm.so
[ASM Library - Generic Linux, version 2.0.4 (KABI_V2)]
Discovered disk: ORCL:DISK1 [419424957 blocks (214745577984 bytes), maxio 512]
Discovered disk: ORCL:DISK2 [419424957 blocks (214745577984 bytes), maxio 512]
Discovered disk: ORCL:DISK3 [419424957 blocks (214745577984 bytes), maxio 512]
Discovered disk: ORCL:DISK4 [419424957 blocks (214745577984 bytes), maxio 512]
Discovered disk: ORCL:DISK5 [419424957 blocks (214745577984 bytes), maxio 512]
[oracle@DBRAC01 disks]$ kfed read /dev/oracleasm/disks/DISK1
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: blk=0
kfbh.block.obj:              2147483648 ; 0x008: disk=0
kfbh.check:                  3179708272 ; 0x00c: 0xbd867f70
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:    ORCLDISKDISK1 ; 0x000: length=13
kfdhdb.driver.reserved[0]:   1263749444 ; 0x008: 0x4b534944
kfdhdb.driver.reserved[1]:           49 ; 0x00c: 0x00000031
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                186646528 ; 0x020: 0x0b200000
kfdhdb.dsknum:                        0 ; 0x024: 0x0000
kfdhdb.grptyp:                        1 ; 0x026: KFDGTP_EXTERNAL
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname:                   DISK1 ; 0x028: length=5
kfdhdb.grpname:                    DATA ; 0x048: length=4
kfdhdb.fgname:                    DISK1 ; 0x068: length=5
kfdhdb.capname:                         ; 0x088: length=0
kfdhdb.crestmp.hi:             32983095 ; 0x0a8: HOUR=0x17 DAYS=0x1 MNTH=0x2 YEAR=0x7dd
kfdhdb.crestmp.lo:           3869179904 ; 0x0ac: USEC=0x0 MSEC=0x3c0 SECS=0x29 MINS=0x39
kfdhdb.mntstmp.hi:             33001236 ; 0x0b0: HOUR=0x14 DAYS=0x18 MNTH=0x3 YEAR=0x7de
kfdhdb.mntstmp.lo:            575480832 ; 0x0b4: USEC=0x0 MSEC=0x349 SECS=0x24 MINS=0x8
kfdhdb.secsize:                     512 ; 0x0b8: 0x0200
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000
kfdhdb.ausize:                  1048576 ; 0x0bc: 0x00100000
kfdhdb.mfact:                    113792 ; 0x0c0: 0x0001bc80
kfdhdb.dsksize:                  204797 ; 0x0c4: 0x00031ffd
kfdhdb.pmcnt:                         3 ; 0x0c8: 0x00000003
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002
kfdhdb.f1b1locn:                      2 ; 0x0d4: 0x00000002
kfdhdb.redomirrors[0]:                0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]:                0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]:                0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]:                0 ; 0x0de: 0x0000
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000
kfdhdb.grpstmp.hi:             32983095 ; 0x0e4: HOUR=0x17 DAYS=0x1 MNTH=0x2 YEAR=0x7dd
kfdhdb.grpstmp.lo:           3868648448 ; 0x0e8: USEC=0x0 MSEC=0x1b9 SECS=0x29 MINS=0x39
kfdhdb.vfstart:                      64 ; 0x0ec: 0x00000040
kfdhdb.vfend:                        96 ; 0x0f0: 0x00000060
kfdhdb.spfile:                        0 ; 0x0f4: 0x00000000
kfdhdb.spfflg:                        0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[0]:                   0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[1]:                   0 ; 0x100: 0x00000000

Snippet....

If there's any issue with oralceasm driver, the disks are not visible in /dev/oracleasm/disks/..
this can happen when the server/OS kernel is upgraded and oracleasm driver is not updated to the same kernel.
 For this we need to download the correct asm driver for the kernel and update.
Post OS patching, it's recommended to relink binaries...

Troublshooting any errors with asm or any other... look for /var/log/messages

Before making any changes to asm configurations... take a backup of current configuration once the asm 
services are down from /etc/sysconfig/oracleasm*

[oracle@DBRAC01 sysconfig]$ ls -ltr oracle*
lrwxrwxrwx 1 root root  24 Jan 31  2013 oracleasm -> oracleasm-_dev_oracleasm
-rw-r--r-- 1 root root 260 Jan 31  2013 oracleasm-update
-rw-r--r-- 1 root root 778 Feb  4  2013 oracleasm-_dev_oracleasm

Updating ASMLIB Driver Using Automatic “update-driver”

Updating ASMLIB Driver Using “update-driver”

This article is about updating ASMLIB after or before updating kernel version.
We know that the ASMLIB driver is kernel dependent and has to be updated to match the kernel version. We have to go to the Oracle site, find the proper version for ASMLIB driver, download it and install. But beginning oracleasm-support version 2.1.0 and higher we can use the embedded function “update-driver” which can help us to save time and simplify the process of updating ASMLIB driver.

How does it work? As example, we have installed Linux with kernel version 2.6.18-194.8.1.0.1.el5 x86_64 but ASMLIB driver is for the old kernel version 2.6.18-194.3.1.
As result we are getting an error trying to start ASMLIB.
1
2
3
4
5
[root@db1 ~]# /usr/sbin/oracleasm init
Creating /dev/oracleasm mount point: /dev/oracleasm
Loading module "oracleasm": failed
Unable to load module "oracleasm"
[root@db1 ~]#
Instead searching, downloading and installing the new driver you can just run “oracleasm update-driver” and automatically get the updated version for the driver.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@db1 ~]# /usr/sbin/oracleasm update-driver
Kernel:         2.6.18-194.8.1.0.1.el5 x86_64
Driver name:    oracleasm-2.6.18-194.8.1.0.1.el5
 
Fetching Obsoletes list for channel: el5_x86_64_latest...
########################################
 
Fetching rpm headers...
########################################
 
Name                                    Version        Rel
----------------------------------------------------------
oracleasm-2.6.18-194.8.1.0.1.el5        2.0.5          1.el5             x86_64
 
Testing package set / solving RPM inter-dependencies...
########################################
oracleasm-2.6.18-194.8.1.0. ########################## Done.
Preparing              ########################################### [100%]
 
Installing...
1:oracleasm-2.6.18-194.8.########################################### [100%]
[root@db1 ~]# /usr/sbin/oracleasm init
Loading module "oracleasm": oracleasm
Mounting ASMlib driver filesystem: /dev/oracleasm
[root@db1 var]#  /etc/init.d/oracleasm  start
Initializing the Oracle ASMLib driver:                     [  OK  ]
Scanning the system for Oracle ASMLib disks:               [  OK  ]
[root@db1 var]#  /etc/init.d/oracleasm  listdisks
DATADISK1
[root@db1 var]#
Finally! We have an updated working driver.
And, we also have some options for this feature:
-d allows us only download the driver.
-n allows only determine what driver would be updated without taking any action.