Professional Documents
Culture Documents
Userful Unix Commands
Userful Unix Commands
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
Pid: 15012 Command: maker4X.exe Segid Type Description 1572 pers /dev/hd3:62 142 pers /dev/hd3:51 Inuse 0 0 0 0 Pin Pgspace Address Range 0 0..-1 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. 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 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
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
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))) Go top
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 Use a more faster processor 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 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 Go top
is available for use. Output on AIX appvg1 rootvg 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 hd5 hd6 hd8 hd4 hd2 hd9var hd3 hd1 pridumplv softwarelv scriptslv TYPE LPs PPs PVs LV STATE MOUNT POINT boot 1 2 2 closed/syncd N/A paging 16 32 2 open/syncd N/A jfslog 1 2 2 open/syncd N/A jfs 5 10 2 open/syncd / jfs 42 84 2 open/syncd /usr jfs 3 6 2 open/syncd /var jfs 36 72 2 open/syncd /tmp jfs 3 6 2 open/syncd /home sysdump 5 5 1 open/syncd N/A jfs 8 8 1 closed/syncd /software 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 orastagelv loglv00 crpr11ilv prdap11i paging00 testbkup rootvg: LV NAME hd5 hd6 hd8 hd4 hd2 hd9var TYPE LPs PPs PVs LV STATE MOUNT POINT jfs 122 122 1 open/syncd /orastage jfslog 1 1 1 open/syncd N/A jfs 160 160 1 open/syncd /crpr11i jfs 120 120 1 open/syncd /prdap11i paging 20 20 1 open/syncd N/A jfs 120 120 1 closed/syncd /testbkup TYPE LPs PPs PVs LV STATE boot 1 2 2 closed/syncd N/A paging 16 32 2 open/syncd N/A jfslog 1 2 2 open/syncd N/A jfs 5 10 2 open/syncd / jfs 42 84 2 open/syncd /usr jfs 3 6 2 open/syncd /var MOUNT POINT
jfs jfs
36 72 2 open/syncd /tmp 3 6 2 open/syncd /home sysdump 5 5 1 open/syncd N/A jfs 8 8 1 closed/syncd /software jfs 8 8 1 open/syncd /scripts Go top
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 hd5 hd6 pridumplv LPs PPs DISTRIBUTION 1 1 01..00..00..00..00 N/A 16 16 00..16..00..00..00 N/A 5 5 00..05..00..00..00 N/A MOUNT POINT
8 1 5 42 3 36 3
8 1 5 42 3 36 3
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%
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 . . . Go top
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 Go top
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
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. 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 this is the amount of CPU that is servicing the user tasks this is the percentage of CPU being used to service system tasks.
Pi (page in)
this is the percentage of CPU that is idle this shows the percentage of CPU that is waiting on external operations such as disk I/O
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
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
Output on AIX AIX dbsrv 3 4 000106DF4C00 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 17:07:57 17:08:00 0 0 0 0 17:08:03 0 0 0 0 17:08:06 0 0 0 0 17:08:09 0 0 0 0 17:08:12 0 0 device 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 0 0.0 0.0 0 0.0 0 0.0 0 0.0 0 0 0.0 0.0 0 0.0 0 09/21/02 r+w/s blks/s avwait avserv 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 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.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 %busy avque 09/21/02
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.0 Go top
Searching for a particular Text in the directory and sub-directories under that
find . -name "*" -exec grep -il <search_string> {} \; | tee <output_file_name>
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
Tar backup taken with relative path. Notice that the path is starting with dot ( '.' ) tar tvf u01_oradata_relative.tar -rwxr-x--- 500/501 -rwxr-x--- 500/501 -rw-r----- 500/501 -rwxr-x--- 500/501 0 Jul 4 21:56 2007 ./oradata/PRODDB/system.dbf 0 Jul 4 21:58 2007 ./oradata/PRODDB/undotbs.dbf 0 Jul 4 21:58 2007 ./oradata/PRODDB/users.dbf 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
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 <n>CTRL-F move ahead <n> full screens <n>CTRL-B move back <n> full screens Modifying Text rn <n>rn Rstring ESC replace current char with n replace <n> characters with n 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 <n>cw 3c$ Deleting Text will change from current cursor position to end of line. will change next <n> words will change next three lines
x <n>x dw <n>dw d$ D <n>d$ d) d} d]] dd <n>dd dENTER dG u U p current line) P current line) :e! Searching for text /<string> /ENTER ?<string> n yw <n>yw y$ y) y} y]] yy or Y <n>Y p P
deletes current character deletes <n> characgters delete from cursor to end of the word delete <n> words delete to the end of line deletes to end of line (Same as d$) deletes till end of n lines ahead deletes to beg of next line deletes to beg of next paragraph deletes to be of next section deletes current line deletes n lines deletes 2 lines Deletes from Cursor to End of File undo most recent change or deletion undo all changes made ina line since you last moved to that line put the contents to of the buffer to the right of the cursor (immediately below the put the contents of the buffer to the left of the cursor (immediately above the undo all the changes made since last time you save the file seach forward for the specified string continue searching search backup for the specified string continue searching in the same direction yanks (copies) a word yanks <n> words yanks to the end of line yanks to the end of sentence yanks to the end of paragraph yanks to the end of section yanks the current line yanks <n> lines paste to the right of the cursor 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 Memory CPU