Mar 7, 2008

Useful Unix commands for DBAs

Useful Unix commands for DBAs

Here are some useful Unix/Linux commands which you will find handy in your day-to-day life as an Oracle DBA. Most of these commands are just query commands and will not change / alter anything on the operating system. Commands whch can change / alter anything at operating system level are denoted with Caution sign. However please use due diligence in using these commands. Please also note that the output may differ depending on the version and flavor of Unix that you are using.

Do give your feedback, suggestions and contribution to improve this page.

Memory

Display total RAM (Memory) on the server

Tru64 Unix uerf –r 300 | grep –i mem
Solaris prtconf | grep –i mem
Linux free
HP-UX swapinfo –tm
AIX lsdev –C | grep mem
lsattr –El

$ lsdev -C | grep mem

Output on AIX

mem0 Available 00-00 Memory

$ lsattr -El mem0

size 1536 Total amount of physical memory in Mbytes False
goodsize 1536 Amount of usable physical memory in Mbytes False

Display paging utilization

lsps –a (provides a snapshot of the current utilization of each of the paging spaces on a system)

Output on AIX

Page Space Physical Volume Volume Group Size %Used Active Auto Type
paging01 hdisk4 dbvg2 2560MB 9 yes yes lv
hd6 hdisk0 rootvg 512MB 42 yes yes lv

lsps -s (provides a summary of the total active paging space and its current utilization)

Output on AIX

Total Paging Space Percent Used
4096MB 1%

Display memory utilization on Linux

To read memory usage in Linux, please use "free" command. As you said, you may noticed that most the memory had been used, here is the example,

# free

Output on Linux
total used free shared buffers cached
Mem: 26871344 15263128 11608216 0 374036 13635804
-/+ buffers/cache: 1253288 25618056
Swap: 54524600 0 54524600

"cached" memory basically are free to be used. The Linux philosophy is keeping resource idle/wasted as little as it can. Keeping the cache means that if something needs the same data again. You will notice the cached is very little during the system just rebooted, but it keeps growing if you leave it running for days.

If you want to know the memory used, please read the second line. The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications. So, for this example, we still have 25GB memory free to be used.

The bottom line is as far as swap is not being used (third line from the example), memory usage isn't impacting system performance. Refer to URL for more information. http://www.redhat.com/advice/tips/meminfo.html

Which process is using memory at O/S (AIX)

The following command displays the memory usage statistics for the top ten processes. If you do not specify a number, it will display all the processes currently running in this system.

# svmon -Pau 10

Output on AIX

Pid Command Inuse Pin Pgspace 15012 maker4X.exe 4783 1174 4781
2750 X 4353 1178 5544
15706 dtwm 3257 1174 4003
17172 dtsession 2986 1174 3827
21150 dtterm 2941 1174 3697
17764 aixterm 2862 1174 3644
2910 dtterm 2813 1174 3705
19334 dtterm 2813 1174 3704
13664 dtterm 2804 1174 3706
17520 aixterm 2801 1174 3619

Pid: 15012
Command: maker4X.exe

Segid Type Description Inuse Pin Pgspace Address Range

1572 pers /dev/hd3:62 0 0 0 0..-1
142 pers /dev/hd3:51 0 0 0 0..-1
1bde pers /dev/hd3:50 0 0 0 0..-1
2c1 pers /dev/hd3:49 1 0 0 0..7
9ab pers /dev/hd2:53289 1 0 0 0..0
404 work kernel extension 27 27 0 0..24580
1d9b work lib data 39 0 23 0..607
909 work shared library text 864 0 7 0..65535
5a3 work sreg[4] 9 0 12 0..32768
1096 work sreg[3] 32 0 32 0..32783
1b9d work private 1057 1 1219 0..1306 : 65307..65535
1af8 clnt 961 0 0 0..1716
0 work kernel 1792 1146 3488 0..32767 : 32768..65535

Pid 15012 is the process ID that has the highest memory usage. The Command indicates the command name, in this case maker4X.exe. The Inuse column (total number of pages in real memory from segments that are used by the process) shows 4783 pages (each page is 4 KB). The Pin column (total number of pages pinned from segments that are used by the process) shows 1174 pages. The Pgspace column (total number of paging-space pages that are used by the process) shows 4781 pages.

Displaying Allocated RAM Memory Segments in Unix

ipcs –pmb (Inter process control system)

