Friday, December 10, 2010

Linux Disk +performance+other conmands

to find if process is using port
--------------------------------
netstat -a | 7777
to get system log messgaes in aix
---------------------------------
errpt



To kill vnc session without locking of port
-----------------------------------------------------
Vncserver –kill :0

Oratab locations in solaris
-----------------------------------
/var/opt/oracle

using alias for big command
============================
The following command assigns the new compound command to an alias named nuke_oracle :
alias nuke_oracle="ps -ef|grep 'ora_'|grep -v grep|grep $ORACLE_SID|awk '{ print $2 }'|xargs kill -9"
preferably place it in .bash_profile

Some good aliases for oracle users:
--------------------------------------------
alias alert='tail -100 $DBA/$ORACLE_SID/bdump/alert_$ORACLE_SID.log|more'
alias arch='cd $DBA/$ORACLE_SID/arch'
alias bdump='cd $DBA/$ORACLE_SID/bdump'
alias cdump='cd $DBA/$ORACLE_SID/cdump'
alias pfile='cd $DBA/$ORACLE_SID/pfile'
alias rm='rm -i'
alias sid='env|grep ORACLE_SID'
alias admin='cd $DBA/admin'


Any alias can be removed easily with the Unix unalias command. For example, to remove the pfile alias, you would enter the command
unalias pfile.


set the below command in .profile to change the look of the prompt when on linux
--------------------------------------------------------------------------------------------------
PS1=" `hostname`*\${ORACLE_SID}-\${PWD} >"

cd /u01/oradata/PROD
The prompt will be :-
corphp*PROD-/u01/oradata/PROD >


To run job in background
--------------------------------
nohup run_sql.ksh > logfile.lst 2>&1 &

watching logfile
-------------------
tail -f logfile.lst


Send some part of text /data through email
----------------------------------------------------
cat ~oracle/.sh_history|mailx -s "Secret DBA Activity Report" donald.burleson@remote-dba.net


mail ora-600 to email
---------------------------
dbalist='burleson@frontiernet.net\
Don@remote-dba.net'
cat alert_$ORACLE_SID.log|grep 0600|mailx -s\
"$ORACLE_SID alert log message detected" $dbalist


crontab -l

The five execution-time elements are defined, in the order in which they appear, as follows:
minute
The minute of the hour (0-59)
hour
The hour of the day (0-23)
monthday
The day of the month (1-31)
month
The month of the year (1-12)
weekday
The day of the week (0=Sunday, 1=Monday, . . . 6=Saturday)
For


Disk Management commands
==============================
Disks exist in Unix as physical volumes and are carved into physical partitions (PPs). These physical partitions are, in turn, assigned to logical volumes. A logical volume is a chunk of storage that consists of one or more physical partitions. The logical volumes are then mapped onto Unix mountpoints. Several logical volumes can be used in a mount point, and a collection of such logical volumes is referred to as a volume group. A Unix mount point is like a directory name, and is used by you, the Oracle DBA, when allocating Oracle data files

The following lsvg -o
command can be used to display a list of volume groups with Unix mount points:

Now that you can see the volume groups, you can drill-in using lsvg -l to see details for a specific volume group:
>lsvg -l >name from above command>

Sar commands:
==============
sar -u
Shows CPU activity

sar -w
Shows swapping activity

sar -b
Shows buffer activity

sar -u a b
a=interval between reading
b=number of readings

vmstat
========
execute vmstat 3 and get a line of output every three seconds:
>vmstat 3

The critical vmstat values that you need to know about are as follows:
r
The run queue. When this value exceeds the number of CPUs, the server is experiencing a CPU bottleneck. (You can get the number of CPUs by entering lsdev -C|grep Process|wc -l.)
pi
The page-in count. Non-zero values typically indicate that the server is short on memory and that RAM is being written to the swap disk. However, non-zero values can also occur when numerous programs are accessing memory for the first time. To find out which is the case, check the scan rate (sr) column. If both the page-in count and the scan rate are non-zero, then you are short on RAM.
sr
The scan rate. If you see the scan rate rising steadily, you know that the paging daemon is busy allocating memory pages.
For AIX and HP-UX, vmstat also provides the following CPU values. These values are expressed as percentages and will sum to 100:
us
User CPU percentage
sy
System CPU percentage
id
Idle CPU percentage
wa
Wait CPU percentage
When the sum of user and system CPU percentages (us + sy) approaches 100, then the CPUs are busy, but not necessarily overloaded. The run queue value can indicate a CPU overload, but only when the run queue exceeds the number of CPUs on the server.
When wait CPU percentages (the wa values) exceed 20, then 20% or more of the processing time is waiting for a resource, usually I/O. It is common to see high wait CPU percentages during backups and exports, but they can also indicate an I/O bottleneck.



