Oracle DBA – Tips and Techniques

Knowledge is Power – so share it ….

Archive for the ‘Unix’ Category

Unix – tar and gzip commands

Posted by Arjun Raja on July 23, 2009

tar and compress a bunch of datafiles and then untar and uncompress them

cd /u02/oradata/test- (area of database files )

Now tar and compress and copy the files to backup area – /u02/oradata/test_bkup and name the file as test.tar.gz

tar cvf – * |gzip -c >/u02/oradata/test_bkup/test.tar.gz –

cd /u02/oradata/test_bkup > ls -lrt

-rw-r–r– 1 ofsad1 dba 105952962 Feb 26 11:31 test.tar.gz

Now to untar and uncompress the files back to the original area -

cd /u02/oradata/test

gzip -dc < /u02/oradata/test_bkup/test.tar.gz | tar xvf -

Posted in Unix | Tagged: , , | Leave a Comment »

Unix for the Oracle DBA – Part 1

Posted by Gavin Soorma on July 17, 2009

Locating Files under a particular directory

find . -print |grep -i test.sql

Using AWK in UNIX

To remove a specific column of output from a UNIX command – for example to determine the UNIX process Ids for all Oracle processes on server (second column)

ps -ef |grep -i oracle |awk ‘{ print $2 }’

Changing the standard prompt for Oracle Users

Edit the .profile for the oracle user

PS1=”`hostname`*$ORACLE_SID:$PWD>”

Display top 10 CPU consumers using the ps command

/usr/ucb/ps auxgw | head –11

Show number of active Oracle dedicated connection users for a particular ORACLE_SID

ps -ef | grep $ORACLE_SID|grep -v grep|grep -v ora_|wc –l

Display the number of CPU’s in Solaris

psrinfo -v | grep “Status of processor”|wc –l

Display the number of CPU’s in AIX

lsdev –C | grep Process|wc –l

Display RAM Memory size on Solaris

prtconf |grep -i mem

Display RAM memory size on AIX

First determine name of memory device

lsdev -C |grep mem

then assuming the name of the memory device is ‘mem0’

lsattr -El mem0

Swap space allocation and usage

Solaris : swap -s or swap -l

Aix : lsps -a

Total number of semaphores held by all instances on server

ipcs -as | awk ‘{sum += $9} END {print sum}’

View allocated RAM memory segments

ipcs -pmb

Manually deallocate shared memeory segments

ipcrm -m ‘ID’

Show mount points for a disk in AIX

lspv -l hdisk13

Display amount of occupied space (in KB) for a file or collection of files in a directory or sub-directory

du -ks * | sort -n| tail

Display total file space in a directory

du -ks .

Cleanup any unwanted trace files more than seven days old

find . *.trc -mtime +7 -exec rm {} \;

Locate Oracle files that contain certain strings

find . -print | xargs grep rollback

Locate recently created UNIX files (in the past one day)

find . -mtime -1 –print

Finding large files on the server (more than 100MB in size)

find . -size +102400 -print

Crontab :

To submit a task every Tuesday (day 2) at 2:45PM

45 14 2 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

To submit a task to run every 15 minutes on weekdays (days 1-5)

15,30,45 * 1-5 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

To submit a task to run every hour at 15 minutes past the hour on weekends (days 6 and 0)

15 * 0,6 * * opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

Posted in Unix | Tagged: , , , , , | Leave a Comment »

Performance Tuning Tips and Techniques

Posted by Gavin Soorma on July 17, 2009

Checks to be performed at the machine level (note the example is Red Hat Linux specific)

run queue should be ideally not more than the number of CPU’s on the machine

At the maximum it should never be more than twice the number of CPU’s.

This is denoted by the column ‘r’ in the vmstat output shown below

vmstat – 5

face:/opt/oracle>vmstat 5
procs                      memory      swap          io     system         cpu
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 4  1 488700 245704 178276 12513572    0    1    10    17   48  1365 40 12 43  5
 2  0 488700 302568 178312 12514904    0    0   157   686 3354  4342 55 22 22  1
 3  1 488700 257500 178508 12517896    0    0   616   221 1352  2132 21  7 64  9
 2  2 488700 232348 178820 12525392    0    0  1550   274 3632  6091 29  9 42 20
 3  0 488700 225040 178880 12527336    0    0   346   452 2494  3300 45 13 38  4
 5  0 488700 225680 178916 12527884    0    0    79   269 2005  3847 29 11 58  2

CPU idle% < 10 ( id column) could indicate a machine that is having CPU resource issues

Note: How to find number of CPU’s on a LINUX machine?

cat /proc/cpuinfo |grep -w “processor” |wc –l

Swap columns si and so should ideally be 0 to indicate no swapping activity

face:/opt/oracle>free -m
             total       used       free     shared    buffers     cached
Mem:         15635      15476        159          0        173      12196
-/+ buffers/cache:       3106      12528
Swap:         3999        477       3522

We should be looking at the free and used values in the row denoted by
“-/+ buffers/cache”

The ‘top’ command will help us identify the load average on the machine as well as any process that is consuming excessive CPU

face:/opt/oracle>top
09:04:01  up 243 days, 13:01, 10 users,  load average: 2.80, 3.14, 3.13
813 processes: 797 sleeping, 8 running, 8 zombie, 0 stopped
CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle
           total   40.7%    0.0%   12.7%   0.0%     0.3%    2.3%   43.7%
           cpu00   42.8%    0.0%   13.4%   0.3%     1.1%    1.9%   40.0%
           cpu01   37.3%    0.0%   12.6%   0.0%     0.0%    1.7%   48.2%
           cpu02   47.5%    0.0%   14.1%   0.0%     0.1%    1.1%   36.9%
           cpu03   35.1%    0.0%   10.5%   0.0%     0.0%    4.5%   49.7%

