17
UNIX/Linux Commands for Oracle DBAs DBA TEAM Revision History Date Revision Name Reviewer 13/05/013 1.0 VikramGrg Ashish Man. Baisyet Basic File Navigation df  command in Linux provides disk space usage information of your file systems. $ df h (in human readable format) [oracle@asmdb ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 19G 8.6G 69% / /dev/sda1 99M 9.9M 84M 11% /boot tmpfs 2.0G 295M 1.8G 15% /dev/shm du command Display how much disk space is being used by directories. [oracle@asmdb asmsoft]$ du -ak /softwares/asmsoft / -a - Shows counts for all files encountered, not only directories. -k - Use 1024 byte blocks instead of the default 512. Basic File Navigation Head command prints the first N number of data of the given input. By default, it prints first 10 lines of each given file. tail Show last lines of a file. $tail -500 alert.log #Print only the last 500 lines of the alert log file. man

UNIXLInux for Oracle DBAMustKnow-libre

  • Upload
    wiscad

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 1/17

UNIX/Linux Commands for Oracle DBAs

DBA TEAM

Revision History 

Date Revision Name Reviewer

13/05/013 1.0 VikramGrg Ashish Man. Baisyet

Basic File Navigation

df  command in Linux provides disk space usage information of your file systems.

$ df –h (in human readable format)

[oracle@asmdb ~]$ df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 30G 19G 8.6G 69% /

/dev/sda1 99M 9.9M 84M 11% /boot

tmpfs 2.0G 295M 1.8G 15% /dev/shm

du command

Display how much disk space is being used by directories.

[oracle@asmdb asmsoft]$ du -ak /softwares/asmsoft/

-a - Shows counts for all files encountered, not only directories.

-k - Use 1024 byte blocks instead of the default 512.

Basic File Navigation

Head command prints the first N number of data of the given input. By default, it prints first 10

lines of each given file.

tail 

Show last lines of a file.

$tail -500 alert.log #Print only the last 500 lines of the alert log file. 

man

Page 2: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 2/17

The Linux command "man" is used at the command line to explain the functions and definitions

of other commands commonly used within Linux. The term "man" is short for manual pages

and gives you a very in-depth explanation of the said command which you are referring to.

$ man ls

$ man chown

"pwd" command displays the present working directory.

[oracle@asmdb ~]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1

The "ls" command lists all files and directories in the specified directory. If no location is defined

it acts on the current directory.

[oracle@asmdb ~]$ ls

[oracle@asmdb ~]$ ls /u01

[oracle@asmdb ~]$ ls –al

$ ls –l or ll (Listing in long format).

The "-a" flag lists hidden "." files.

The "-l" flag lists file details (Listing in long format).

"cd" command -> change directories.

[oracle@asmdb ~]$ cd /u01/app/oracle

[oracle@asmdb oracle]$ pwd

/u01/app/oracle

"touch" -> create a new empty file.

[oracle@asmdb ~]$ touch my.log

vi Editor

The default editor that comes with the UNIX/Linux operating system is called vi (visual editor)

Page 3: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 3/17

[oracle@asmdb ~]$ vi filename.txt

The vi editor has three modes, command mode, insert mode and command line mode.

1.  Command mode: letters or sequence of letters interactively command vi. Commands

are case sensitive. The ESC key can end a command.2.  Insert mode: Text is inserted. The ESC key ends insert mode and returns you to

command mode. One can enter insert mode with the "i" (insert), "a" (insert after), "A"

(insert at end of line), "o" (open new line after current line) or "O" (Open line above

current line) commands.

3.  Command line mode: One enters this mode by typing ":" which puts the command line

entry at the foot of the screen.

To Exit vi 

Usually the new or modified file is saved when you leave vi. However, it is also possible

to quit vi without saving the file.

* :x<Return>  Save and quit vi. 

:wq<Return> Write and quit vi .

:q<Return>  quit (or exit) vi .

* :q!<Return>  quit vi even though latest changes have not been saved for this vi call

cat ->Display one or more files contents.

[oracle@asmdb ~]$ cat pfile1.ora

"rm" command -> to delete files and directories.

[oracle@asmdb ~]$ rm my.log

[oracle@asmdb ~]$ rm -rf /softwares/asmsoft1

Recursively(-r) deletes directories and subdirectories with contents forcefully(-f) without

prompt.

"mv" command -> move/rename files and directories.

[oracle@asmdb ~]$ mv myfile.log myfile_bk.log

[oracle@asmdb ~]$ mv * /softwares/asmsoft/

[oracle@asmdb ~]$ mv /archive/arch_bk/* .

Page 4: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 4/17

"." -> represents current directory.

"cp" command -> copy files and directories.

[oracle@asmdb ~]$ cp myfile.log myfile_bk.log

[oracle@asmdb ~]$ cp * /softwares/asmsoft/

[oracle@asmdb ~]$ cp /archive/arch_bk/* .

"mkdir" command -> create new directories.

[oracle@asmdb ~]$ mkdir archive

[root@asmdb ~]# mkdir -p /u01/app/oracle

"which" command -> to get location of an executable you are using.

[oracle@asmdb ~]$ which sqlplus

chggrp 

Change group of the named file or directory.

Example:

$ su - root #sitch to root accout or use “su –“ oly.

$ chgrp oracle test.txt #Change the group ownership of the test file.

$ ls –l test #Display again the test file information using the long list

format (-l)

File Permissions

Linux Files, Directories and Permissions. 

"umask" command -> read or set default file permissions for the current user.

[root@asmdb ~]# umask 022

The default umask value is 0022, which decides the default permission for a new file or

directory. Default permission for a directory is 0777, for files the permissions are 0666 from

which the default umask value 0022 is deducted to get the newly created files or directory

permission.

Page 5: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 5/17

Note:- The umask value is subtracted from the default file permissions (666) to give the final

permission.

666 : Default permission

022 : - umask value

644 : final permission

Final default permission for a file is calculated as shown below:

Default file permission: 666

Default umask : 022

Final default file permission: 644

Final default permission for a directory is calculated as shown below:

Default directory permission: 777

Default umask: 022

Final default directory permission: 755

"chmod" command -> alter file/folder permissions.

chmod stands for change mode.

[root@asmdb ~]# chmod -R 775 /softwares/

Character eqivalents can be used in the chmod command.

[root@asmdb ~]# chmod o+rwx *.log

[root@asmdb ~]# chmod g+r softwares

[root@asmdb ~]# chmod -Rx *.log

Here u-> user, g-group, o-other

Permission Equivalence

Value Permission

4 read (r)

2 write (w)

1 execute (x)

Page 6: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 6/17

"chown" command -> reset/change the ownership of files/directories.

[root@asmdb ~]# chown -R oracle.oinstall /u01

“-R" -> recurse through any subdirectories.

OS Users Management

"useradd" command to add OS users.

[root@asmdb ~]# useradd -g oinstall -G asmadmin,asmdba,asmoper -d /home/grid -s

/bin/bash grid

"-g " specifies the primary group."-G " specifies secondary groups.

"-d" specifies the default directory.

"-s" specifies the default shell.

-u, --uid UID

The numerical value of the user as ID. This value must be unique, unless the -o option is

used.

“usermod" command is used to modify the user settings.

[root@asmdb ~]# usermod -g oinstall -G dba,oper,asmdba oracle

"userdel" command is used to delete existing users.

[root@asmdb ~]# userdel -r npuser

Delete the specified user recursively (deleting its home directory also).

groupadd

Creates a new group account.

[root@asmdb ~]# groupadd dba

Make sure it is created successfully.

Page 7: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 7/17

 [root@asmdb ~]# cat /etc/group | grep dba

dba:x:502:oracle,grid

If you want to create a group with a specific group id, do the following.

# groupadd -g 9090 apache

"passwd" command is used to set/change the users login password.

[root@asmdb ~]# passwd vikramgrg

"who" command -> to list all users who have OS connections.

[root@asmdb ~]# who

[root@asmdb ~]# who | grep -i ora

[root@asmdb ~]# who | wc -l

"grep -i ora" command restricts the output to lines containing "ora".

"wc -l" command returns the number of lines from "who", and hence the number of

connected users.

Process Management

Linux Process Management (ps, top, kill). 

"ps" command lists current process information.

[root@asmdb ~]# ps

[root@asmdb ~]# ps -ef | grep pmon

Specific processes can be killed by specifying the process id in the kill command.

[root@asmdb ~]# kill -9 12345

The "uname" and "hostname" commands can be used to get information about the host.

Page 8: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 8/17

[oracle@asmdb ~]$ uname -a 

Linux asmdb.nepasoft.com.np 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386

GNU/Linux

[oracle@asmdb ~]$ hostname 

asmdb.nepasoft.com.np

*Error Lines in Files

You can return the error lines in a file using.

[oracle@asmdb ~]$ more alert_nepasoft.log | grep -i ORA-

More is a filter for paging through text one screenful at a time.

"-i" flag makes the comparison case insensitive.

Linux Archive Tools (tar, star, gzip, bzip2, zip, cpio). 

In order to save space on the file system you may wish to compress files such as archived redo

logs. This can be using either the gzip or compress commands or Other Compression methods.

gzip myfile

gunzip myfile.gz

free -m

Reports the current memory usage(in MB).

Install RPM(Red Hat Package Manager) packages(.rpm)

The RPM Package Manager (RPM) is an open packaging system, which runs on Red Hat

Enterprise Linux as well as other Linux and UNIX systems. Red Hat, Inc. encourages other

vendors to use RPM for their own products. RPM is distributed under the terms of the GPL.

[root@asmdb ~]# rpm -ivh oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm

[root@asmdb ~]# rpm -Uvh oracleasm-2.6.18-8.el5-2.0.4-1.el5.i686.rpm

{-i -> install , -v -> verbose output, -h -> print hash marks, -U -> Upgrade }

Page 9: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 9/17

Install RPM(Red Hat Package Manager) Using Yum

yum (Yellowdog Updater Modified) is an interactive, rpm based, package manager. perform

installation of new packages, removal of old packages and perform queries on the installed

and/or available packages among many other commands/services.

[root@asmdb ~]# yum install sysstat*.rpm

CRON jobs

CRON : Scheduling Tasks on Linux. 

"crontab -e" option to edit the crontab file directly.

The entries have the following elements.

field allowed values

----- --------------

minute 0-59

hour 0-23

day of month 1-31

month 1-12

day of week 0-7 (both 0 and 7 are Sunday)

command Valid command or script.

Example:-

Execute every Friday 1AM

So if we want to schedule the script to run at 1AM every Friday, we would need the following

cronjob:

[oracle@asmdb asmsoft]$ crontab -e

0 1 * * 5 /bin/execute/this/script.sh

Mount

The following examples illustrate typical uses of the command mount for attaching the file

directory of a device or partition to the file directory tree of the Linux system.

# mkdir /cdmount

# mount /dev/cdrom /cdmount

Page 10: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 10/17

 

View all Mount points

# mount

Append the mount point as following entry to the "/etc/fstab" file( if required) (for makingpermanent mount point).

nfs-server-name:/u04/backup /backup nfs rw,bg,intr 0 0

Finally, mount the fileset.

mount /backup

Useful Files

Here are some files (system administration files) that may be of use.

Path Contents

/etc/passwd User settings

/etc/group Group settings for users.

/etc/hosts Hostname lookup information.

/etc/system Kernel parameters for Solaris.

/etc/sysconfigtab Kernel parameters for Tru64.

/etc/sysctl.conf Kernel parameters for Linux.

Process, IO Monitoring and Swap Recommendations

1)  The top  program provides a dynamic real-time view of a running system i.e. actual

process activity.

$ top –c

how much CPU each job uses.

Page 11: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 11/17

 

The ps (i.e., process status) command is used to provide information about the currently

running processes.

$ ps -ef | grep pmon

ps aux | grep oracle

$ ps -aux | more

-a : list the processes of all users.

-u : detailed information about each process.

-x : option adds to the list processes that have no controlling terminal, such as daemons.

2) 

Linux Performance Monitoring:-

a. 

iostat reports CPU, disk I/O, and NFS statistics.

b.  vmstat reports virtual memory statistics.

c. 

mpstat reports processors statistics.

a)  iostat

:- The iostat  command is used for monitoring system input/output device loading by

observing the time the devices are active in relation to their average transfer rates

b)  vmstat

:- Report virtual memory statistics:- is a tool that collects and reports data about your

system's memory, swap, and processor resource utilization in real time.

It can be used to determine the root cause of performance and issues related to memory use.

The following example illustrates an interval of one (2) second twenty (10) times:

[oracle@npsoftdb ~]$ vmstat 2 10

Page 12: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 12/17

 

Here: 'r' the run queue ,

'b' the wait queue

In the default operation, vmstat displays memory statistics in kilobytes.

Note:- If the sum of columns id (Idle) and wa (Wait IO) is almost 100,this means there are

some configuration problems.

Because the machine is seem it does not doing anything but disk IO operations.

[oracle@npsoftdb ~]$ iostat -d –x

-d : Display the disk device utilization report.

-x : Display extended statistics including disk utilization

How do We interpret the output result for optimization?

The average service time (svctm)

Percentage of CPU time during which I/O requests were issued (%util)

See if a hard disk reports consistently high reads/writes (r/s and w/s)

If any one of these are high, we need to take respective action to resolve the issue

Page 13: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 13/17

 

[oracle@npsoftdb ~]$ iostat

dm-(0-1) logical volumes

c)  mpstat displays CPU statistics.

$ mpstat 

Tmpfs on Linux:-

Using ramfs or tmpfs you can allocate part of the physical memory to be used as a partition.

tmpfs:- shm / shmfs is also known as tmpfs, which is a common name for a temporary file

storage facility on many Unix-like operating systems. It is intended to appear as a mounted file

system, but one which uses virtual memory instead of a persistent storage device.

tmpfs size should be 75% of your physical RAM as per recommendation

tmpfs will use swap space when necessary. If you don't specify the tmpfs size, it'll be

half of your physical RAM without swap.

Page 14: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 14/17

 

Swap partition

swap file or swap partition  used by operating systems (Linux/UNIX/Windows) to provide

virtual memory.

Total of swap and physical memory is the virtual memory.

Note:-  You can use /dev/shm to improve the performance of application software such as

Oracle or overall Linux system performance.

On heavily loaded system, it can make tons of difference.

. Recommended Swap Space Requirements for Oracle Database

Oracle Recommends setting the maximum number of shared-memory segments to 4096

# vi /etc/sysctl.conf

Kernel.shmmni=4096

Virtual Memory

The following values are recommended to control the rate at which virtual memory

is reclaimed. Add the following to /etc/sysctl.conf:

# What: oracle database: tune shared memory size

# When: 12/12/2011

# Who: J. B. Admin, jba@localhost

vm.swappiness=0

vm.dirty_background_ratio=3

vm.dirty_ratio=15

vm.dirty_expire_centisecs=500

vm.dirty_writeback_centisecs=100

To see all shared memory segments that are allocated on the system, execute:

Page 15: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 15/17

$ ipcs -m

nattch is the number of currently attached processes

If counter is greater than 0, then the resource is available, and if the counter is 0 or less, thenthat resource is busy or being used by someone else. This simple mechanism helps in

synchronizing multithreaded and multiprocess based applications

(Semaphores can be thought of as simple counters that indicate the status of a resource)

[root@npsoftdb ~]# df -h

How to mount and edit Tmpfs size.

# mkdir -p /mnt/tmp

# mount -t tmpfs -o size=1G tmpfs /mnt/tmp

Or edit an existing value in /etc/fstab something like this

Page 16: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 16/17

# mount -o remount /dev/shm

# df –h

Use a Hard Drive Partition for Additional Swap Space

# mkswap /dev/sda5

# swapon /dev/sda5

Page 17: UNIXLInux for Oracle DBAMustKnow-libre

7/23/2019 UNIXLInux for Oracle DBAMustKnow-libre

http://slidepdf.com/reader/full/unixlinux-for-oracle-dbamustknow-libre 17/17

To make this swap space partition available even after the reboot, add the following line to the

/etc/fstab file.

# vi /etc/fstab

/dev/ sda5 swap swap defaults 0 0

Verify whether the newly created swap area is available for your use.

# swapon –s

# free –m

If you do’t hae ay additioal disks, you ca create a file soehere o your filesysteusig

dd command), and use that file for swap space.