Most frequently used unix commands for database administrator

20
Most Frequently Used UNIX Commands For DBAs WHITE PAPER Author: Suparna Chaudhuri
  • date post

    22-Oct-2014
  • Category

    Technology

  • view

    263
  • download

    0

description

Linux useful commands

Transcript of Most frequently used unix commands for database administrator

Page 1: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

WHITE PAPER

Author: Suparna Chaudhuri

Table of ContentsIntroduction....................................................................................................................3File & Directory Navigation..........................................................................................4File Permissions..............................................................................................................7OS Users Management...................................................................................................8Process Monitoring.........................................................................................................9uname and hostname....................................................................................................10

Page 2: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

Compress Files..............................................................................................................10Performance Monitoring.............................................................................................11CPU Utilization.............................................................................................................11Disk Space Usage..........................................................................................................13CRON............................................................................................................................14References.....................................................................................................................15About the Authors........................................................................................................15

Page 3: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

Introduction

This paper contains common UNIX commands for DBAs. This is not a complete but a compact list of commands used on regular basis. This will give you a jumpstart on some of the common Linux commands. All UNIX commands and filenames are case sensitive.

Page 4: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

File & Directory Navigation

catcat filenameDisplay a filename

cat /etc/passwdcat bigfile | more

cdcd dirnameChange from one directory to other directory.

cd /oraData

cpcp file1 file2Copies one file/directory to specified location.

cp data.txt /tmp

filefile filenameIdentifies the type of file type like binary, text.

File /dev/wd0afile compressed.gz

findfind filename/dirFinds a file/directory.

find /usr –name *stat

Find every file under the directory /usr ending in "stat".

headhead filenameShows the beginning of a file.

head –n 5 mydoc.txt

Page 5: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

To view the first n number of lines.

lessless filenameAllows you to quickly view the file.

less table1

It will display the top of the file, ‘table1’.

lsls dirnameList directory contents

ls /home/usr/doc/book

mkdirmkdir dirnameCreates the specified directory.

mkdir mydir

moremore filenameThe more command writes your file onto the screen one page at a time.

ls –a | more

mvmv file1 file2Moves the location of or renames a file/directory.

mv my_file.txt your_file.txt

pwdShows the current directory the user is in

root>pwd

/u01/app/oracleproduct/9.2.0.1.0

rmrm filenameRemoves a file.

Page 6: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

rm my_file.txtrm –R /archievelog

rmdirrmdir dirnameRemoves a directory.

rmdir backup

tailtail filenameShows the end of a file.

tail dblog.txt

This command will print the last ten line of the file named dblog.txt.

tail dblog.txt –n 100

This command will print the last 100 lines of the file named dblog.txt.

touchtouch filename

Creates a blank file or modifies an existing file”s access and modification time.

touch newfile.log

Creates a file known as newfile.log, if it does not already exist. If the file already exists the accessed and modification time will be updated for the file, newfile.log.

whereiswhereis filenameShows the location of a file.

whereis –b ls

ls: /bin/ls

whichwhich filenameShows the location of a file if it is in your PATH.

oracle> which sqlplusThe "which" command searches PATH setting for occurrences of the specified executable.

Page 7: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

File Permissions

umaskWhen user creates a file or directory under Linux or UNIX, he/she creates it with a default set of permissions. The user file-creation mode mask (umask) is used to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number.You can setup umask in /etc/bashrc or /etc/profile file for all users.

The octal notations are as follows:Octal value : Permission

0 : read, write and execute1 : read and write2 : read and execute3 : read only4 : write and execute5 : write only6 : execute only7 : no permissions

root>umask 022

chmodChanges the permission of a file.

Permissionsu - User who owns the file.g - Group that owns the file.o - Other.a - All.r - Read the file.w - Write or edit the file.x - Execute or run the file as a program.

root > chmod 644 file.htmroot> chmod o+rwx *.logroot> chmod g+r *.log

chownchown command changes the user and/or group ownership for a given file.chown owner-user filechown owner-user:owner-group file

