Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Saturday, September 27, 2008

File Management in UNIX

Finding Large Files in the server

# find . -size +10000 -print
The above command prints all the files whose size is greater than 10,000 bytes. This command is very useful when the disk space is nearing 100%.

Changing File Permissions
Unix Permission Values
4-Read Permission
2-Write Permission
1-Execute Permission
Thus, if a file permission is 751, it means read+write+execute permission to owner. 

# ls -l temp
-rw-rw-rw- 1 root dba 0 Apr 21 11:55 temp

Let me explain what "-rw-rw-rw-" means. 
  1. The first '-' indicates that it is a plain file. If it is a directory, then it would start with 'd'. 
  2. rw means read+write permission. The corresponding numeric values are 4 & 2 respectively. When you add it, you get 6. so the permission of the file is 666.
How to change File Ownership?
To change the current ownership of a file, use 'chown' (change owner) command.
To find the current owners of the files under a directory, just issue the command,

# ls -al
The third column lists out the owners of each file & directory.

Now issue the command,

# chown oracle:ocsinfra *

How to change File Permissions?

# chmod 774 *

By using the above command, you can make the files & directory under the current directory r+w+e for the owner and its group and read permission to the rest.

Memory, CPU & Disk Management in Solaris

I. Display RAM Size

# prtconf | grep -i mem
The above command displays the total available RAM in the server
II. Display Number of CPUs

# psrinfo -v | wc -l

III. System Activity Reporter
The sar utility gives detailed information about oracle tasks from the unix level.

# sar -u 2 5
gives the CPU activity by taking 5 samples at 2 seconds interval 

# sar -w 5 5
gives the swapping activity report by taking 5 samples at 5 seconds interval

#sar -b 1 6
gives the buffer activity report

Iostat is an Unix utility which gives elapsed I/O against the physical disks.It is very useful to find out busy disks.

# iostat 2
The second parameter is the interval in seconds.

To display the mount points issue the command as below,
$ df –k

Unix for Oracle DBAs- Basic Unix Commands

1) Finding list of active processes running on the server
First step, to find out the list of active processes on the server, just run the command

$ ps -ef

You will see a big list of processes. Just limit the list to only related to oracle database by issuing the following command

$ ps -ef |grep "ora_"

The above command will remove all but the Oracle background processes since the oracle background process always start with 'ora_". 
You will again note that the output includes the process thats running the grep command. Now pipe the output to "grep -v grep" to exclude that process. Now the command becomes

$ ps -ef |grep "ora_" |grep -v grep 

grep -v option excludes the required string.

Still, we have filter out processes which is related only to a particular SID. Now append this filter like the following,

$ ps -ef |grep "ora_" |grep -v grep | grep $ORACLE_SID

2) Kill active processes running on the server
To kill background Unix process, use the 'kill' command. The syntax of using this command is as follows,
$ kill -9 PID1 PID2 PID3
The "-9" directs unix to kill the process immediately.

3) Finding Strings
Use the find command to find any matching strings in any files. For e.g. if you want to search for 'ServerAdmin' , then issue the command as follows,

$ find . -print |xargs grep -i ServerAdmin
-i option is used for 'ignore case'

4)Monitor Execution of a Process
Since most of the oracle processes are written to a logfile, the process can be monitored by using the following command,
$ tail -f opmn.log

5) Process Management
If you want to display top CPU consumers on a server, just issue the command,

$ ps -ef | sort +6| tail
Or
$ ps -ef | sort +7| tail

Since the Unix sort command sorts it according in ascending order, the process which consumes most CPU will be at the end of the list.

6) Get Active Oracle Dedicated Connections
$ ps -ef | grep -v grep|grep $ORACLE_SID|grep -v "ora_"|wc -l

In the above command, grep -v "ora_" excludes all the background oracle processes.

How to search for a string recursively in UNIX/Solaris?

Go to the Parent folder from where the text has to be searched. Then, use the following
UNIX command,
$ find * -type fl -print | xargs grep "<text_to_search>" | more