$ ipcs -pmb

Output on AIX

IPC status from /dev/mem as of Fri Aug 2 15:20:20 WAUST 2002
T ID KEY MODE OWNER GROUP SEGSZ CPID LPID
Shared Memory:
m 131072 0x58000932 --rw-rw-rw- root system 134217728 6990 47580
m 1 0x0d003187 --rw-rw-rw- root system 1440 11872 27654
m 131074 0xffffffff --rw------- root system 104857600 45198 45198
m 2621443 0x05c17710 --rw-r----- crpor11i oradba 368291840 25196 29384
m 1310724 0x50942e5c --rw-r----- devor11i oradba 405147648 25450 46580

Identify all held RAM memory segments & release the RAM memory from Unix

ipcs –pmb (To check for held memory)

Output on AIX

IPC status from /dev/mem as of Fri Aug 2 14:27:14 WAUST 2002
T ID KEY MODE OWNER GROUP SEGSZ CPID LPID
Shared Memory:
m 131072 0x58000932 --rw-rw-rw- root system 134217728 6990 47580
m 1 0x0d003187 --rw-rw-rw- root system 1440 11872 7812
m 131074 0xffffffff --rw------- root system 104857600 45198 45198
m 2621443 0x05c17710 --rw-r----- crpor11i oradba 368291840 25196 39296
m 1310724 0x50942e5c --rw-r----- devor11i oradba 405147648 25450 39290

caution ipcrm –m 1310724 (To release the memory)

CPU

Displaying the No. of CPU processors in UNIX

AIX lsdev –C | grep Process | wc –l
HP-UX ioscan –C processor | grep processor | wc –l
Solaris psrinfo –v | grep “Status of Processor” | wc –l
Linux cat /proc/cpuinfo | grep processor | wc –l

Display top CPU Consumers with ps

$ ps –ef | sort +7 | tail

Output on AIX

devor11i 30420 1 0 02:36:10 - 0:05 oracleDEV (LOCAL=NO)
devor11i 33088 1 0 02:36:10 - 0:06 oracleDEV (LOCAL=NO)
devor11i 41300 1 0 02:36:06 - 0:01 oracleDEV (LOCAL=NO)
devor11i 48032 1 2 13:46:19 - 0:02 oracleDEV (LOCAL=NO)
crpor11i 18498 7812 2 14:12:49 pts/0 0:00 ps -ef
crpap11i 31850 1 0 06:17:06 - 0:00 rwmts60 name=REP60_CRP
devap11i 32832 1 0 02:35:31 - 0:00 rwmts60 name=REP60_DEV
crpor11i 48448 7812 1 14:12:49 pts/0 0:00 sort +7
crpor11i 39190 7812 0 14:12:49 pts/0 0:00 tail
root 15182 9030 0 13:24:19 - 0:00 telnetd -a

ps auxgw | sort +2 | tail

The third column of this listing (%CPU) shows the percentage of CPU used.

Output on AIX

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND

crpor11i 42412 0.1 1.0 29420 16164 - A 06:15:58 0:30 ora_qmn0_CRP
devor11i 48032 0.1 1.0 30252 16036 - A 13:46:19 0:03 oracleDEV (LOCAL
=NO)
crpor11i 27526 0.1 1.0 30372 17336 - A 12:53:46 0:10 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
root 2888 0.2 0.0 164 36 - A Jul 20 73:42 /usr/sbin/syncd 60 crpor11i 34816 0.3 1.0 31916 18888 - A 13:43:29 0:12 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
root 45198 0.3 7.0 175204 103064 - A Jul 24 67:10 dsmserv quiet
crpor11i 43620 0.4 1.0 32264 19236 - A 13:58:23 0:08 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
root 774 47.1 0.0 12 7492 - A Jul 20 17411:25 kproc
root 516 48.0 0.0 12 7492 - A Jul 20 17723:26 kproc

ps augxww | grep “RSS| “ | head

