useful unix commands for dbas

21
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 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 <name from previous command> $ 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 Go top 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% Go top

Upload: lado55

Post on 12-Nov-2014

86 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Useful Unix Commands for DBAs

Useful Unix commands for DBAsHere 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 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 memSolaris prtconf | grep –i memLinux freeHP-UX swapinfo –tmAIX lsdev –C | grep mem lsattr –El <name from previous command>

$ lsdev -C | grep mem

Output on AIX

mem0 Available 00-00 Memory

$ lsattr -El mem0

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

Go top

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 Typepaging01 hdisk4 dbvg2 2560MB 9 yes yes lvhd6 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%

Go top

Page 2: Useful Unix Commands for DBAs

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 cachedMem: 26871344 15263128 11608216 0 374036 13635804-/+ buffers/cache: 1253288 25618056Swap: 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

Go top

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 47812750 X 4353 1178 554415706 dtwm 3257 1174 400317172 dtsession 2986 1174 382721150 dtterm 2941 1174 369717764 aixterm 2862 1174 36442910 dtterm 2813 1174 370519334 dtterm 2813 1174 370413664 dtterm 2804 1174 370617520 aixterm 2801 1174 3619

Pid: 15012Command: 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

Page 3: Useful Unix Commands for DBAs

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..245801d9b 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..327681096 work sreg[3] 32 0 32 0..327831b9d work private 1057 1 1219 0..1306 : 65307..655351af8 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.

Go top

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 2002T ID KEY MODE OWNER GROUP SEGSZ CPID LPIDShared Memory:m 131072 0x58000932 --rw-rw-rw- root system 134217728 6990 47580m 1 0x0d003187 --rw-rw-rw- root system 1440 11872 27654m 131074 0xffffffff --rw------- root system 104857600 45198 45198m 2621443 0x05c17710 --rw-r----- crpor11i oradba 368291840 25196 29384m 1310724 0x50942e5c --rw-r----- devor11i oradba 405147648 25450 46580

Go top

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 2002T ID KEY MODE OWNER GROUP SEGSZ CPID LPIDShared Memory:m 131072 0x58000932 --rw-rw-rw- root system 134217728 6990 47580m 1 0x0d003187 --rw-rw-rw- root system 1440 11872 7812m 131074 0xffffffff --rw------- root system 104857600 45198 45198m 2621443 0x05c17710 --rw-r----- crpor11i oradba 368291840 25196 39296m 1310724 0x50942e5c --rw-r----- devor11i oradba 405147648 25450 39290

Page 4: Useful Unix Commands for DBAs

ipcrm –m 1310724 (To release the memory)

Go top

CPU

Displaying the No. of CPU processors in UNIX

AIX lsdev –C | grep Process | wc –l HP-UX ioscan –C processor | grep processor | wc –lSolaris 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 -efcrpap11i 31850 1 0 06:17:06 - 0:00 rwmts60 name=REP60_CRPdevap11i 32832 1 0 02:35:31 - 0:00 rwmts60 name=REP60_DEVcrpor11i 48448 7812 1 14:12:49 pts/0 0:00 sort +7crpor11i 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_CRPdevor11i 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 (DESCRIPTION=(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 (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))root 45198 0.3 7.0 175204 103064 - A Jul 24 67:10 dsmserv quietcrpor11i 43620 0.4 1.0 32264 19236 - A 13:58:23 0:08 oracleCRP (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))root 774 47.1 0.0 12 7492 - A Jul 20 17411:25 kprocroot 516 48.0 0.0 12 7492 - A Jul 20 17723:26 kproc

Page 5: Useful Unix Commands for DBAs

ps augxww | grep “RSS| “ | head

Output on AIX

USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMANDroot 516 48.0 0.0 12 7492 - A Jul 20 17725:33 kprocroot 774 47.1 0.0 12 7492 - A Jul 20 17413:32 kproccrpor11i 46568 1.9 1.0 29768 16728 - A 14:16:18 0:02 oracleCRP (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))crpor11i 43620 0.4 1.0 32264 19236 - A 13:58:23 0:08 oracleCRP (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))crpor11i 34816 0.3 1.0 31924 18896 - A 13:43:29 0:14 oracleCRP (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))root 45198 0.3 7.0 175204 103012 - A Jul 24 67:10 dsmserv quietroot 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 dtgreetcrpor11i 27526 0.1 1.0 30372 17336 - A 12:53:46 0:10 oracleCRP (DESCRIPTION=(LOCAL=no)(ADDRESS=(PROTOCOL=BEQ)))