Mem:  16010560k av, 15808688k used,  201872k free,       0k shrd,  181324k buff
                   11368660k actv, 2257548k in_d,  265628k in_c
Swap: 4095984k av,  488700k used, 3607284k free                 12551192k cache

  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
24062 oracle    18   0 1342M 1.3G 1328M S    14.0  8.5 370:13   2 oracle
 6129 oracle    18   0  958M 953M  923M R    12.3  6.0 172:14   0 oracle
10077 oracle    25   0  149M 149M  145M R     4.5  0.9   0:00   2 oracle
 9924 oracle    16   0  156M 155M  150M S     2.6  0.9   0:00   2 oracle
10038 oracle    17   0  140M 140M  136M S     2.5  0.8   0:00   1 oracle
10055 oracle    24   0  136M 135M  132M S     2.4  0.8   0:00   0 oracle
25529 oracle    17   0  782M 782M  775M S     1.7  5.0   3:58   0 oracle
 8245 oracle    16   0  274M 274M  268M S     1.6  1.7   0:03   1 oracle
 9751 oracle    16   0 70484  67M 62952 S     1.3  0.4   0:01   2 oracle
31879 oracle    16   0  830M 828M  815M R     1.0  5.2  46:06   3 oracle
 9210 oracle    15   0  229M 229M  225M S     0.7  1.4   0:01   3 oracle

A load average greater than 5 or 10 could indicate a heavily utilized machine

CPU information for each CPU is also provided via the top command as well as information on the physical as well as virtual Memory that is available on the machine.

Information on the top CPU as well as Memory consuming processes is also provided along with the Process ID (PID). In a later section we will use this PID as a parameter for a SQL query to identify the SQL being executed by the same CPU consuming process.

Identify if any single PID is constantly appearing in the top output

The iowait column can also help us identify if there s any resource contention from the IO perspective.

A value above 40-50% would indicate I/O resource issues and require further investigation into the process that is causing this high I/O – or it could indicate a case of inefficient disk sub system or file layout in the database.

We can also view the state of the machine at a particular time of the day by running the sar command which will provide the system utilisation report since 12:00 AM on that particular day.

We can use the sar command to identify the machine state even for a particular day of the month

For example sar -f /var/log/sa/sa03 will report for the 3rd of the month

Checks to be performed at the database level

Identify with the user if the problem is a slow response or a hanging situation.

Establish a connection via SQL*NET using a non SYSDBA account to confirm that the listener is accepting client connections and the hanging is not due to the archive area getting 100% full.

Examine the alert log file for ‘Checkpoint Not Completed’ errors recorded at the time the performance problem is reported – this could indicate an I/O contention issue or inadequately sized redo log files which can also cause an application hang while the checkpoint completes.

Ensure that the mount point on which the Oracle software is not 100% full or the disks holding the controlfiles are also not 100% full.

Check the listener.log file if it exists and ensure that it is not > 2GB – on some Operating Systems like LINUX, there is a file size upper limit for the listener.log file after which client connections will not be accepted by the listener.

Check for locked sessions (see script check_lock.sql).

If a PID has been identified as a top CPU consuming process, check the SQL being executed by that particular PID (see script check_pid_sql.sql)

If the user provides a particular SID where a possible performance issue exists, check the SQL being executed by that SID ( see script check_sid_sql.sql)

If the user provides a particular Oracle username where a possible performance issue exists, check the SQL being executed by that Oracle user ( see script check_username_sql.sql)

Very Important – check the major wait events in the database (see script wait_events.sql)

Check the SID along with the events that each SID is waiting on (see script wait_events_sid.sql) – based on the SID, the SQL being executed by the waiting sessions can be obtained as well ( see script check_sid_sql.sql)

Refer document Resolving common Oracle Wait Events using the Wait Interface for details on important wait events along with their possible causes and resolution.

Check for any sessions continuously waiting for on a particular latch (see script check_latch.sql) and also refer document “Resolving common Oracle Wait Events using the Wait Interface.doc”.

What has changed?

Is there a measurable baseline regarding the “problem” query – when did it last perform well?

Has the database been upgraded recently?

Has any modifications been done to the database in terms of init.ora parameters?

Have any new indexes been added to the table or has the table structure changed?

Has the platform or database version changed?

Is this a period of unusual business activity? – like a monthly data load or one-off batch job

Appendix

check_pid_sql.sql

SET PAGESIZE 500
set long 500000
set head off
select
       s.username su,
       substr(sa.sql_text,1,540) txt
from v$process p,
     v$session s,
     v$sqlarea sa
where    p.addr=s.paddr
and      s.username is not null
and      s.sql_address=sa.address(+)
and      s.sql_hash_value=sa.hash_value(+)
and spid=;

check_sid_sql.sql

SET PAGESIZE 500
PROMPT=============================================================
PROMPT Current SQL statement this session executes
PROMPT=============================================================
col sql_text for a70 hea "Current SQL"
select q.sql_text
from v$session s
,    v$sql     q
WHERE s.sql_address = q.address
and   s.sql_hash_value + DECODE
                 (SIGN(s.sql_hash_value), -1, POWER( 2, 32), 0) = q.hash_value
AND   s.sid= ;

check_username_sql.sql

set long 500000
SET PAGESIZE 500
select
       s.username su,
       substr(sa.sql_text,1,540) txt
from v$process p,
     v$session s,
     v$sqlarea sa
where    p.addr=s.paddr
and      s.username is not null
and      s.sql_address=sa.address(+)
and      s.sql_hash_value=sa.hash_value(+)
and s.username=upper('&username');

check_lock.sql