Output on AIX

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND
root 516 48.0 0.0 12 7492 - A Jul 20 17725:33 kproc
root 774 47.1 0.0 12 7492 - A Jul 20 17413:32 kproc
crpor11i 46568 1.9 1.0 29768 16728 - A 14:16:18 0:02 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
crpor11i 43620 0.4 1.0 32264 19236 - A 13:58:23 0:08 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
crpor11i 34816 0.3 1.0 31924 18896 - A 13:43:29 0:14 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))
root 45198 0.3 7.0 175204 103012 - A Jul 24 67:10 dsmserv quiet
root 2888 0.2 0.0 164 36 - A Jul 20 73:42 /usr/sbin/syncd 60 root 47586 0.1 0.0 1296 212 - A Jul 24 26:07 dtgreet
crpor11i 27526 0.1 1.0 30372 17336 - A 12:53:46 0:10 oracleCRP (DESCR
IPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))

To display processes consuming CPU% & elapsed time

ps -aef -o ruser,pid,pcpu,args,etime,

Output on AIX

app_prd 6504490 0.1 f60runm webfile=5,13090,ebspap1_9000_ebspr 04:05:37
app_prd 6512660 0.0 f60runm webfile=5,14982,ebspap1_9000_ebspr 01:18
app_prd 6516842 0.0 f60runm webfile=5,14058,ebspap1_9000_ebspr 02:11:32
app_prd 6520950 0.0 f60runm webfile=5,13662,ebspap1_9000_ebspr 02:50:33
app_prd 6533186 0.2 f60runm webfile=5,14771,ebspap1_9000_ebspr 30:17
app_prd 6541388 0.0 f60runm webfile=5,14886,ebspap1_9000_ebspr 15:33
app_prd 6557804 0.6 f60runm webfile=5,14865,ebspap1_9000_ebspr 18:29
app_prd 6562028 0.0 /a01/app/app_prd/product/ebsprdiAS/Apache/ 2-13:42:42
app_prd 6570158 0.1 f60runm webfile=5,12980,ebspap1_9000_ebspr 04:38:38
app_prd 6574202 0.0 d2ls60 9100 9200 2-13:42:30
app_prd 6582450 0.0 /a01/app/app_prd/product/ebsprdiAS/Apache/ 2-13:42:39
app_prd 6586452 0.1 f60runm webfile=5,14453,ebspap1_9000_ebspr 01:17:47

Monitoring CPU Run-Queue with sar command

sar -qu 5 5 (ATT)

Output on AIX

10:58:02 runq-sz %runocc swpq-sz %swpocc
%usr %sys %wio %idle
10:58:07 2.8 100
0 2 4 94


Note: The CPU is spending most (94%) of its time in idle mode. This CPU is not being heavily used at all. Generally it is alright to have a CPU that is 0% idle as long as the RUN-QUEUE is not too large. In this case the run queue is 100% occupied (there is always a process waiting to be run) and there are an average of 2.8 processes waiting to be run in the RUN-QUEUE. You want to keep the RUN-QUEUE under 5-6 for a single CPU machine. If the run queue gets any larger that those values you will see some performance degradation. Two solutions to this are:

Obtain a faster processor
Use more CPU's.

Avoid overloading your CPU. Response time on your machine will suffer if it is overloaded. Try to keep the run queue 100% occupied and have less that 6 processes waiting to be run for one CPU. This changes as you add more CPU's or a faster CPU. You may also want to avoid the CPU spending most of its time (more than 50%) in system mode. This may indicate that you are spending too much time in kernel mode servicing interrupts, swapping processes etc.

Disk

To list the disks/tapes on the Server

To list the tapes on your system

$ lsdev -C -c tape

Output on AIX

rmt0 Available 40-60-00-0,0 SCSI 4mm Tape Drive
smc0 Available 21-08-00-5,0 IBM 3581 Tape Medium Changer
rmt1 Available 21-08-00-6,0 IBM 3580 Ultrium Tape Drive

To list the disks on your system

$ lsdev -C -c disk

hdisk0 Available 40-60-00-4,0 16 Bit LVD SCSI Disk Drive
hdisk1 Available 40-60-00-8,0 16 Bit LVD SCSI Disk Drive
hdisk2 Available 11-08-00-0,0 SCSI Disk Array RAID 5
hdisk3 Available 11-08-00-1,0 SCSI Disk Array RAID 5
hdisk4 Available 14-08-L SSA Logical Disk Drive
hdisk5 Available 31-08-L SSA Logical Disk Drive
hdisk6 Available 31-08-L SSA Logical Disk Drive
hdisk7 Available 14-08-L SSA Logical Disk Drive
hdisk8 Available 14-08-L SSA Logical Disk Drive

Viewing UNIX volume groups

$ lsvg –o