root> ls –l testjar.sh

Page 8: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

-rw-r--r-- 1 root root 0 Aug 31 05:48 testjar.sh

root> chown schau testjar.sh

root> ls –l testjar.sh

-rw-r--r-- 1 schau root 0 Aug 31 05:48 testjar.sh

chgrpchgrp command changes group associated to a file/folder from one group to other.Change group name:sales of a file to other group name:hrgroup

chgrp hrgroup file1

OS Users Management

useraddThis command is used to create new users and also update default new user information.

root> useradd -G oinstall -g dba -d /usr/users/my_user -m -s /bin/ksh my_userThe "-G" flag specifies the primary group. The "-g" flag specifies the secondary group. The "-d" flag specifies the default directory. The "-m" flag creates the default directory. The "-s" flag specifies the default shell. When a user account is created, some extra information is associated with account by default. To view these default values, use the -D option along with this command.

[root@houora27 ~]# useradd -D

GROUP=100HOME=/homeINACTIVE=-1EXPIRE=SHELL=/bin/bashSKEL=/etc/skel

usermodThe "usermod" command is used to modify the user settings after a user has been created:

root> usermod -s /bin/csh my_user

userdelThe "userdel" command is used to delete existing users:

root> userdel -r my_user

Page 9: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

The "-r" flag removes the default directory.

passwd

The "passwd" command is used to set, or reset, the users login password:

root> passwd my_user

whoThe "who" command can be used to list all users who have OS connections:

root>whoroot>who | head -5root>who | tail -5root>who | grep –I oraroot>who | wc -1

The "head -5" command restricts the output to the first 5 lines of the who command. The "tail -5" command restricts the output to the last 5 lines of the who command. The "grep -i ora" command restricts the output to lines containing "ora". The "wc -l" command returns the number of lines from "who", and hence the number of connected users.

groupaddgroupadd command is used to create group accounts. It updates the /etc/group file accordingly.

root> ls –l testjar.sh

If you want to create a group with a specific group id use below command.

root> groupadd dbgrp –g 9090

groupdelThis command will remove a group.

groupdel dbgrp

Process Monitoring

ps

This command lists current process information.

[oracle@houora27 oracleData]$ ps

PID TTY TIME CMD

Page 10: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

12326 pts/1 00:00:00 bash12874 pts/1 00:00:00 ps

[oracle@houora27 oracleData]$ ps -ef|grep -i ora

oracle 11217 1 0 Jul22 ? 00:01:23 /opt/Oracle/DB10gR2/beta4/product/10.2.0/db_1/bin/tnslsnr LISTENER -inheritoracle 11226 1 0 Jul22 ? 00:03:52 ora_pmon_BETA4oracle 11228 1 0 Jul22 ? 00:00:06 ora_psp0_BETA4oracle 11230 1 0 Jul22 ? 00:02:07 ora_mman_BETA4oracle 11232 1 0 Jul22 ? 00:05:34 ora_dbw0_BETA4oracle 11234 1 0 Jul22 ? 02:13:47 ora_lgwr_BETA4oracle 11236 1 0 Jul22 ? 00:03:43 ora_ckpt_BETA4oracle 11238 1 0 Jul22 ? 00:04:32 ora_smon_BETA4oracle 11240 1 0 Jul22 ? 00:00:00 ora_reco_BETA4

-e – to display all processes-f – to display full format listing

uname and hostnameThe "uname" and "hostname" commands can be used to get information about the host:

[oracle@houora27 oracleData]$ uname –a

Linux houora27 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686 i686 i386 GNU/Linux

[oracle@houora27 oracleData]$ hostnamehouora27

Compress FilesTo save space on the filesystem user can compress files such as archived redo logs. This can be using gzip. The gzip command results in a compressed copy of the original file with a ".gz" extension. The gunzip command reverses this process:

gzipgzip myfileCompresses the file myfile, making it myfile.gz. Note. When doing this the original file will no longer exist on the drive.

gunzipgunzip -f myfile.gz

Page 11: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

