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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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.
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.
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
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
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.
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
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
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.
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.
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.
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
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