-o Lists only the active volume groups (those that are varied on). An active volume group is one that is available for use.

Output on AIX

appvg1
rootvg

lsvg –l

For details on a specific volumne group, you can use lsvg –l, passing the volume group name as a parameter

$ lsvg -l rootvg

Output on AIX

rootvg:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
hd5 boot 1 2 2 closed/syncd N/A
hd6 paging 16 32 2 open/syncd N/A
hd8 jfslog 1 2 2 open/syncd N/A
hd4 jfs 5 10 2 open/syncd /
hd2 jfs 42 84 2 open/syncd /usr
hd9var jfs 3 6 2 open/syncd /var
hd3 jfs 36 72 2 open/syncd /tmp
hd1 jfs 3 6 2 open/syncd /home
pridumplv sysdump 5 5 1 open/syncd N/A
softwarelv jfs 8 8 1 closed/syncd /software
scriptslv jfs 8 8 1 open/syncd /scripts

lsvg –o | xargs lsvg –l

The xargs UNIX command is used to pass the complete output of the first command (lsvg –o in this case) one at a time to the lsvg –l command.

$ lsvg -o | xargs lsvg -l

Output on AIX

appvg1:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
orastagelv jfs 122 122 1 open/syncd /orastage
loglv00 jfslog 1 1 1 open/syncd N/A
crpr11ilv jfs 160 160 1 open/syncd /crpr11i
prdap11i jfs 120 120 1 open/syncd /prdap11i
paging00 paging 20 20 1 open/syncd N/A
testbkup jfs 120 120 1 closed/syncd /testbkup

rootvg:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
hd5 boot 1 2 2 closed/syncd N/A
hd6 paging 16 32 2 open/syncd N/A
hd8 jfslog 1 2 2 open/syncd N/A
hd4 jfs 5 10 2 open/syncd /
hd2 jfs 42 84 2 open/syncd /usr
hd9var jfs 3 6 2 open/syncd /var
hd3 jfs 36 72 2 open/syncd /tmp
hd1 jfs 3 6 2 open/syncd /home
pridumplv sysdump 5 5 1 open/syncd N/A
softwarelv jfs 8 8 1 closed/syncd /software
scriptslv jfs 8 8 1 open/syncd /scripts

Display Unix Mount Points

df –k

A UNIX mount point is the UNIX location of disk storage. As a Oracle DBA you should know the mapping between your physical disks, logical volumes and mount points.

$ df -k

Output on AIX

Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 163840 138700 16% 1376 2% /
/dev/hd2 1376256 144952 90% 31234 10% /usr
/dev/hd9var 98304 89588 9% 457 2% /var
/dev/hd3 1179648 968404 18% 468 1% /tmp
/dev/hd1 98304 72612 27% 256 2% /home
/dev/orastagelv 15990784 3335864 80% 21256 1% /orastage
/dev/crpr11ilv 20971520 10737752 49% 85411 2% /crpr11i
/dev/scriptslv 262144 105352 60% 90 1% /scripts
/dev/prdap11i 15728640 5718636 64% 84626 3% /prdap11i

Show mount points for a Disk

$ lspv

Output on AIX

hdisk0 000780ffaac20aee rootvg
hdisk1 000780ffdb900f40 rootvg
hdisk2 000780ffdde9b3e7 dbvg1
hdisk3 000780dfddf63eb8 appvg1
hdisk4 000780dff8276946 dbvg2
hdisk5 none None

lspv –l

You can use the physical volume command lspv to display disk mount points in IBM AIX.

$ lspv -l hdisk0

Output on AIX

hdisk0:
LV NAME LPs PPs DISTRIBUTION MOUNT POINT
hd5 1 1 01..00..00..00..00 N/A
hd6 16 16 00..16..00..00..00 N/A
pridumplv 5 5 00..05..00..00..00 N/A
scriptslv 8 8 00..08..00..00..00 /scripts
hd8 1 1 00..00..01..00..00 N/A
hd4 5 5 00..00..05..00..00 /
hd2 42 42 00..00..42..00..00 /usr
hd9var 3 3 00..00..03..00..00 /var
hd3 36 36 00..00..36..00..00 /tmp
hd1 3 3 00..00..03..00..00 /home

Miscellenous

To see the Server Configuration

$ prtconf

Output on AIX