set linesize 500
SET PAGESIZE 500
col waiting_session format 99999 heading 'Waiting|Session'
col holding_session format 99999 heading 'Holding|Session'
col mode_held format a20 heading 'Mode|Held'
col mode_requested format a20 heading 'Mode|Requested'
col lock_type format a20 heading 'Lock|Type'
prompt blocked objects from V$LOCK and SYS.OBJ$

set lines 132
col BLOCKED_OBJ format a35 trunc

select /*+ ORDERED */
    l.sid
,   l.lmode
,   TRUNC(l.ctime/60) min_blocked
,   u.name||'.'||o.NAME blocked_obj
from (select *
      from v$lock
      where type='TM'
      and sid in (select sid
                  from v$lock
                  where block!=0)) l
,     sys.obj$ o
,     sys.user$ u
where o.obj# = l.ID1
and   o.OWNER# = u.user#
;

prompt blocked sessions from V$LOCK

select /*+ ORDERED */
   blocker.sid blocker_sid
,  blocked.sid blocked_sid
,  TRUNC(blocked.ctime/60) min_blocked
,  blocked.request
from (select *
      from v$lock
      where block != 0
      and type = 'TX') blocker
,    v$lock        blocked
where blocked.type='TX'
and blocked.block = 0
and blocked.id1 = blocker.id1
;

prompt blockers session details from V$SESSION

set lines 132
col username format a10 trunc
col osuser format a12 trunc
col machine format a15 trunc
col process format a15 trunc
col action format a50 trunc

SELECT sid
,      serial#
,      username
,      osuser
,      machine
FROM v$session
WHERE sid IN (select sid
      from v$lock
      where block != 0
      and type = 'TX')
;

wait_events.sql

SELECT count(*), event FROM v$session_wait
WHERE wait_time = 0
AND event NOT IN
('smon timer','pmon timer','rdbms ipc message',
'SQL*Net message from client')
GROUP BY event ORDER BY 1 DESC
;

wait_events_sid.sql

col username format a12
col sid format 9999
col state format a15
col event format a45
col wait_time format 99999999
set pagesize 800
set linesize 800
select s.sid, s.username, se.event
from v$session s, v$session_wait se
where s.sid=se.sid
and se.event not like 'SQL*Net%'
and se.event not like '%rdbms%'
and s.username is not null
order by 3;

check_latch.sql

select count(*), name latchname from v$session_wait, v$latchname
where event='latch free' and state='WAITING' and p2=latch#
group by name order by 1 desc;

Posted in Performance Tuning, Unix | Tagged: , , , , , , , , , , | Leave a Comment »

Data Guard Log Shipping Report

Posted by Gavin Soorma on July 16, 2009

If we have a number of Data Guard physical standby database environments to manage, the following report can help us quickly identify the log transported and log applied status of the Primary and Standby databases in our environment and if any standby database is lagging behind the primary as well.

The script can also be customised so as to email an alert notification if the standby and the primary go out of sync by say 5 log files. Drop me a line if you need that customisation script.

This report is based on a Unix shell script (check_logship.sh) which in turn calls a SQL script (check_logship.sql).

The script requires a user MONITOR to be created in each target database with the CONNECT and SELECT ANY DICTIONARY privileges. We also have a config file (in our case bw_dg.lst) which will contain the list of all the TNS aliases of the Primary databases which we need to monitor.

[PROD] emrep:/u01/oracle/scripts > ./check_logship.sh

#######################################################################################
	Data Guard Log Shipping Summary Report:  Thu Jul 16 14:22:02 WAUST 2009
#######################################################################################

DB_NAME  HOSTNAME     LOG_ARCHIVED LOG_APPLIED APPLIED_TIME  LOG_GAP
-------- ------------ ------------ ----------- ------------  -------

GENPRD   CBDORCA201          16742       16742 16-JUL/14:12       0

CPSPRD   PRDU009N1           11494       11494 16-JUL/14:10       0

LN1P     CBDORCA101          51173       51171 16-JUL/12:25       2

LA1P     CBDORCA105          76971       76970 16-JUL/13:10       1

#######################################################################################

check_logship.sql

