Unix Oracle Commands For DBAs
Contents
- 1 Basic File Navigation
- 2 File Permissions
- 3 OS Users Management
- 4 Process Management
- 5 uname and hostname
- 6 Error Lines in Files
- 7 File Exists Check
- 8 Remove Old Files
- 9 Remove DOS CR/LFs (^M)
- 10 Run Commands As Oracle User From Root
- 11 Compress Files
- 12 General Performance
- 13 vmstat
- 14 CPU Usage
- 15 sar
- 16 mpstat
- 17 ps
- 18 Automatic Startup Scripts on Linux
- 19 CRON
- 20 Cluster Wide CRON Jobs On Tru64
- 21 NFS Mount (Sun)
- 22 NFS Mount (Tru64)
- 23 PC XStation Configuration
- 24 Useful Profile Settings
- 25 Useful Files
This article contains a brief list of commands that most UNIX DBAs will need on a regular basis. Basic File NavigationThe "pwd" command displays the current directory:The "ls" command lists all files and directories in the specified directory. If no location is defined it acts on the current directory:root> pwd The "-a" flag lists hidden "." files. The "-l" flag lists file details.root> ls The "cd" command is used to change directories: The "touch" command is used to create a new empty file with the default permissions:root> cd /u01/app/oracle The "rm" command is used to delete files and directories:root> touch my.log The "-R" flag tells the command to recurse through subdirectories.root> rm my.log The "mv" command is used to move or rename files and directories: The "." represents the current directoryroot> mv [from] [to] The "cp" command is used to copy files and directories: The "mkdir" command is used to create new directories:root> cp [from] [to] The "rmdir" command is used to delete directories:root> mkdir archive The "find" command can be used to find the location of specific files:root> rmdir archive The "/" flag represents the staring directory for the search. Wildcards such as "dbms*" can be used for the filename.root> find / -name dbmspool.sql The "which" command can be used to find the location of an executable you are using: The "which" command searches your PATH setting for occurences of the specified executable.oracle> which sqlplus File PermissionsThe "umask" command can be used to read or set default file permissions for the current user:The umask value is subtracted from the default permissions (666) to give the final permission:root> umask 022 The "chmod" command is used to alter file permissions after the file has been created:666 : Default permission Character eqivalents can be used in the chmod command:root> chmod 777 *.log The "chown" command is used to reset the ownership of files after creation:root> chmod o+rwx *.log The "-R" flag causes the command ro recurse through any subdirectories.root> chown -R oinstall.dba * OS Users ManagementThe "useradd" command is used to add OS users:root> useradd -G oinstall -g dba -d /usr/users/my_user -m -s /bin/ksh my_user
The "userdel" command is used to delete existing users:root> usermod -s /bin/csh my_user The "-r" flag removes the default directory.root> userdel -r my_user The "passwd" command is used to set, or reset, the users login password: The "who" command can be used to list all users who have OS connections:root> passwd my_user root> who
Process ManagementThe "ps" command lists current process information:Specific processes can be killed by specifying the process id in the kill command:root> ps root> kill -9 12345 uname and hostnameThe "uname" and "hostname" commands can be used to get information about the host:root> uname -a Error Lines in FilesYou can return the error lines in a file using:The "grep -i ORA-" command limits the output to lines containing "ORA-". The "-i" flag makes the comparison case insensitive. A count of the error lines can be returned using the "wc" command. This normally give a word count, but the "-l" flag alteres it to give a line count:root> cat alert_LIN1.log | grep -i ORA- root> cat alert_LIN1.log | grep -i ORA- | wc -l File Exists CheckThe Korn shell allows you to check for the presence of a file using the "test -s" command. In the following script a backup log is renamed and moved if it is present:#!/bin/ksh Remove Old FilesThe find command can be used to supply a list of files to the rm command:find /backup/logs/ -name daily_backup* -mtime +21 -exec rm -f {} ; Remove DOS CR/LFs (^M)Remove DOS style CR/LF characters (^M) from UNIX files using:The newly created tempfile should have the ^M character removed.sed -e 's/^M$//' filename > tempfile Run Commands As Oracle User From RootThe following scripts shows how a number of commands can be run as the "oracle" user the "root" user:This is often necessary where CRON jobs are run from the root user rather than the oracle user.#!/bin/ksh Compress FilesIn order to save space on the filesystem you may wish to compress files such as archived redo logs. This can be using either the gzip or the compress commands. The gzip command results in a compressed copy of the original file with a ".gz" extension. The gunzip command reverses this process:The compress command results in a compressed copy of the original file with a ".Z" extension. The uncompress command reverses this process:gzip myfile compress myfile General Performancevmstat$ vmstat 5 3Displays system statistics (5 seconds apart; 3 times):
Having any processes in the b or w columns is a sign of a problem system. Having an id of 0 is a sign that the cpu is overburdoned. Having high values in pi and po show excessive paging.
CPU Usagesar$ sar -u 10 8Reports CPU Utilization (10 seconds apart; 8 times):
%usr : Percent of CPU in user mode %sys : Percent of CPU in system mode %wio : Percent of CPU running idle with a process waiting for block I/O %idle : Percent of CPU that is idle mpstat$ mpstat 10 2Reports per-processor statistics on Sun Solaris (10 seconds apart; 8 times):
ps$ ps -e -o pcpu -o pid -o user -o args | sort -k 1 | tail -21rDisplays the top 20 CPU users on the system.
The PID column can then be matched with the SPID column on the V$PROCESS view to provide more information on the process: SELECT a.username, Automatic Startup Scripts on LinuxCreate a file in the /etc/init.d/ directory, in this case the file is called myservice, containing the commands you wish to run at startup and/or shutdown.Use the chmod command to set the privileges to 750: Link the file into the appropriate run-level script directories:chmod 750 /etc/init.d/myservice Associate the myservice service with the appropriate run levels:ln -s /etc/init.d/myservice /etc/rc0.d/K10myservice The script should now be automatically run at startup and shutdown (with "start" or "stop" as a commandline parameter) like other service initialization scripts.chkconfig --level 345 dbora on CRONThere are two methods of editing the crontab file. First you can use the "crontab -l > filename" option to list the contents and pipe this to a file. Once you've editied the file you can then apply it using the "crontab filename":
The entries have the following elements: The first 5 fields can be specified using the following rules:field allowed values The following entry runs a cleanup script a 01:00 each Sunday. Any output or errors from the script are piped to /dev/null to prevent a buildup of mails to root:* - All available values or "first-last". 0 1 * * 0 /u01/app/oracle/dba/weekly_cleanup > /dev/null 2>&1 Cluster Wide CRON Jobs On Tru64On clustered systems cron is node-specific. If you need a job to fire once per cluster, rather than once per node you need an alternative approach to the standard cron job. One approach is put forward in the HP best practices document (Using cron in a TruCluster Server Cluster), but in my opinion a more elegant solution is proposed by Jason Orendorf of HP Tru64 Unix Enterprise Team (TruCluster Clustercron).In his solution Jason creates a file called /bin/cronrun with the following contents: This script returns TRUE (0) only on the node which is the CFS serving cluster_root.#!/bin/ksh All cluster wide jobs should have a crontab entry on each node of the cluster like: Although the cron jobs fire on all nodes, the "/bin/cronrun &&" part of the entry prevents the script from running on all nodes except the current CFS serving cluster_root.5 * * * /bin/cronrun && /usr/local/bin/myjob NFS Mount (Sun)The following deamons must be running for the share to be seen by a PC:
First the mount point must be shared so it can be seen by remote machines:exportfs Next the share can be mounted on a remote machine by root using:share -F nfs -o ro /cdrom mkdir /cdrom#1 NFS Mount (Tru64)On the server machine:If NFS is not currently setup do the following:
Append the following entry to the "/etc/exports" file:mkdir /u04/backup Make sure the correct permissions are granted on the directory:/u04/backup On the client machine:chmod -R 777 /u04/backup If NFS is not currently setup do the following:
Append an following entry to the "/etc/fstab" file:mkdir /backup Finally, mount the fileset:nfs-server-name:/u04/backup /backup nfs rw,bg,intr 0 0 At this point you can start to use the mount point from your client machine. Thanks to Bryan Mills for his help with Tru64.mount /backup PC XStation ConfigurationDownload the CygWin setup.exe from http://www.cygwin.com .Install, making sure to select all the X11R6 (or XFree86 in older versions) optional packages. If you need root access add the following entry into the /etc/securettys file on each server: From the command promot on the PC do the following:<client-name>:0 The X environment should start in a new window.set PATH=PATH;c:cygwinbin;c:cygwinusrX11R6bin Many Linux distributions do not start XDMCP by default. To allow XDMCP access from Cygwin edit the "/etc/X11/gdm/gdm.conf" file. Under the "[xdmcp]" section set "Enable=true". If you are starting any X applications during the session you will need to set the DISPLAY environment variable. Remember, you are acting as an XStation, not the server itself, so this variable must be set as follows: DISPLAY=<client-name>:0.0; export DISPLAY Useful Profile SettingsThe following .profile settings rely on the default shell for the user being set to the Korn shell (/bin/ksh).The backspace key can be configured by adding the following entry: The command line history can be accessed using the [Esc][k] by adding the following entry:stty erase "^H" Auto completion of paths using a double strike of the [Esc] key can be configured by adding the following entry:set -o vi set filec Useful FilesHere are some files that may be of use:
For more information see: |
??
Wiziontech Solutions | Created by Thiyagaraaj