System Model: IBM,7026-6H1
Processor Type: PowerPC_RS64-IV
Number Of Processors: 4
Memory Size: 6144MB
Good Memory Size: 6144MB
Firmware Version: IBM,M2P030828_condor_
Console Login: enable
Auto Restart: true
Full Core: true

Network Information
Host Name: dbsrv
IP Address: 137.40.1.100
Sub Netmask: 255.255.254.0
Gateway: 137.40.1.1
Name Server: 137.40.1.50
Domain Name: asagarwal.com

Paging Space Information
Total Paging Space: 4096MB
Percent Used: 1%

Displaying Server Kernel Values (AIX)

$ lsdev –C

This command will display all of the attached components including disk, memory, CPUs, buses and other hardware components.

Output on AIX

sys0 Available 00-00 System Object
sysplanar0 Available 00-00 System Planar
pci0 Available 00-fff7f09000 PCI Bus
pci1 Available 00-fff7f0a000 PCI Bus
pci2 Available 00-fff7f08000 PCI Bus
isa0 Available 10-80 ISA Bus
sa0 Available 01-S1 Standard I/O Serial Port
sa1 Available 01-S2 Standard I/O Serial Port
sa2 Available 01-S3 Standard I/O Serial Port
sa3 Available 01-S4 Standard I/O Serial Port
siokma0 Available 01-K1 Keyboard/Mouse Adapter
fda0 Available 01-D1 Standard I/O Diskette Adapter
pci3 Available 10-58 PCI Bus
scsi0 Available 11-08 Wide/Fast-20 SCSI I/O Controller
pci4 Available 10-5a PCI Bus
pci5 Available 10-5c PCI Bus
pci6 Available 10-5e PCI Bus
pci7 Available 20-58 PCI Bus
ssa0 Available 21-08 IBM SSA 160 SerialRAID Adapter (14109100)
pci8 Available 20-5a PCI Bus
mg20 Available 24-08 GXT130P Graphics Adapter
pci9 Available 20-5b PCI Bus
pci10 Available 20-5c PCI Bus
pci11 Available 20-5e PCI Bus
……………….
……………….
……………….

To see the base values for the server in AIX

$ lsattr –El sys0

This is useful for displaying UNIX kernel variables that are used by Oracle such as maxuproc and maxbuf

Output on AIX

keylock normal State of system keylock at boot time False
maxbuf 20 Maximum number of pages in block I/O BUFFER CACHE True
maxmbuf 0 Maximum Kbytes of real memory allowed for MBUFS True
maxuproc 128 Maximum number of PROCESSES allowed per user True
autorestart false Automatically REBOOT system after a crash True
iostat false Continuously maintain DISK I/O history True
realmem 1572864 Amount of usable physical memory in Kbytes False
conslogin enable System Console Login False
fwversion IBM,M2P011204 Firmware version and revision levels False
maxpout 0 HIGH water mark for pending write I/Os per file True
minpout 0 LOW water mark for pending write I/Os per file True
fullcore false Enable full CORE dump True

Displaying System Log Messages

$ errpt –a | more

Output on AIX

----------------------------------------------------------
LABEL: CORE_DUMP
IDENTIFIER: C60BB505

Date/Time: Thu Aug 1 23:40:47
Sequence Number: 13368
Machine Id: 000780DF4C00
Node Id: db11i
Class: S
Type: PERM
Resource Name: SYSPROC

Description
SOFTWARE PROGRAM ABNORMALLY TERMINATED

Probable Causes
SOFTWARE PROGRAM

User Causes
USER GENERATED SIGNAL

Recommended Actions
CORRECT THEN RETRY

How to Tell if OS is a 32-Bit or 64-Bit

AIX

lslpp -l bos.64bit

Fileset Level State Description
----------------------------------------------------------------------------
Path: /usr/lib/objrepos
bos.64bit 4.3.3.79 APPLIED Base Operating System 64 bit
Runtime

Path: /etc/objrepos
bos.64bit 4.3.3.79 APPLIED Base Operating System 64 bit
Runtime

You will also need to check if the hardware is 32/64 bit enabled. You can do this by issuing 'bootinfo -y' as the unix root user.

# bootinfo -y
64

Example of 32-bit AIX OS

lslpp -l bos.64bit
lslpp: Fileset bos.64bit not installed.

HP-UX

getconf KERNEL_BITS
64

Linux – RedHat

# uname -i
i386

# uname -i
X86_64

To check the OS Version

AIX