SET PAGESIZE 124
SET HEAD OFF
COL DB_NAME FORMAT A8
COL HOSTNAME FORMAT A12
COL LOG_ARCHIVED FORMAT 999999
COL LOG_APPLIED FORMAT 999999
COL LOG_GAP FORMAT 9999
COL APPLIED_TIME FORMAT A12
SELECT DB_NAME, HOSTNAME, LOG_ARCHIVED, LOG_APPLIED,APPLIED_TIME,
LOG_ARCHIVED-LOG_APPLIED LOG_GAP
FROM
(
SELECT NAME DB_NAME
FROM V$DATABASE
),
(
SELECT UPPER(SUBSTR(HOST_NAME,1,(DECODE(INSTR(HOST_NAME,’.'),0,LENGTH(HOST_NAME),
(INSTR(HOST_NAME,’.')-1))))) HOSTNAME
FROM V$INSTANCE
),
(
SELECT MAX(SEQUENCE#) LOG_ARCHIVED
FROM V$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED=’YES’
),
(
SELECT MAX(SEQUENCE#) LOG_APPLIED
FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED=’YES’
),
(
SELECT TO_CHAR(MAX(COMPLETION_TIME),’DD-MON/HH24:MI’) APPLIED_TIME
FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED=’YES’
);

check_logship.sh

if [ -f /tmp/dataguard1.out ]
then
rm /tmp/dataguard1.out
fi

if [ -f /tmp/dataguard2.out ]
then
rm /tmp/dataguard2.out
fi

export SCRPT=/u01/app/scripts

for i in `cat $SCRPT/bw_dg.lst`
do
sqlplus -s monitor/xxx@$i <> /tmp/dataguard2.out
@/$SCRPT/check_logship.sql
EOF
echo “#######################################################################################” > /tmp/dataguard1.out
echo ” Data Guard Log Shipping Summary Report: `date ` ” >> /tmp/dataguard1.out
echo “#######################################################################################” >> /tmp/dataguard1.out
echo >> /tmp/dataguard1.out
echo “DB_NAME HOSTNAME LOG_ARCHIVED LOG_APPLIED APPLIED_TIME LOG_GAP” >> /tmp/dataguard1.out
echo “——– ———— ———— ———– ———— ——-” >> /tmp/dataguard1.out
cat /tmp/dataguard2.out >> /tmp/dataguard1.out
done
cat /tmp/dataguard1.out

Posted in High Availability, Unix | Tagged: , , , , , | Leave a Comment »

Customizing the Unix prompt (PS1)

Posted by Gavin Soorma on July 9, 2009

We can customize the .profile on Unix to make the prompt display (variable PS1) more meaningful as well as provide some useful shortcuts.

For example, this is the .profile we use on one of the production AIX machines.

This results in the prompt display as shown below where we display the type of the machine using a color combination (in this case Red is used for all Production machines) , the current ORACLE_SID and the present working directory.

[PROD] rcatp:/u01/oracle

stty erase ^?
export ORACLE_SID=rcatp
alias sql=”sqlplus sys/xxx as sysdba”
set -o vi
export EDITOR=/usr/bin/vi
LOGS=/u01/local/bwdba/backup/logs;export LOG
export SCRPT=/u01/local/bwdba/scripts
Green=”33[32m"
Red="33[31m"
Yellow="33[33m"
BoldON="33[1m"
BoldOFF="33[22m"
NC="33[0m" # No Color
MESSAGE=`echo "$Red$BoldON[PROD]$BoldOFF$NC”`
export MESSAGE
Bold=$(tput smso)
Normal=$(tput sgr0)
export PS1=”$MESSAGE \${ORACLE_SID}:\$PWD > “

Including aliases and shortcuts make navigation very easy and enables us to quickly locate files when required.

For example to check the alert log we just need to do

$ cd $BDUMP

Or, to check the days RMAN backup logs, we just need to do

$ cd $LOG

Posted in Unix | Tagged: , , , , | Leave a Comment »

Data Guard Switchover Unix shell script

Posted by Gavin Soorma on July 6, 2009

The following Unix shell scripts can be used to automate the Data Guard Switchover process of a physical standby database.

It is very important that the scripts are run in the correct order and on right machine.

These scripts are based on a few customisations. The *.sh scripts are located in a directory called “/var/opt/oracle/dataguard” and there is another file called “set$ORACLE_SID” which is located under “/var/opt/oracle/cronjobs”. This script sets the environment for the individual Oracle instance like the $ORACLE_SID and the $ORACLE_HOME.

On the machine where the Primary Database is running we need to run the following scripts

$ cd /var/opt/oracle/dataguard
$ ./pre_switchover_check.sh
$ ./make_me_standby.sh

On the machine where the Standby Database is running we need to run the following script:

$ cd /var/opt/oracle/dataguard
$ ./make_me_primary.sh

After the switchover is completed, we need to run the following script on the machine where the former Primary (now new Standby) database is running:

$ cd /var/opt/oracle/dataguard
$ ./start_recovery.sh

pre_switchover_check.sh

!/bin/ksh

if [ "$1" = "" ]
then
echo ""
echo "##################################################################"
echo "# PLEASE ENTER ORACLE_SID AS THE FIRST COMMAND LINE ARGUMENT     #"
echo "#      SCRIPT USAGE : pre_switchover_check.sh        #"
echo "##################################################################"
echo ""
exit
fi

ORACLE_SID=`echo $1 |tr '[A-Z]' '[a-z]'`; export ORACLE_SID;

ls -l /var/opt/oracle/cronjobs/set$ORACLE_SID > /dev/null
if [ $? != 0 ]
then
echo ""
echo "##################################################################"
echo "#           ENVIRONMENT SETTING SET FILE NOT FOUND...!!!         #"
echo "#           /var/opt/oracle/cronjobs/set$ORACLE_SID              #"
echo "##################################################################"
echo ""
exit
fi

. /var/opt/oracle/cronjobs/set$ORACLE_SID

DB=`echo $1 |tr '[a-z]' '[A-Z]'`; export DB;

echo ""
echo "##################################################################"
echo "#            PERFORMING PRE-SWITCHOVER CHECKS FOR $DB            #"
echo "##################################################################"
echo ""

sqlplus  -s /nolog |&
print -p  "connect / as sysdba"
print -p  "set feedback off pause off pagesize 0 heading off verify off linesize 500 term off "
print -p  "set sqlprompt ''"
read  -p   JUNK
print -p  "SELECT DATABASE_ROLE DBROLE FROM V\$DATABASE;"
read  -p   DBROLE
print -p  "SELECT COUNT(FILE#) FILESTAT FROM V\$DATAFILE WHERE STATUS IN ('RECOVER', 'OFFLINE');"
read  -p   FILESTAT
print -p  "SELECT COUNT(FILE#) BKPSTAT FROM V\$BACKUP WHERE STATUS = 'ACTIVE';"
read  -p   BKPSTAT
print -p  "SELECT LOG_ARCHIVED-LOG_APPLIED LOGGAP
FROM (SELECT MAX(SEQUENCE#) LOG_ARCHIVED
FROM V\$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES'
AND RESETLOGS_CHANGE#=(SELECT MAX(RESETLOGS_CHANGE#)
FROM V\$ARCHIVED_LOG)),
(SELECT MAX(SEQUENCE#) LOG_APPLIED
FROM V\$ARCHIVED_LOG WHERE DEST_ID=2
AND APPLIED='YES'
AND RESETLOGS_CHANGE#=(SELECT MAX(RESETLOGS_CHANGE#) FROM V\$ARCHIVED_LOG)) ;"
read  -p   LOGGAP
print -p  "EXIT"

echo "CHECKING CURRENT DATABASE ROLE..."
if [ "$DBROLE" = "PHYSICAL STANDBY"  ]
then
echo ""
echo "##################################################################"
echo "# ERROR ! ! ! NOT  A PRIMARY DATABASE, PLEASE RUN IT ON PRIMARY  #"
echo "##################################################################"
echo ""
exit
else
echo ""
echo "   OK   "
echo ""
fi

echo "CHECKING LOG GAP BETWEEN PRIMARY & STANDBY..."
if [ $LOGGAP -ne 0 ]
then
echo ""
echo "######################################################################"
echo "# ERROR ! ! !  PRIMARY & STANDBY ARE NOT IN SYNC, LOG GAP = $LOGGAP  #"
echo "######################################################################"
echo ""
exit
else
echo ""
echo "   OK   "
echo ""
fi

echo "CHECKING FILES OFFLINE OR RECOVER STATUS..."
if [ $FILESTAT -ne 0 ]
then
echo ""
echo "##################################################################"
echo "#  ERROR ! ! !  ONE OR MORE FILE/S OFFLINE OR IN RECOVER STATUS  #"
echo "##################################################################"
echo ""
exit
else
echo ""
echo "   OK   "
echo ""
fi

echo "CHECKING FILES IN BACKUP MODE..."
if [ $BKPSTAT -ne 0 ]
then
echo ""
echo "##################################################################"
echo "#      ERROR ! ! !  ONE OR MORE FILE/S ARE IN BACKUP MODE        #"
echo "##################################################################"
echo ""
exit
else
echo ""
echo "   OK   "
echo ""
fi

echo ""
echo "##################################################################"
echo "# ALL PRE-SWITCHOVER CHECKS SUCCEEDED... PROCEED WITH SWITCHOVER #"
echo "##################################################################"
echo ""
make_me_standby.sh

#!/bin/ksh

if [ "$1" = "" ]
then
echo ""
echo "##################################################################"
echo "# PLEASE ENTER ORACLE_SID AS THE FIRST COMMAND LINE ARGUMENT     #"
echo "#        SCRIPT USAGE : make_me_standby.sh           #"
echo "##################################################################"
echo ""
exit
fi

ORACLE_SID=`echo $1 |tr '[A-Z]' '[a-z]'`; export ORACLE_SID;

ls -l /var/opt/oracle/cronjobs/set$ORACLE_SID > /dev/null
if [ $? != 0 ]
then
echo ""
echo "##################################################################"
echo "#           ENVIRONMENT SETTING SET FILE NOT FOUND...!!!         #"
echo "#           /var/opt/oracle/cronjobs/set$ORACLE_SID              #"
echo "##################################################################"
echo ""
exit
fi

. /var/opt/oracle/cronjobs/set$ORACLE_SID

DB=`echo $1 |tr '[a-z]' '[A-Z]'`; export DB;

sqlplus  -s /nolog |&
print -p  "connect / as sysdba"
print -p  "set feedback off pause off pagesize 0 heading off verify off linesize 500 term off"
print -p  "set sqlprompt ''"
read  -p   JUNK
print -p  "SELECT DATABASE_ROLE DBROLE FROM V\$DATABASE;"
read  -p   DBROLE
print -p  "SELECT COUNT(FILE#) FILESTAT FROM V\$DATAFILE WHERE STATUS IN ('RECOVER', 'OFFLINE');"
read  -p   FILESTAT
print -p  "SELECT COUNT(FILE#) BKPSTAT FROM V\$BACKUP WHERE STATUS = 'ACTIVE';"
read  -p   BKPSTAT
print -p  "SELECT LOG_ARCHIVED-LOG_APPLIED LOGGAP
FROM (SELECT MAX(SEQUENCE#) LOG_ARCHIVED
FROM V\$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES'
AND RESETLOGS_CHANGE#=(SELECT MAX(RESETLOGS_CHANGE#)
FROM V\$ARCHIVED_LOG)),
(SELECT MAX(SEQUENCE#) LOG_APPLIED
FROM V\$ARCHIVED_LOG WHERE DEST_ID=2
AND APPLIED='YES'
AND RESETLOGS_CHANGE#=(SELECT MAX(RESETLOGS_CHANGE#) FROM V\$ARCHIVED_LOG)) ;"
read  -p   LOGGAP
print -p  "EXIT"

if [ "$DBROLE" = "PHYSICAL STANDBY"  ]
then
echo ""
echo "##################################################################"
echo "# ERROR ! ! ! NOT  A PRIMARY DATABASE, PLEASE RUN IT ON PRIMARY  #"
echo "##################################################################"
echo ""
exit
fi

if [ $LOGGAP -ne 0 ]
then
echo ""
echo "######################################################################"
echo "# ERROR ! ! !  PRIMARY & STANDBY ARE NOT IN SYNC, LOG GAP = $LOGGAP  #"
echo "######################################################################"
echo ""
exit
fi

echo "CHECKING FILES OFFLINE OR RECOVER STATUS..."
if [ $FILESTAT -ne 0 ]
then
echo ""
echo "##################################################################"
echo "#  ERROR ! ! !  ONE OR MORE FILE/S OFFLINE OR IN RECOVER STATUS  #"
echo "##################################################################"
echo ""
exit
fi

if [ $BKPSTAT -ne 0 ]
then
echo ""
echo "##################################################################"
echo "#      ERROR ! ! !  ONE OR MORE FILE/S ARE IN BACKUP MODE        #"
echo "##################################################################"
echo ""
exit
fi

echo ""
echo "##################################################################"
echo "#              ALL PRE-SWITCHOVER CHECKS SUCCEEDED...            #"
echo "       SWITCHING $DB TO STANDBY ROLE, PLEASE CONFIRM ...          "
echo "##################################################################"
echo ""
echo ""
echo "Continue? - Please enter 'Y' to proceed & 'N' to exit"
read ans
if [ "$ans" = 'Y' -o "$ans" = 'y' ]
then
sqlplus -s  /nolog < /tmp/make_me_standby.log
connect / as sysdba;
startup force;
alter database commit to switchover to standby with session shutdown;
shutdown immediate;
startup nomount;
alter database mount standby database;
select database_role from v\$database;
EOF
cat /tmp/make_me_standby.log
$ORACLE_HOME/bin/lsnrctl stop PRIMARY_$DB
else
echo "Quitting ....."
exit
fi

echo ""
echo "####################################################################"
echo "# PLEASE CONFIRM THAT THE STATUS OF DATABASE IS NOW "STANDBY"      #"
echo "#                                                                  #"
echo "# On OLD STANDBY Host please run the following script:         #"
echo "# /var/opt/oracle/dataguard/make_me_primary.sh                #"
echo "####################################################################"
echo ""
make_me_primary.sh

#!/bin/ksh

if [ "$1" = "" ]
then
echo ""
echo "##################################################################"
echo "#  PLEASE ENTER ORACLE_SID AS THE FIRST COMMAND LINE ARGUMENT    #"
echo "#         SCRIPT USAGE : make_me_primary.sh          #"
echo "##################################################################"
echo ""
exit
fi

ORACLE_SID=`echo $1 |tr '[A-Z]' '[a-z]'`; export ORACLE_SID;

ls -l /var/opt/oracle/cronjobs/set$ORACLE_SID > /dev/null
if [ $? != 0 ]
then
echo ""
echo "##################################################################"
echo "#           ENVIRONMENT SETTING SET FILE NOT FOUND...!!!         #"
echo "#           /var/opt/oracle/cronjobs/set$ORACLE_SID              #"
echo "##################################################################"
echo ""
exit
fi

. /var/opt/oracle/cronjobs/set$ORACLE_SID

DB=`echo $1 |tr '[a-z]' '[A-Z]'`; export DB;

sqlplus  -s /nolog |&
print -p  "connect / as sysdba"
print -p  "set feedback off pause off pagesize 0 heading off verify off linesize 500 term off"
print -p  "set sqlprompt ''"
read  -p   JUNK
print -p  "SELECT DATABASE_ROLE DBROLE FROM V\$DATABASE;"
read  -p   DBROLE
print -p  "exit"

if [ "$DBROLE" = "PRIMARY"  ]
then
echo ""
echo "##################################################################"
echo "#   ERROR ! ! ! NOT STANDBY DATABASE, PLEASE RUN IT ON STANDBY   #"
echo "##################################################################"
echo ""
exit
fi

echo ""
echo "##################################################################"
echo "#         SWITCHING $DB TO PRIMARY ROLE, PLEASE CONFIRM ...      #"
echo "##################################################################"
echo ""
echo "Continue? - Please enter 'Y' to proceed & 'N' to exit"
read ans
if [ "$ans" = 'Y' -o "$ans" = 'y' ]
then
sqlplus -s /nolog < /tmp/make_me_primary.log
connect / as sysdba;
alter database commit to switchover to primary with session shutdown;
shutdown immediate;
startup mount;
alter system set log_archive_dest_state_2=enable scope=both;
alter database set standby database to maximize performance;
alter database open;
select database_role from v\$database;
EOF
cat /tmp/make_me_primary.log
$ORACLE_HOME/bin/lsnrctl start PRIMARY_$DB
else
echo "Quitting ....."
exit
fi

echo "####################################################################"
echo "# PLEASE CONFIRM THAT THE STATUS OF DATABASE IS NOW "PRIMARY"      #"
echo "#                                                                  #"
echo "# On NEW STANDBY Host please run the following script:             #"
echo "# /var/opt/oracle/dataguard/start_recovery.sh                 #"
echo "####################################################################"
start_recovery.sh

#!/bin/ksh

if [ "$1" = "" ]
then
echo ""
echo "##################################################################"
echo "#   PLEASE ENTER ORACLE_SID AS THE FIRST COMMAND LINE ARGUMENT   #"
echo "#      SCRIPT USAGE : start_recovery.sh              #"
echo "##################################################################"
echo ""
exit
fi

ORACLE_SID=`echo $1 |tr '[A-Z]' '[a-z]'`; export ORACLE_SID;

ls -l /var/opt/oracle/cronjobs/set$ORACLE_SID > /dev/null
if [ $? != 0 ]
then
echo ""
echo "##################################################################"
echo "#           ENVIRONMENT SETTING SET FILE NOT FOUND...!!!         #"
echo "#           /var/opt/oracle/cronjobs/set$ORACLE_SID              #"
echo "##################################################################"
echo ""
exit
fi

. /var/opt/oracle/cronjobs/set$ORACLE_SID

DB=`echo $1 |tr '[a-z]' '[A-Z]'`; export DB;

sqlplus  -s /nolog |&
print -p  "connect / as sysdba"
print -p  "set feedback off pause off pagesize 0 heading off verify off linesize 500 term off"
print -p  "set sqlprompt ''"
read  -p   JUNK
print -p  "SELECT DATABASE_ROLE DBROLE FROM V\$DATABASE;"
read  -p   DBROLE
print -p  "exit"

if [ "$DBROLE" = "PRIMARY"  ]
then
echo ""
echo "##################################################################"
echo "#   ERROR ! ! ! NOT STANDBY DATABASE, PLEASE RUN IT ON STANDBY   #"
echo "##################################################################"
echo ""
exit
fi

echo ""
echo "##################################################################"
echo "#     STARTING RECOVERY FOR $DB  STANDBY, PLEASE CONFIRM ...     #"
echo "##################################################################"
echo ""
echo "Continue? - Please enter 'Y' to proceed & 'N' to exit"
read ans
if [ "$ans" = 'Y' -o "$ans" = 'y' ]
then
sqlplus -s /nolog < /tmp/start_recovery.log
connect / as sysdba;
recover managed standby database disconnect;
alter system set log_archive_dest_state_2=defer scope=both;
EOF
cat /tmp/start_recovery.log
ps -ef | grep ora_mrp0_$ORACLE_SID |grep -v grep > /dev/null
if [ $? != 0 ]
then
echo ""
echo "##################################################################"
echo "#           RECOVERY PROCESS NOT RUNNING... PLEASE CHECK         #"
echo "##################################################################"
echo ""
exit
else
echo "##################################################################"
echo "#           MRP PROCESS SUCESSFULLY STARTED                      #"
echo "##################################################################"
echo ""
echo "####################################################################"
echo "# 		SWITCHOVER COMPLETE                              #"
echo ""
echo "* Perform Database Post-Switchover Checklist!                      "
echo "####################################################################"
fi
else
echo "Quitting ....."
exit
fi

Posted in High Availability, Scripts, Unix | Tagged: , | Leave a Comment »

Unix – remove file with unseen characters

Posted by Arjun Raja on June 25, 2009

This works on AIX – Please test on other systems.

If a file name is vague and can’t be removed.

Ex – a file name has some hidden characters which prevents it’s removal as the name is not recognized by the rm command.

ls -lai sqlnet.log
19462 -rw-r—– 1 oraofsap dba 7741 Jun 4 13:14 sqlnet.log

look for number against file and rm number .

find . -inum 19462 -exec rm {} \;

Posted in Unix | Tagged: | Leave a Comment »

List and remove all files older than 30 days

Posted by Arjun Raja on June 22, 2009

 

 

find /u01/local/logs -mtime +30 -exec ls -l {} \;

find /u01/local/logs -mtime +30 -exec rm {} \;

 

Posted in Unix | Leave a Comment »

How to find files based on size in Unix

Posted by Gavin Soorma on June 21, 2009

For example – to find all files > 100 MB in size
find .  -size +200000 -exec ls -l {} \;

Posted in Unix | 2 Comments »

Cloning an existing ORACLE_HOME on Unix

Posted by Gavin Soorma on June 19, 2009

By using the procedure shown below, we can replicate a ‘master’ copy of an Oracle software installation on any number of target servers. Not only will it ensure that Oracle software installations are standardised and include all the required patches, but will save considerable time and effort required to stage the software on multiple servers.

 How to Clone an existing ORACLE HOME on UNIX

 Source

Hostname: devu014

Oracle Home: /u01/oracle/product/10204

 Target

Hostname: devu007

Oracle Home: /u02/oradata/product/10204

  Use ‘tar’ to create a zipped archive of the source Oracle software. Note: use the  ‘-p’ flag to preserve file permissions

 oracle@devu014:pwd

/u01/oracle/product

 oracle@devu014: tar -pcvf 10204.tar 10204

 On the target machine scp the tar file to the appropriate location and unzip the archive

 crashdb:/u02/oradata> mkdir product

crashdb:/u02/oradata> cd product

crashdb:/u02/oradata/product> scp -rp devu014:/u01/oracle/product/10204.tar .

oracle@devu014’s password:

10204.tar                                                             100% 4389MB  14.1MB/s   05:12

crashdb:/u02/oradata/product> ls

10204.tar

 crashdb:/u02/oradata/product> tar -xvf 10204.tar

 Note the file permissions of the source is preserved after the files are unzipped on the target

 crashdb:/u02/oradata/product/10204> cd bin

 crashdb:/u02/oradata/product/10204/bin> ls -l oracle

-rwsr-s–x   1 oracle   dba       133931237 Oct 31 09:54 oracle

 Use the clone.pl perl script to perform the installation process which will also perform the relink and update of the Oracle Inventory

 perl clone.pl ORACLE_HOME=”/u02/oradata/product/10204″ ORACLE_HOME_NAME=”10204_HOME”

 ./runInstaller -silent -clone -waitForCompletion  “ORACLE_HOME=/u02/oradata/product/10204″ “ORACLE_HOME_

NAME=10204_HOME” -noConfig -nowait

Starting Oracle Universal Installer…

 No pre-requisite checks found in oraparam.ini, no system pre-requisite checks will be executed.

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2008-11-05_12-20-31PM. Please wait ..

.Oracle Universal Installer, Version 10.2.0.4.0 Production

Copyright (C) 1999, 2008, Oracle. All rights reserved.

 You can find a log of this install session at:

 /u01/oracle/oraInventory/logs/cloneActions2008-11-05_12-20-31PM.log

………………………………………………………………………………………. 100% Done.

 

 

Installation in progress (Wednesday, November 5, 2008 12:21:22 PM WST)

………………………………………………………………                                                        72% Done.

Install successful

 

Linking in progress (Wednesday, November 5, 2008 12:22:04 PM WST)

Link successful

 

Setup in progress (Wednesday, November 5, 2008 12:28:27 PM WST)

Setup successful

 

End of install phases.(Wednesday, November 5, 2008 12:28:42 PM WST)

WARNING:

The following configuration scripts need to be executed as the “root” user.

#!/bin/sh

#Root script to run

/u02/oradata/product/10204/root.sh

To execute the configuration scripts:

    1. Open a terminal window

    2. Log in as “root”

    3. Run the scripts

 

The cloning of 10204_HOME was successful.

 Confirm that the Oracle Inventory has been updated with the cloned Oracle Home information

 crashdb:/u01/oracle/oraInventory/ContentsXML> ls

comps.xml      inventory.xml  libs.xml

 cat inventory.xml

 <?xml version=”1.0″ standalone=”yes” ?>

<!– Copyright (c) 2008 Oracle Corporation. All rights Reserved –>

<!– Do not modify the contents of this file by hand. –>

<INVENTORY>

<VERSION_INFO>

   <SAVED_WITH>10.2.0.4.0</SAVED_WITH>

   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>

</VERSION_INFO>

<HOME_LIST>

<HOME LOC=”/u01/app/oracle/gnu/product/92″ IDX=”1″/>

<HOME LOC=”/u01/oracle/product/10.2/kana” IDX=”2″/>

<HOME LOC=”/u01/oracle/product/11.0″ IDX=”3″/>

<HOME LOC=”/u01/oracle/agent10g” IDX=”5″/>

<HOME LOC=”/u02/oradata/product/10204″ IDX=”7″/>

</HOME_LIST>

</INVENTORY>

Posted in Unix | Leave a Comment »

Oracle 10g Pre Installation Validation for AIX 5L

Posted by Gavin Soorma on June 18, 2009

Oracle has provided a utility which we can run before doing an installation on AIX – it will check quite a few things for us and enable us to fix those before proceeding with an installation which could fail at a later stage.

There is a tar file validate.tar located in the $HOME directory on HQIBM102 – copy this file to the required machine and after extracting the files execute as shown below :

perl validate.pl <Output file>.txt

Example:

coekd:/opt1/oracle> perl validate.pl 10gr2_rdbms_aix_hcve_100705.txt

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Health Check/Validation (V 01.07.00)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

“Validation Rule Engine” will be run in following environment:

HOSTNAME    :
USERNAME    : oracle
ORACLE_SID  : coekd
ORACLE_HOME : /devdb02/ORACLE/product10gp

If this is not correct environment
Please set correct env parameters and rerun the program
Would you like to continue [Y]es/[N]o (Hit return for [Y]es) : Y
Executing Rules
~~~~~~~~~~~~~~~

Executing Rule: OS Certified?        – completed successfully.
Executing Rule: User in /etc/passwd? – completed successfully.
Executing Rule: Group in /etc/group? – completed successfully.
Executing Rule: Input ORACLE_HOME    – user INPUT Required.

Enter value for < Planned ORACLE_HOME location or if set >
(Hit return for [$ORACLE_HOME]) :

                                     – completed successfully.
Executing Rule: ORACLE_HOME valid?   – completed successfully.
Executing Rule: O_H perms OK?        – completed successfully.
Executing Rule: Umask set to 022?    – completed successfully.
Executing Rule: LDLIBRARYPATH unset? – completed successfully.
Executing Rule: LIBPATH unset?       – completed successfully.
Executing Rule: Other O_Hs in PATH?  – completed successfully.
Executing Rule: oraInventory perms   – completed successfully.
Executing Rule: /tmp adequate?       – completed successfully.
Executing Rule: Swap (in Mb)         – completed successfully.
Executing Rule: RAM (in Mb)          – completed successfully.
Executing Rule: SwapToRAM OK?        – completed successfully.
Executing Rule: Disk Space OK?       – completed successfully.
Executing Rule: AIXTHREAD_SCOPE=S?   – completed successfully.
Executing Rule: LINK_CNTRL is unset? – completed successfully.
Executing Rule: Got ld,nm,ar,make?   – completed successfully.
Executing Rule: ulimits OK?          – completed successfully.
Executing Rule: Got OS packages?     – completed successfully.
Executing Rule: Got OS patches?      – completed successfully.
Executing Rule: other OUI up?        – completed successfully.
Test “10gr2_rdbms_aix_hcve_100705″ executed at Wed Jan 16 10:30:57 2008
Test Results
~~~~~~~~~~~~

   ID NAME                 RESULT C VALUE
===== ==================== ====== = ========================================
   10 OS Certified?        PASSED = Certified with 10g RDBMS
   20 User in /etc/passwd? PASSED = userOK
   30 Group in /etc/group? PASSED = GroupOK
   40 Input ORACLE_HOME    RECORD   $ORACLE_HOME
   50 ORACLE_HOME valid?   PASSED = OHexists
   60 O_H perms OK?        PASSED = CorrectPerms
   70 Umask set to 022?    FAILED = UmaskNotOK
   80 LDLIBRARYPATH unset? FAILED = IsSet
   90 LIBPATH unset?       PASSED = UnSet
  100 Other O_Hs in PATH?  PASSED = NoneFound
  110 oraInventory perms   PASSED = oraInventoryOK
  120 /tmp adequate?       PASSED = TempSpaceOK
  130 Swap (in Mb)         RECORD   16384
  140 RAM (in Mb)          PASSED > 12288
  150 SwapToRAM OK?        PASSED = SwapToRAMOK
  160 Disk Space OK?       FAILED = NoSpace
  170 AIXTHREAD_SCOPE=S?   FAILED = AIXTHREAD_SCOPEBad
  175 LINK_CNTRL is unset? PASSED = LINK_CNTRLunset
  180 Got ld,nm,ar,make?   PASSED = ld_nm_ar_make_found
  190 ulimits OK?          PASSED = ulimitOK
  200 Got OS packages?     PASSED = All required OS packages are installed
  210 Got OS patches?      PASSED = PatchesFound
  220 other OUI up?        PASSED = NoOtherOUI

Please see the log file for detailed results and recommendations
Log FileName: 10gr2_rdbms_aix_hcve_100705_run_2580534/validate_result_10gr2_rdbms_aix_hcve_100705.log

Posted in Unix | Leave a Comment »

How to kill all similar processes in Unix

Posted by Gavin Soorma on June 18, 2009

In this example all opmn processes are being killed. This command is useful if we find a lot of processes still present at the OS level even after shutting down in this case the Oracle Application Server

ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}

Posted in Unix | Leave a Comment »