Go top

To display processes consuming CPU% & elapsed time

ps -aef -o ruser,pid,pcpu,args,etime,<time>

Output on AIX

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

Go top

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 1000 2 4 94

Page 6: Useful Unix Commands for DBAs

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.

Go top

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 Drivesmc0 Available 21-08-00-5,0 IBM 3581 Tape Medium Changerrmt1 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 Drivehdisk1 Available 40-60-00-8,0 16 Bit LVD SCSI Disk Drivehdisk2 Available 11-08-00-0,0 SCSI Disk Array RAID 5hdisk3 Available 11-08-00-1,0 SCSI Disk Array RAID 5hdisk4 Available 14-08-L SSA Logical Disk Drivehdisk5 Available 31-08-L SSA Logical Disk Drivehdisk6 Available 31-08-L SSA Logical Disk Drivehdisk7 Available 14-08-L SSA Logical Disk Drivehdisk8 Available 14-08-L SSA Logical Disk Drive

Go top

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

Page 7: Useful Unix Commands for DBAs

is available for use.

Output on AIX

appvg1rootvg

lsvg –l <volume group>

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 POINThd5 boot 1 2 2 closed/syncd N/Ahd6 paging 16 32 2 open/syncd N/Ahd8 jfslog 1 2 2 open/syncd N/Ahd4 jfs 5 10 2 open/syncd /hd2 jfs 42 84 2 open/syncd /usrhd9var jfs 3 6 2 open/syncd /varhd3 jfs 36 72 2 open/syncd /tmphd1 jfs 3 6 2 open/syncd /homepridumplv sysdump 5 5 1 open/syncd N/Asoftwarelv jfs 8 8 1 closed/syncd /softwarescriptslv 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 POINTorastagelv jfs 122 122 1 open/syncd /orastageloglv00 jfslog 1 1 1 open/syncd N/Acrpr11ilv jfs 160 160 1 open/syncd /crpr11iprdap11i jfs 120 120 1 open/syncd /prdap11ipaging00 paging 20 20 1 open/syncd N/Atestbkup jfs 120 120 1 closed/syncd /testbkup

rootvg:LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINThd5 boot 1 2 2 closed/syncd N/Ahd6 paging 16 32 2 open/syncd N/Ahd8 jfslog 1 2 2 open/syncd N/Ahd4 jfs 5 10 2 open/syncd /hd2 jfs 42 84 2 open/syncd /usrhd9var jfs 3 6 2 open/syncd /var

Page 8: Useful Unix Commands for DBAs

hd3 jfs 36 72 2 open/syncd /tmphd1 jfs 3 6 2 open/syncd /homepridumplv sysdump 5 5 1 open/syncd N/Asoftwarelv jfs 8 8 1 closed/syncd /softwarescriptslv jfs 8 8 1 open/syncd /scripts

Go top

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 rootvghdisk1 000780ffdb900f40 rootvghdisk2 000780ffdde9b3e7 dbvg1hdisk3 000780dfddf63eb8 appvg1hdisk4 000780dff8276946 dbvg2hdisk5 none None

lspv –l <device>

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 POINThd5 1 1 01..00..00..00..00 N/Ahd6 16 16 00..16..00..00..00 N/Apridumplv 5 5 00..05..00..00..00 N/A

Page 9: Useful Unix Commands for DBAs

scriptslv 8 8 00..08..00..00..00 /scriptshd8 1 1 00..00..01..00..00 N/Ahd4 5 5 00..00..05..00..00 /hd2 42 42 00..00..42..00..00 /usrhd9var 3 3 00..00..03..00..00 /varhd3 36 36 00..00..36..00..00 /tmphd1 3 3 00..00..03..00..00 /home

Go top

Miscellenous

To see the Server Configuration

$ prtconf

Output on AIX