oslevel –r

HP-UX / Linux

uname –a

To see the previous logons and logoffs

last

The last command is generally used to display, in reverse chronological order, all previous logins and logoffs recorded in the /var/adm/wtmp file.

oracle pts/0 10.81.1.92 Jun 23 13:43 still logged in.
oracle pts/0 10.81.1.92 Jun 16 10:37 - 10:51 (00:13)
oracle pts/0 10.81.1.92 Jun 15 08:34 - 09:09 (00:35)
ashish pts/1 10.81.1.110 Jun 14 11:24 - 11:24 (00:00)
root ftp 137.40.68.207 Jun 14 10:53 - 10:54 (00:00)
root ftp cch70 Jun 14 10:33 - 10:35 (00:01)
root ftp 10.81.1.110 Jun 14 10:29 - 10:30 (00:01)
ashish pts/1 10.81.1.110 Jun 14 10:24 - 11:24 (01:00)
ashish pts/0 10.81.1.110 Jun 14 10:24 - 10:24 (00:00)
root ftp 10.81.1.110 Jun 14 10:21 - 10:23 (00:02)
ashish pts/1 10.81.1.110 Apr 20 09:57 - 09:57 (00:00)

Some Examples

The last command can also be used to determine when the system was last shut down. The syntax of the command follows:

# last shutdown

If you want to find out when the user root logged on and off from the console, enter the command:

# last root console

To see When the Server was started

uptime

01:57PM up 2 days, 22:40, 1 user, load average: 1.11, 0.57, 0.40

To shutdown the Server

Cautionshutdown –Fr

This command will shutdown and Fast Restart the Server.

At times, it may be necessary to properly close down all the applications and other user processes without issuing a kill command to end the processes. You can achieve this by adding your desired commands and actions to a file named /etc/rc.shutdown. The /etc/rc.shutdown file is checked each time a shutdown command is issued. If the file exists, it will be run; otherwise, the system will perform a regular shutdown depending on the flags that are used to bring the system down.

/etc/rc.shutdown must be set as executable before it can called by the /usr/sbin/shutdown script.

To kill all the oracle process from OS

Cautionps –ef | grep “ora_” | grep –v grep | awk ‘{print $2}’ | -exec kill –9 {} \ ;

Show number of active Oracle dedicated Connection Users

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

Remarks: If you are not using multithreaded server this command will give you an accurate count of the number of Oracle connections on the Unix Server

Killing Stubborn Unix Tasks

Cautioncat /dev/null > /dev/ttyname kill –9

Remarks: This command is indispensable when killing stubborn UNIX tasks.

vmstat

r (run queue)
the run queue value shows the number of tasks executing and waiting for cpu resources. When this number exceeds the number of CPUs on the server, a CPU bottleneck exists, and some tasks are waiting for execution.
Pi (page in)
a page in operation occurs when the server is experiencing a shortage of RAM memory. While all virtual memory server will page out to the swap disk, page in operations show that the server has exceeded the available RAM storage. Any nonzero value for pi indicates excessive activity as RAM memory contents are read in from the swap disk
Us (user CPU)
this is the amount of CPU that is servicing the user tasks
Sy (system CPU)
this is the percentage of CPU being used to service system tasks.
Id (idle)
this is the percentage of CPU that is idle
Wa (wait)
this shows the percentage of CPU that is waiting on external operations such as disk I/O

Output on AIX

kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------
r b avm fre re pi po fr sr cy in sy cs us sy id wa
0 1 286902 1063 0 0 0 32 90 0 146 1059 180 3 1 87 8
0 2 287086 257 0 54 0 0 0 0 400 995 758 11 2 52 35
0 3 287086 137 0 0 0 0 0 0 343 807 240 10 0 66 23
0 2 287086 120 0 0 0 0 0 0 261 854 107 2 0 96 2
0 2 287086 124 0 1 0 1 4 0 223 484 66 1 1 97 2

sar utility on Unix

The sar utility is short for System Activity Reporter.

Usage : sar 2 5

sar –b Monitor Unix buffer Activity
sar –u Monitor CPU Usage
sar –w RAM Memory Switching & Swapping Activity
sar –d Monitor disk usage

# sar -u 5 5

Output on AIX

AIX dbsrv 3 4 000106DF4C00 09/21/02