Uncompress the file myfile.gz and if the uncompressed file(s) already exist force an overwrite. When doing this the file myfile.gz will no longer be on the drive.

gunzip -c myfile.gz > myfile.txt

Uncompress the file myfile.tz to the myfile.txt file, however, don't delete the .gz file. This is useful if you don't want to delete the .gz and keep it with the uncompressed file.

Performance Monitoring

vmstatvmstat will display the memory usage.

[oracle@houora27 oracleData]$ vmstat 5 3

Displays system statistics (5 seconds apart; 3 times)

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 21744 40832 78420 3535796 0 0 1 4 2 5 19 41 35 5 1 0 21744 40768 78440 3535776 0 0 0 188 1041 114 25 27 44 4 1 0 21744 40784 78460 3535756 0 0 0 160 1036 108 24 28 45 4

vmstat output contains the following fields:

Procs – r: Total number of processes waiting to run Procs – b: Total number of busy processes Memory – swpd: Used virtual memory Memory – free: Free virtual memory Memory – buff: Memory used as buffers Memory – cache: Memory used as cache. Swap – si: Memory swapped from disk (for every second) Swap – so: Memory swapped to disk (for every second) IO – bi: Blocks in. i.e blocks received from device (for every second) IO – bo: Blocks out. i.e blocks sent to the device (for every second) System – in: Interrupts per second System – cs: Context switches CPU – us, sy, id, wa, st: CPU user time, system time, idle time, wait time

CPU Utilization

top

The top program provides a dynamic real-time view of a running system. It displays system summary information; list of tasks currently being managed by the Linux kernel.The top command monitors CPU utilization, process statistics, and memory utilization.

Page 12: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

root>top

top - 12:04:31 up 43 days, 18:31, 1 user, load average: 1.01, 1.20, 1.24Tasks: 114 total, 2 running, 112 sleeping, 0 stopped, 0 zombieCpu(s): 24.8% us, 27.2% sy, 0.0% ni, 45.0% id, 3.0% wa, 0.0% hi, 0.0% siMem: 4148916k total, 4123052k used, 25864k free, 4136k buffersSwap: 6289436k total, 21672k used, 6267764k free, 3631960k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2470 root 25 0 11464 4552 2584 R 99.9 0.1 3354:21 snmpd11295 oracle 16 0 2340m 2.1g 2.1g S 0.7 53.1 1188:31 oracle11299 oracle 16 0 2340m 2.1g 2.1g S 0.7 53.0 549:18.14 oracle11301 oracle 16 0 2344m 2.1g 2.1g S 0.7 52.6 180:57.14 oracle11303 oracle 16 0 2338m 2.1g 2.1g S 0.7 52.3 58:32.22 oracle16366 root 17 0 3336 944 740 R 0.7 0.0 0:00.05 top

mpstat

For multiple CPU system mpstat command displays the utilization of each CPU individually. It reports processors related statistics.

root>mpstatLinux 2.6.9-34.ELsmp (houora27) 09/03/2013

12:07:09 PM CPU %user %nice %system %iowait %irq %soft %idle intr/s12:07:09 PM all 18.13 0.93 40.86 4.62 0.01 0.00 35.44 1065.19

sarThis command displays today’s cpu activity.

root>sar

Linux 2.6.9-34.ELsmp (houora27) 09/03/2013

12:00:01 AM CPU %user %nice %system %iowait %idle12:10:01 AM all 24.42 0.00 28.04 4.67 42.8712:20:01 AM all 24.60 0.00 28.10 4.57 42.7312:30:01 AM all 24.36 0.00 28.12 4.69 42.8412:40:01 AM all 24.89 0.00 28.18 3.09 43.8512:50:02 AM all 24.42 0.00 28.03 2.95 44.6001:00:01 AM all 24.51 0.00 28.09 3.18 44.2201:10:01 AM all 24.33 0.00 28.10 3.11 44.4601:20:01 AM all 24.43 0.00 28.05 2.97 44.55

Where,%user: Percentage of CPU utilization that occurred while executing at the user level (application).

Page 13: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

%nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority. %system: Percentage of CPU utilization that occurred while executing at the system level (kernel). %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

Disk Space Usage

dfThis command displays the file system disk space usage.

root>df –k

displays output in bytes

Filesystem 1K-blocks Used Available Use% Mounted on/dev/sda2 20641788 9019860 10573288 47% //dev/sdb1 70557052 14689764 52283192 22% /Misc/dev/sda1 101086 11506 84361 13% /bootnone 2063504 35880 1922804 2% /dev/shm/dev/sda6 2063504 35880 1922804 2% /dev/shm/dev/sda5 20641788 5846244 13746904 30% /opt/dev/sdc1 288362876 171807444 101907368 63% /oracleBackup/dev/sdd1 288362876 260358600 13356212 96% /oracleData

root>df –h

displays output in human readable form.

Filesystem Size Used Avail Use% Mounted on/dev/sda2 20G 8.7G 11G 47% //dev/sdb1 68G 15G 50G 22% /Misc/dev/sda1 99M 12M 83M 13% /bootnone 2.0G 36M 1.9G 2% /dev/shm/dev/sda6 2.0G 36M 1.9G 2% /dev/shm/dev/sda5 20G 5.6G 14G 30% /opt/dev/sdc1 276G 164G 98G 63% /oracleBackup/dev/sdd1 276G 249G 13G 96% /oracleData

root>df –T

displays what type of file system

Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sda2 ext3 20641788 9019860 10573288 47% /

Page 14: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

/dev/sdb1 ext3 70557052 14689764 52283192 22% /Misc/dev/sda1 ext3 101086 11506 84361 13% /bootnone tmpfs 2063504 35880 1922804 2% /dev/shm/dev/sda6 ext3 2063504 35880 1922804 2% /dev/shm/dev/sda5 ext3 20641788 5846244 13746904 30% /opt/dev/sdc1 ext3 288362876 171807444 101907368 63% /oracleBackup/dev/sdd1 ext3 288362876 260358600 13356212 96% /oracleData

CRONCrontab command is used to schedule commands to be executed periodically.Using below command you can see what crontabs are currently running on your system.

root> crontab -1

There are two methods of editing the crontab file.

You can use the "crontab -l > filename" option to list the contents and pipe this to a file. After editing the file you can apply it using the "crontab filename":

Login as root crontab -l > newcrontabfile Edit newcrontabfile file. crontab newcrontabfile

You can use the "crontab -e" option to edit the crontab file directly.

root> crontab –e

* * * * * /bin/execute/test.sh

There are 5 stars which represent different date parts in the following order:

minute (from 0 to 59) hour (from 0 to 23) day of month (from 1 to 31) month (from 1 to 12) day of week (from 0 to 6) (0=Sunday)

Using below statement you can schedule the script to run at 1AM every Friday.

0 1 * * 5 /bin/execute/test.sh

Page 15: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

References

1. http://www.tjhsst.edu/~dhyatt/superap/unixcmd.html 2. http://kb.iu.edu/data/afsk.html

About the Authors

Name Suparna ChaudhuriE-Mail [email protected] OracleEmployee ID 142476

Page 16: Most frequently used unix commands for database administrator

Most Frequently Used UNIX Commands For DBAs

About Wipro Technologies

Wipro is the first PCMM Level 5 and SEI CMMi Level 5 certified IT Services Company globally. Wipro provides comprehensive IT solutions and services (including systems integration, IS outsourcing, package implementation, software application development and maintenance) and Research & Development services (hardware and software design, development and implementation) to corporations globally.

Wipro's unique value proposition is further delivered through our pioneering Offshore Outsourcing Model and stringent Quality Processes of SEI and Six Sigma.

© Copyright 2013. Wipro Technologies. All rights reserved. No part of this document may be reproduced, stored in a retrieval system, transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without express written permission from Wipro Technologies. Specifications subject to change without notice. All other trademarks mentioned herein are the property of their respective owners.