System Model: IBM,7026-6H1Processor Type: PowerPC_RS64-IVNumber Of Processors: 4Memory Size: 6144MBGood Memory Size: 6144MBFirmware Version: IBM,M2P030828_condor_Console Login: enableAuto Restart: trueFull 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 Objectsysplanar0 Available 00-00 System Planar

Page 10: Useful Unix Commands for DBAs

pci0 Available 00-fff7f09000 PCI Buspci1 Available 00-fff7f0a000 PCI Buspci2 Available 00-fff7f08000 PCI Busisa0 Available 10-80 ISA Bussa0 Available 01-S1 Standard I/O Serial Portsa1 Available 01-S2 Standard I/O Serial Portsa2 Available 01-S3 Standard I/O Serial Portsa3 Available 01-S4 Standard I/O Serial Portsiokma0 Available 01-K1 Keyboard/Mouse Adapterfda0 Available 01-D1 Standard I/O Diskette Adapterpci3 Available 10-58 PCI Busscsi0 Available 11-08 Wide/Fast-20 SCSI I/O Controllerpci4 Available 10-5a PCI Buspci5 Available 10-5c PCI Buspci6 Available 10-5e PCI Buspci7 Available 20-58 PCI Busssa0 Available 21-08 IBM SSA 160 SerialRAID Adapter (14109100)pci8 Available 20-5a PCI Busmg20 Available 24-08 GXT130P Graphics Adapterpci9 Available 20-5b PCI Buspci10 Available 20-5c PCI Buspci11 Available 20-5e PCI Bus……………….……………….……………….

Go top

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 Falsemaxbuf 20 Maximum number of pages in block I/O BUFFER CACHE Truemaxmbuf 0 Maximum Kbytes of real memory allowed for MBUFS Truemaxuproc 128 Maximum number of PROCESSES allowed per user Trueautorestart false Automatically REBOOT system after a crash Trueiostat false Continuously maintain DISK I/O history Truerealmem 1572864 Amount of usable physical memory in Kbytes Falseconslogin enable System Console Login Falsefwversion IBM,M2P011204 Firmware version and revision levels Falsemaxpout 0 HIGH water mark for pending write I/Os per file Trueminpout 0 LOW water mark for pending write I/Os per file Truefullcore false Enable full CORE dump True

Go top

Page 11: Useful Unix Commands for DBAs

Displaying System Log Messages

$ errpt –a | more

Output on AIX

----------------------------------------------------------LABEL: CORE_DUMPIDENTIFIER: C60BB505

Date/Time: Thu Aug 1 23:40:47Sequence Number: 13368Machine Id: 000780DF4C00Node Id: db11iClass: SType: PERMResource Name: SYSPROC

DescriptionSOFTWARE PROGRAM ABNORMALLY TERMINATED

Probable CausesSOFTWARE PROGRAM

User CausesUSER GENERATED SIGNAL

Recommended Actions CORRECT THEN RETRY

Go top

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 -y64

Example of 32-bit AIX OS

lslpp -l bos.64bit

Page 12: Useful Unix Commands for DBAs

lslpp: Fileset bos.64bit not installed.

HP-UX

getconf KERNEL_BITS64

Linux – RedHat

# uname -ii386

# uname -iX86_64

Go top

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

Go top

Page 13: Useful Unix Commands for DBAs

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

shutdown –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.

Go top

To kill all the oracle process from OS

ps –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

cat /dev/null > /dev/ttyname kill –9 <pid#>

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

Go top

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 this is the percentage of CPU being used to service system tasks.

Page 14: Useful Unix Commands for DBAs

CPU)

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

Go top

sar utility on Unix

The sar utility is short for System Activity Reporter.

Usage : sar <flag> 2 5

sar –b Monitor Unix buffer Activitysar –u Monitor CPU Usagesar –w RAM Memory Switching & Swapping Activitysar –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 %idle17:05:40 23 22 1 5417:05:45 23 18 0 5917:05:50 22 17 0 6017:05:55 33 35 0 3217: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/s17:06:52 0 0 0 0 0 0 0 017:06:55 0 0 0 0 0 0 0 017:06:58 0 0 0 0 0 0 0 0

Page 15: Useful Unix Commands for DBAs