17:05:35 %usr %sys %wio %idle
17:05:40 23 22 1 54
17:05:45 23 18 0 59
17:05:50 22 17 0 60
17:05:55 33 35 0 32
17:06:00 34 42 0 24

Average 27 27 0 46

# sar -b 3 5

sar –b command reports buffer activity which equates to disk I/O and is especially helpful if you suspsect that your database is I/O bound.

Output on AIX

AIX dbsrv 3 4 000106DF4C00 09/21/02

17:06:49 bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit/s
17:06:52 0 0 0 0 0 0 0 0
17:06:55 0 0 0 0 0 0 0 0
17:06:58 0 0 0 0 0 0 0 0
17:07:01 0 0 0 0 0 0 0 0
17:07:04 0 0 0 0 0 0 0 0

Average 0 0 0 0 0 0 0 0

Bread/s Number of Physical Reads from disk per second
Lread/s

# sar -w 3 5

Output on AIX

AIX dbsrv 3 4 000106DF4C00 09/21/02

17:07:27 cswch/s
17:07:30 16308
17:07:33 18440
17:07:36 18760
17:07:39 16757
17:07:42 13467

Average 16746

# sar -d 3 5

Output on AIX

AIX dbsrv 3 4 000106DF4C00 09/21/02

17:07:57 device %busy avque r+w/s blks/s avwait avserv

17:08:00 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0

17:08:03 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0

17:08:06 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0

17:08:09 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0

17:08:12 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0

Average 0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0
0 0.0 0 0 0.0 0.0


Determining the type of the file

file or file *

e.g.

$file sqlnet.log

sqlnet.log: ASCII text

Searching for a particular Text in the directory and sub-directories under that

find . -name "*" -exec grep -il {} \; | tee

Find all files except owned by a specific user

Will list the file names containing the search string.

find . ! -user oracle9i -print

‘ ! ‘ negates the expression. The other example will list all the files not owned by user oracle9i.

Find files having some specific permission

find . –name *.* -perm 664 -print

Searching for links in all the folders under the directory and output to a text file to create a script to change the links.

find . -type l -print -exec ls -trl {} \; | grep -i uat | awk '{ print $11, $9 }' | tee change_link.sh

Taking TAR Backup on Internal (Default) Tape Drive

Tested on AIX

Cautionmt -f /dev/rmt1 rewind
cd /
Cautiontar -cvf /dev/rmt0 ./prodr11i ./prod_dat ./prod_idx ./prod_msc

To view the list of files backed up

tar –tvf /dev/rmt0

Taking TAR Backup on Disk

Tested on SunOS 5.9

Cautiontar cpf u01_oradata_absolute.tar /u01/oradata/PRODDB*

The tar file u01_oradata_absolute.tar will be created in the present directory.

CAUTION: The above command will store the absolute path in the tar file and will restore to the same location while extracting. If you do not want to extract the files to the same location, take the tar backup with relative file name. E.g.

cd /u01/
Cautiontar cpf /backup/u01_oradata_relative.tar ./oradata/PRODDB*

Extracting file from TAR backup

Cautiontar xpf u01_oradata_absolute.tar

CAUTION: The above command will extract the files to its original location if the files were tarred using the absolute path. E.g. if the TAR file include the file backed up from /vaporub/u04/oradata/, using the absolute path, the extract command will restore the files to /vaporub/u04/oradata/ thereby overwriting the original contents.

To check whether the tar backup was taken using the absolute path or relative path using the the following command.

Tar backup taken with absolute path

tar tvf u01_oradata_absolute.tar

-rwxr-x--- 500/501 0 Jul 4 21:56 2007 /u01/oradata/PRODDB/system.dbf
-rwxr-x--- 500/501 0 Jul 4 21:58 2007 /u01/oradata/PRODDB/undotbs.dbf
-rw-r----- 500/501 0 Jul 4 21:58 2007 /u01/oradata/PRODDB/users.dbf
-rwxr-x--- 500/501 0 Jul 4 21:58 2007 /u01/oradata/PRODDB/index.dbf

Tar backup taken with relative path. Notice that the path is starting with dot ( '.' )

tar tvf u01_oradata_relative.tar

-rwxr-x--- 500/501 0 Jul 4 21:56 2007 ./oradata/PRODDB/system.dbf
-rwxr-x--- 500/501 0 Jul 4 21:58 2007 ./oradata/PRODDB/undotbs.dbf
-rw-r----- 500/501 0 Jul 4 21:58 2007 ./oradata/PRODDB/users.dbf
-rwxr-x--- 500/501 0 Jul 4 21:58 2007 ./oradata/PRODDB/index.dbf