STEPS TO AUTOMATE VMSTAT REPORTS IN ORACLE
===============================================
DROP TABLE MON_VMSTATS;
CREATE TABLE MON_VMSTATS
(
START_DATE DATE,
DURATION NUMBER,
SERVER_NAME VARCHAR2(20),
RUNQUE_WAITS NUMBER,
PAGE_IN NUMBER,
PAGE_OUT NUMBER,
USER_CPU NUMBER,
SYSTEM_CPU NUMBER,
IDLE_CPU NUMBER,
WAIT_CPU NUMBER
)
tablespace dba_perf
STORAGE (INITIAL 500K
NEXT 500K
PCTINCREASE 0)
;

get_vmstat.ksh
==============
#!/bin/ksh
# First, we must set the environment.
ORACLE_SID=BURLESON
export ORACLE_SID
ORACLE_HOME=`cat /etc/oratab|\
grep \^$ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
MON=`echo ~oracle/mon`
export MON
SERVER_NAME=`uname -a|awk '{print $2}'`
typeset -u SERVER_NAME
export SERVER_NAME
# Sample every five minutes (300 seconds).
SAMPLE_TIME=300
while true
do
vmstat ${SAMPLE_TIME} 2 > /tmp/msg$$
# This script is intended to run starting at
# 7:00 AM EST until midnight EST.
cat /tmp/msg$$|sed 1,4d | awk '{ \
printf("%s %s %s %s %s %s %s\n", $1, $6, $7,\
$14, $15, $16, $17) }' | while read RUNQUE\
PAGE_IN PAGE_OUT USER_CPU SYSTEM_CPU\
IDLE_CPU WAIT_CPU
do
$ORACLE_HOME/bin/sqlplus -s / <insert into mon_vmstats values (
sysdate,
$SAMPLE_TIME,
'$SERVER_NAME',
$RUNQUE,
$PAGE_IN,
$PAGE_OUT,
$USER_CPU,
$SYSTEM_CPU,
$IDLE_CPU,
$WAIT_CPU
);
EXIT
EOF
done
done


GETTING report
================
set pages 9999;
set feedback off;
set verify off;
column my_date heading 'date' format a20
column c2 heading runq format 999
column c3 heading pg_in format 999
column c4 heading pg_ot format 999
column c5 heading usr format 99
column c6 heading sys format 99
column c7 heading idl format 99
column c8 heading wt format 99
select
to_char(start_date,'day') my_date,
-- avg(runque_waits) c2
-- avg(page_in) c3,
-- avg(page_out) c4,
avg(user_cpu + system_cpu) c5,
-- avg(system_cpu) c6,
-- avg(idle_cpu) c7,
avg(wait_cpu) c8
from
mon_vmstats
group BY
to_char(start_date,'day')
;



the check_parms.ksh script requires two parameters: an Oracle SID and a numeric value that must be greater than 100. The if statements cause the script to terminate if the required parameters are not passed.

# Exit if no first parameter $1.
if [ -z "$1" ]
then
echo "Usage: check_parms.ksh \
<#_days> (where value is > 100)"
exit 99
fi
# Exit if no second parameter $2.
if [ -z "$2" ]
then
echo "Usage: check_parms.ksh \
<#_days> (where value is > 100)"
exit 99
fi

# Exit if parm is not greater than 100.
tmp=`expr $2` # Convert string to number.
if [ $tmp -lt 101 ]
then
echo
echo "Argument two is less than 100.\
Aborting Script."
echo
exit 99
fi


Script to check if oracle user is only the one executing the script

if [ `whoami` != 'oracle' ]
then
echo "Error: You must be oracle to execute."
exit 99
fi

script to validate if right oracle sid has been passed

TEMP=`cat /etc/oratab|grep \^$1:|\
cut -f1 -d':'|wc -l`
tmp=`expr TEMP` # Convert string to number.
if [ $tmp -ne 1 ]
then
echo "Your input $1 is not a valid ORACLE_SID."
exit 99
fi

Linux system info commands

Getting system info
========================
to get info of RAM of servers-
-----------------------------
cat /proc/meminfo

to get info on CPU of servers
-------------------------------
cat /proc/cpuinfo

find Operation System Version of Solaris
-------------------------------------------
uname -a

You will see output like
For Solaris SunOS servername 5.8 Generic_117350-23 sun4u sparc SUNW,Sun-Fire-V240
Which means solaris 5.8

find Operation System Version of Linux
------------------------------------------
cat /etc/*release*
You will see output like
Red Hat Enterprise Linux AS release 3 (Taroon Update 6)

lsb_release -d

To check if the OS is 32 bit or 64 bit on Solaris?
-------------------------------------------------------
isainfo -v
If you see out put like
32-bit sparc applications
That means your O.S. is only 32 bit but if you see output like

The below o/p means your o.s. is 64 bit & can support both 32 & 64 bit applications
64-bit sparcv9 applications
32-bit sparc applications

find RAM size in kb’s
------------------------
root@erptest01:/$ bootinfo -r
8388608

Swap space available:
---------------------
root@erptest01:/$ swap -l
device maj,min total free
/dev/paging00 10, 15 4096MB 2328MB
/dev/hd6 10, 2 4096MB 2327MB
root@erptest01:/$

Find if Kernel is 32 or 64 bit
----------------------------------
bootinfo –K

file descriptors available for user applmgr
rptest01:/dsslti/product# ulimit -a
time(seconds) unlimited
file(blocks) unlimited
data(kbytes) unlimited
stack(kbytes) 4194304
memory(kbytes) unlimited
coredump(blocks) unlimited
nofiles(descriptors) 1024
erptest01:/dsslti/product#
erptest01:/dsslti/product#
erptest01:/dsslti/product# ulimit -n
1024
erptest01:/dsslti/product#


all the devices connectd to aix server
----------------------------------------
lsdev -C

in AIX, you use the lsattr command to view settings for kernel parameters. For example:
>lsattr -El sys0
maxbuf 20 Maximum number of pages in block...
maxmbuf 0 Maximum Kbytes of real memory al...
maxuproc 200 Maximum number of PROCESSES allo...
iostat true Continuously maintain DISK I/O h...
realmem 3137536 Amount of usable physical mem...
modelname IBM,9076-WCN Machine name


display RAM size in AIX
-------------------------
lsdev -C|grep mem
u will gte o/p like
mem0 Available Memory

now run the command
lsattr -El mem0
size 3064 Total amount of physical memory in Mbytes
goodsize 3064 Amount of usable physical memory in Mbytes

to get number of cps's on server
-----------------------------------
lsdev -C|grep Process|wc -l

utility to change kernel parameters:
-----------------------------------
SMIT

to get info on performance of each disk
---------------------------------------
iostat

Linux basic commands

To search particular word
----------------------------------
find . -print|xargs grep -i "ARXTWMAI"

To find files as per size, age
--------------------------------------------------------
find . -type f -mtime +2 -name '*.*' -print
find . -name '*.*' -size +15000k -mtime +20 -print
find . -name '*.*' -mtime +20 -print | args ls

To move/delete files as per age, size
-------------------------------------------
#by age
find . -type f -mtime +1 -name '*mmon*' -print |xargs rm –rf
nohup find . -mtime +x -type f -exec mv {} /psgdsi/applcsf/out_old \; &
find /racp02/u01/app/oracle/eb01qdb/10.2.0RAC/admin/eb01q1_usmliu61/bdump -name 'cdmp*' -mmin +120 -exec rm -fr {}
find . -mmin +5 -mmin -10 # find files modified between6 and 9 minutes ago

#by size
find . -name '*.*' -size +50000k -print | xargs rm –rf

# age and size
find . -name '*.*' -size +5000k -mtime +30 –print

find . -name '*.*' -size +500k

Identify process & kill
-----------------------
top cpu time consuming processes
ps -ef|sort +6|tail

Count all process connected to oracle db(excluding background ones)
-----------------------------------------------------------------
ps -ef|grep ecstest |grep -v grep|grep ora_| wc -l

to kill all oracle instances background processes
--------------------------------------------------
ps -ef|grep "java"|grep -v grep|awk '{print $2}'|xargs -i kill -9 {}

kill processes of single user
----------------------------
pkill -u username
pkill -u asceb05

to kill all processes of a particular user
-------------------------------------------
ps -ef | grep apdchpgi | grep -v grep | grep -v ksh | grep -v UID | grep -v bash | grep -v fu | grep -v xterm | awk '{print $2}' | xargs kill –9




Tar commands
--------------------------
go in appltop and give
nohup tar -cvf - * | gzip > /rh89/u02/app/aibmut1/aibmut1appl.tar.gz &


tar and gzip at same time
==========================
go in appltop and give
nohup tar -cvf - * | gzip > /rh89/u02/app/aibmut1/aibmut1appl.tar.gz &

:1,$ s/ecsqual1/ecsqual3
to replace ecsqual1 by ecsqual3