17:07:01 0 0 0 0 0 0 0 017: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 secondLread/s

# sar -w 3 5

Output on AIX

AIX dbsrv 3 4 000106DF4C00 09/21/02

17:07:27 cswch/s17:07:30 1630817:07:33 1844017:07:36 1876017:07:39 1675717: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

Page 16: Useful Unix Commands for DBAs

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

Go top

Determining the type of the file

file <filename> 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 <search_string> {} \; | tee <output_file_name>

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

Go top

Taking TAR Backup on Internal (Default) Tape Drive

Tested on AIX

mt -f /dev/rmt1 rewind cd / tar -cvf /dev/rmt0 ./prodr11i ./prod_dat ./prod_idx ./prod_msc

To view the list of files backed up

tar –tvf /dev/rmt0

Page 17: Useful Unix Commands for DBAs

Taking TAR Backup on Disk

Tested on SunOS 5.9

tar 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/ tar cpf /backup/u01_oradata_relative.tar ./oradata/PRODDB*

Go top

Extracting file from TAR backup

tar 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 tar xvf /backup/u01_oradata_relative.tar

Go top

Page 18: Useful Unix Commands for DBAs

Take a compressed tar backup of file or directory

/usr/bin/tar cpf - <source_dir> | compress - > <destination_file>

e.g.

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

Copy the file and compress it at the same time

cat <source_file> | compress - > <desintation>.Z

e.g.

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

Go top

Sending Mails from Unix

Sending a file as the body of the mail

For AIXmail –s “Meeting today at 1100 Hrs” [email protected] < mailmsg.file

For HP-UXmailx –s “Meeting today at 1100 Hrs” [email protected] < mailmsg.file

The above command will send the contents of the file mailmsg.file to [email protected] with the subject line as “Meeting today at 1100 Hrs”.

Sending file as attachment

uuencode ashish.test ashish.test | mail [email protected]

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.

Go top

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

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

To uninstall (erase) a packagerpm -e <package_name>

To upgrade a packagerpm -Uvh <package_name>

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

To query whether a package has been installed or notrpm -qa | grep <package_name>

Page 19: Useful Unix Commands for DBAs

To Open or block ports on RedHat Linux

/usr/sbin/lokkit

Go top

vi editor commands

Movement Commands

l or SPACEBAR or -> Moves right one characterh or CTRL-H or BACKSPACE or <- moves left one characterj or CTRL-J or CTRL-N or down arrow move down one linek or CTRL-P or up arrow move up one line0 beginning of line$ End of Line+ or Enter Beginning of next line- Beg of Previous linew Move to next word or punctuation markW Move to next worde Move to end of current word or punctuation E Move to end of current wordb 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 sectionCTRL-F Move forward one full screenCTRL-D Move forward one half screenCTRL-B Move back one full screenCTRL-U Move back one half screenG Move to end of file<n>CTRL-F move ahead <n> full screens<n>CTRL-B move back <n> full screens

Modifying Text

rn replace current char with ‘n’<n>rn replace <n> 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.

<n>cw will change next <n> words3c$ will change next three lines

Deleting Text

Page 20: Useful Unix Commands for DBAs

x deletes current character<n>x deletes <n> characgtersdw delete from cursor to end of the word<n>dw delete <n> wordsd$ delete to the end of lineD deletes to end of line (Same as d$)<n>d$ deletes till end of n lines aheadd) deletes to beg of next lined} deletes to beg of next paragraphd]] deletes to be of next sectiondd deletes current line<n>dd deletes n linesdENTER deletes 2 linesdG Deletes from Cursor to End of File

Undoing changes and deletions

u undo most recent change or deletionU undo all changes made ina line since you last moved to that linep 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

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

Copying and moving text

yw yanks (copies) a word<n>yw yanks <n> wordsy$ yanks to the end of liney) yanks to the end of sentencey} yanks to the end of paragraphy]] yanks to the end of sectionyy or Y yanks the current line<n>Y yanks <n> linesp paste to the right of the cursorP paste to the left of the cursor

Go top

Home | Profile Snapshot | Services | Training & Workshops | Resources for DBAs | My Blog | Social Responsibility | Contact Me Bookmarks

MemoryCPU