To extract to a directory other than where the tar file is located, navigate to that directory and then issue the tar xvf command. E.g.

cd /restore
Cautiontar xvf /backup/u01_oradata_relative.tar

Take a compressed tar backup of file or directory

Caution/usr/bin/tar cpf - | compress - >

e.g.

Caution/usr/bin/tar cpf - ./u01/stage/rapidinstall | compress - > /backup/rapidinstall.Z

Copy the file and compress it at the same time

Cautioncat | compress - > .Z

e.g.

Cautioncat ./u01/stage/rapidinstall | compress - > /tmp/stage_rapidinstall.Z

Sending Mails from Unix

Sending a file as the body of the mail

For AIX
mail –s “Meeting today at 1100 Hrs” asagarwal@hotmail.com <>

For HP-UX
mailx –s “Meeting today at 1100 Hrs” asagarwal@hotmail.com <>

The above command will send the contents of the file mailmsg.file to asagarwal@hotmail.com with the subject line as “Meeting today at 1100 Hrs”.

Sending file as attachment

uuencode ashish.test ashish.test | mail asagarwal@hotmail.com

You can’t specify the subject with mail.

Using mailx instead of mail will send the file as body of the mail and not as an attachment.

Installing, upgrading, removing, querying package using rpm in redhat

To install a package (i=install v=verbose h=show hash marks) :-
rpm -ivh

To uninstall (erase) a package
rpm -e

To upgrade a package
rpm -Uvh

To test a package to see how it would install (without installing, also checks dependencies)
rpm -Uvh --test

To query whether a package has been installed or not
rpm -qa | grep

To Open or block ports on RedHat Linux

/usr/sbin/lokkit

vi editor commands

Movement Commands

l or SPACEBAR or -> Moves right one character
h or CTRL-H or BACKSPACE or <- moves left one character
j or CTRL-J or CTRL-N or down arrow move down one line
k or CTRL-P or up arrow move up one line
0 beginning of line
$ End of Line
+ or Enter Beginning of next line
- Beg of Previous line
w Move to next word or punctuation mark
W Move to next word
e Move to end of current word or punctuation
E Move to end of current word
b move back to beginning of word or punct
B move back begning of word
) start of next sentence
( start of current sentence
} start of next paragraph
{ start of current paragraph
]] start of next section
[[ start of current section
CTRL-F Move forward one full screen
CTRL-D Move forward one half screen
CTRL-B Move back one full screen
CTRL-U Move back one half screen
G Move to end of file
CTRL-F move ahead full screens
CTRL-B move back full screens

Modifying Text

rn replace current char with ‘n’
rn replace characters with ‘n’
Rstring ESC replaces current characters with ‘string until ESC is pressed

cwstringESC change the current word by replacing. The change continues until ESC is pressed. Vi puts $ over the last character of the work do be changed.

c$stringESC will change from current cursor position to end of line.

cw will change next words
3c$ will change next three lines

Deleting Text

x deletes current character
x deletes characgters
dw delete from cursor to end of the word
dw delete words
d$ delete to the end of line
D deletes to end of line (Same as d$)
d$ deletes till end of n lines ahead
d) deletes to beg of next line
d} deletes to beg of next paragraph
d]] deletes to be of next section
dd deletes current line
dd deletes n lines
dENTER deletes 2 lines
dG Deletes from Cursor to End of File

Undoing changes and deletions

u undo most recent change or deletion
U undo all changes made ina line since you last moved to that line
p put the contents to of the buffer to the right of the cursor (immediately below the current line)
P put the contents of the buffer to the left of the cursor (immediately above the current line)
:e! undo all the changes made since last time you save the file

Searching for text

/ seach forward for the specified string
/ENTER continue searching
? search backup for the specified string
n continue searching in the same direction

Copying and moving text

yw yanks (copies) a word
yw yanks words
y$ yanks to the end of line
y) yanks to the end of sentence
y} yanks to the end of paragraph
y]] yanks to the end of section
yy or Y yanks the current line
Y yanks lines
p paste to the right of the cursor
P paste to the left of the cursor



Refer from http://www.asagarwal.com/useful_unix_commands_dbas.html

0 意見: