Thursday, February 27, 2014

Rman backup type

RMAN is very flexible and it offers many different types of backups.  We need to start with a list of backup types:

Full backup:  A full backup backs up all data files in the database, block-by-block, a standalone backup with you need to recover to the point in time when the full backup was collected.

 Level 1 backup:  A level 1 backup includes only those blocks that have been changed since the  last backup taken . Remember a last  backup may be either a level 0 or a level 1 backup.

·Level 0 backup:  A level 0 incremental backup is physically identical to a full backup and it includes every data  block in the file except empty blocks. The only difference is that the level 0 backup is recorded as an incremental backup in the RMAN repository, so it can be used as the parent for a level 1 backup.

Incremental backup:  An incremental backup can be either level 0 or level 1.
There are two types of incremental backups, “differential” and “cumulative”.
Differential vs. incremental cumulative backups.

Differential Incremental Backup:  When using differential incremental backup (the default type of incremental backup), RMAN looks for changed data blocks which were changed after last level 1 incremental backup. It there’s no level 1 backup made before it, it takes a backup of the changed data blocks which were made after level 0 incremental backup.

Cumulative Incremental Backup:  In a cumulative incremental backup RMAN takes backup of all changed data blocks after level 0 or level 1 incremental backup.  Like a differential backup, incremental backups also back up only the changed  data blocks, but an incremental backup only backs up the data that has changed since the last backup.  If the last backup was  also an incremental backup, the current incremental backups only records “changes to the changes”, a much smaller set of block  changes, and hence, a much smaller recovery time than a differential backup

VI editor in Linux

There are many ways to edit files in Unix and for me one of the best ways is using screen-oriented text editor vi.
This editor enable you to edit lines in context with other lines in the file.

Now a days you would find an improved version of vi editor which is called VIM. Here VIM stands for Vi Improved.
Its usually available on all the flavors of Unix system.
Its implementations are very similar across the board.
It requires very few resources.
It is more user friendly than any other editors like ed or ex.

Moving within a File:
To move around within a file without affecting your text, you must be in command mode (press Esc twice). Here are some of the commands you can use to move around one character at a time:

Command Description
k Moves the cursor up one line.
j Moves the cursor down one line.
h Moves the cursor to the left one character position.
l Moves the cursor to the right one character position.
There are following two important points to be noted:

The vi is case-sensitive, so you need to pay special attention to capitalization when using commands.

Most commands in vi can be prefaced by the number of times you want the action to occur. For example, 2j moves cursor two lines down the cursor location.

There are many other ways to move within a file in vi. Remember that you must be in command mode (press Esc twice). Here are some more commands you can use to move around the file:

Command Description
0 or | Positions cursor at beginning of line.
$ Positions cursor at end of line.
w Positions cursor to the next word.
b Positions cursor to previous word.
( Positions cursor to beginning of current sentence.
) Positions cursor to beginning of next sentence.
E Move to the end of Blank delimited word
{ Move a paragraph back
} Move a paragraph forward
[[ Move a section back
]] Move a section forward
n| Moves to the column n in the current line
1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file
fc Move forward to c
Fc Move back to c
H Move to top of screen
nH Moves to nth line from the top of the screen
M Move to middle of screen
L Move to botton of screen
nL Moves to nth line from the bottom of the screen
:x Colon followed by a number would position the cursor on line number represented by x
Control Commands:
There are following useful command which you can use along with Control Key:

Command Description
CTRL+d Move forward 1/2 screen
CTRL+d Move forward 1/2 screen
CTRL+f Move forward one full screen
CTRL+u Move backward 1/2 screen
CTRL+b Move backward one full screen
CTRL+e Moves screen up one line
CTRL+y Moves screen down one line
CTRL+u Moves screen up 1/2 page
CTRL+d Moves screen down 1/2 page
CTRL+b Moves screen up one page
CTRL+f Moves screen down one page
CTRL+I Redraws screen
Editing Files:
To edit the file, you need to be in the insert mode. There are many ways to enter insert mode from the command mode:


Command Description
i Inserts text before current cursor location.
I Inserts text at beginning of current line.
a Inserts text after current cursor location.
A Inserts text at end of current line.
o Creates a new line for text entry below cursor location.
O Creates a new line for text entry above cursor location.
Deleting Characters:
Here is the list of important commands which can be used to delete characters and lines in an opened file:

Command Description
x Deletes the character under the cursor location.
X Deletes the character before the cursor location.
dw Deletes from the current cursor location to the next word.
d^ Deletes from current cursor position to the beginning of the line.
d$ Deletes from current cursor position to the end of the line.
D Deletes from the cursor position to the end of the current line.
dd Deletes the line the cursor is on.
As mentioned above, most commands in vi can be prefaced by the number of times you want the action to occur. For example, 2x deletes two character under the cursor location and 2dd deletes two lines the cursor is on.

I would highly recommend to exercise all the above commands properly before proceeding further.

Change Commands:
You also have the capability to change characters, words, or lines in vi without deleting them. Here are the relevant commands:

Command Description
cc Removes contents of the line, leaving you in insert mode.
cw Changes the word the cursor is on from the cursor to the lowercase w end of the word.
r Replaces the character under the cursor. vi returns to command mode after the replacement is entered.
R Overwrites multiple characters beginning with the character currently under the cursor. You must use Esc to stop the overwriting.
s Replaces the current character with the character you type. Afterward, you are left in insert mode.
S Deletes the line the cursor is on and replaces with new text. After the new text is entered, vi remains in insert mode.
Copy and Past Commands:
You can copy lines or words from one place and then you can past them at another place using following commands:

Command Description
yy Copies the current line.
yw Copies the current word from the character the lowercase w cursor is on until the end of the word.
p Puts the copied text after the cursor.
P Puts the yanked text before the cursor.
Advanced Commands:
There are some advanced commands that simplify day-to-day editing and allow for more efficient use of vi:

Command Description
J Join the current line with the next one. A count joins that many lines.
<< Shifts the current line to the left by one shift width.
>> Shifts the current line to the right by one shift width.
~ Switch the case of the character under the cursor.
^G Press CNTRL and G keys at the same time to show the current filename and the status.
U Restore the current line to the state it was in before the cursor entered the line.
u Undo the last change to the file. Typing 'u' again will re-do the change.
J Join the current line with the next one. A count joins that many lines.
:f Displays current position in the file in % and file name, total number of file.
:f filename Renames current file to filename.
:w filename Write to file filename.
:e filename Opens another file with filename.
:cd dirname Changes current working directory to dirname.
:e # Use to toggle between two opened files.
:n In case you open multiple files using vi, use :n to go to next file in the series.
:p In case you open multiple files using vi, use :p to go to previous file in the series.
:N In case you open multiple files using vi, use :N to go to previous file in the series.
:r file Reads file and inserts it after current line
:nr file Reads file and inserts it after line n.

You can use vi editor to edit an existing file or to create a new file from scratch. You can also use this editor to just read
a text file

Ex mode commands:
  q       Quit                        set <x>   Enable option
  q!      Quit, discard changes       set no<v> Disable option
  r <f>   Read in file <f>            set all   Show all options
  sh      Invoke shell
  vi      Vi mode
  wq      Write and quit
  w <f>   Write file <f>
  w! <f>  Overwrite file <f>

Tuesday, February 18, 2014

Linux command part 2

1. echo: Print message on the terminal
  echo “<message>”
$ echo "Welcome to the workshop"
Welcome to the workshop                 

2-cat: command is used to display the contents of a small file
on terminal

3-gzip: command is used to compress the file, and gunzip is
used to de-compress it.
 usage: gzip <file name>

4-gunzip :The compression ratio depends on the type, size and
nature of the file
 usage: gunzip <file name with.gz>

5- head: command displays the top of the file, when used
without any option it will display first 10 lines of the file

6 tail-Similarly tail command displays the end of the file. By
default it will display last 10 lines of the file

7-exit-To leave the remote computer.

8-rmdir-Delete a empty folder.

9-ps-ps shows you your running jobs.

10-vim – Vi Improved, a programmers text editor   

11- cp – copy files and directories

12-find – search for files in a directory hierarchy

13-history – prints recently used commands  

14-grep ­ print lines matching a pattern   

15-wc ­ print the number of newlines, words, and bytes in files

16-sort – sort lines of text files   

17- chmod – change file access permissions

18-chown – change file owner and group  

19 su –  change user ID or become super­user

20-passwd – update  a user’s authentication tokens(s)

21-who – show who is logged on  

22-kill – to kill a process(using signal mechanism)

23- ssh – SSH client (remote login program)                                    
    “ssh is a program for logging into a remote machine and for         
   executing commands on a remote machine
24-scp – secure copy (remote file copy program)                            
          “scp copies files between hosts on a network” 
25-fdisk – partition manipulator

26-mount – mount a file system                                                  
    Usage: mount ­t type device dir   

27-umount – unmount file systems                                             
    Usage: umount [OPTIONS] dir | device

28- du – estimate file space usage                                                           
     Usage:  du [OPTION]... [FILE]..

29-df – report filesystem disk space usage                                            
    Usage: df [OPTION]... [FILE]... 

30-reboot – reboot the system   

31-• poweroff – power off the system   

32-locate – find or locate a file

33-kate – KDE Advanced Text Editor  

34-• gedit ­ A text Editor. Used to create and edit files.
35-jobs – displays the names and ids of background jobs  


Monday, February 17, 2014

Some thing about Undo

Oracle Database creates and manages information that is used to roll back, or undo, changes to the database.
 Such information consists of records of the actions of transactions, primarily before they are committed. These records
 are collectively referred to as undo.

Undo records are used to:
Roll back transactions when a ROLLBACK statement is issued
Recover the database
Provide read consistency
Analyze data as of an earlier point in time by using Oracle Flashback Query
Recover from logical corruptions using Oracle Flashback features

When a ROLLBACK statement is issued, undo records are used to undo changes that were made to the database by the
uncommitted transaction. During database recovery, undo records are used to undo any uncommitted changes applied
from the redo log to the data files. Undo records provide read consistency by maintaining
the before image of the data for users who are accessing the data at the same time that another user is changing it.

• There are two methods for managing undo data:
– Automatic Undo Management
– Manual Undo Management

Managing Undo Data
Automatic Undo Management
The Oracle server automatically manages the creation, allocation, and tuning of undo segments.

Manual Undo Management
You manually manage the creation, allocation, and tuning of undo segments. It was the only
method available prior to Oracle9i.

Undo Segment
An undo segment is used to save the old value (undo data) when a process changes data in a
database. It stores the location of the data and the data as it existed before being modified.
The header of an undo segment contains a transaction table where information about the
current transactions using the undo segment is stored.
A serial transaction uses only one undo segment to store all of its undo data.
Many concurrent transactions can write to one undo segment.

Undo Segments: Purpose
Transaction Rollback
When a transaction modifies a row in a table, the old image of the modified columns (undo
data) is saved in the undo segment. If the transaction is rolled back, the Oracle server restores
the original values by writing the values in the undo segment back to the row.

Transaction Recovery
If the instance fails while transactions are in progress, the Oracle server needs to undo any
uncommitted changes when the database is opened again. This rollback is part of transaction
recovery. Recovery is possible only because changes made to the undo segment are also
protected by the online redo log files.

Read Consistency
While transactions are in progress, other users in the database should not see any uncommitted
changes made by these transactions. In addition, a statement should not see any changes that
were committed after the statement begins execution. The old values (undo data) in the undo

segments are also used to provide the readers a consistent image for a given statement.

Shared Pool

Shared Pool
The Shared Pool environment contains both fixed and variable structures. The fixed
structures remain relatively the same size, whereas the variable structures grow and shrink
based on user and program requirements. The actual sizing for the fixed and variable
structures is based on an initialization parameter and the work of an Oracle internal
algorithm.

Benefits of Using the Shared Pool
Proper use and sizing of the shared pool can reduce resource consumption in at least four ways:
1-If the SQL statement is in the shared pool, parse overhead is avoided, resulting in reduced CPU resources on the system and elapsed time for the end user.
2-Latching resource usage is significantly reduced, resulting in greater scalability.
3-Shared pool memory requirements are reduced, because all applications use the same pool of SQL statements and dictionary resources.
4-I/O is reduced, because dictionary elements that are in the shared pool do not require disk access

There are two parts of Shared Pool
1-Library Cache
2-Data Dictionary Cache
1- Library cache
                The library cache stores the executable (parsed or compiled) form of recently referenced SQL and PL/SQL code.The Library Cache is managed by an LRU algorithm.It contains -
               
Shared SQL: The Shared SQL stores and shares the execution plan and parse tree for
SQL statements run against the database. The second time that an identical SQL
statement is run, it is able to take advantage of the parse information available in the
shared SQL to expedite its execution. To ensure that SQL statements use a shared SQL
area whenever possible, the text, schema, and bind variables must be exactly the same.

Shared PL/SQL: The Shared PL/SQL area stores and shares the most recently
executed PL/SQL statements. Parsed and compiled program units and procedures
(functions, packages, and triggers) are stored in this area.

2- Data Dictionary Cache
The Data Dictionary Cache is also referred to as the dictionary cache or row cache.
Information about the database (user account data, data file names, segment names, extent
locations, table descriptions, and user privileges) is stored in the data dictionary tables.
When this information is needed by the server, the data dictionary tables are read, and the

data that is returned is stored in the Data Dictionary Cache.

Saturday, February 15, 2014

Cold backup and hot backup in Oracle

Cold Backup,
A cold backup is taking a backup of the database while it is shut down and does not require being in archive log mode. The benefit of taking a cold backup is that it is typically easier to administer the backup and recovery process.It is  Copying the three sets of files (database files, redo logs, and control file) when the instance is shut down.You must shut down the  instance to guarantee a consistent copy.
If a cold backup is performed, the only option available in the event of data file loss is restoring all the files from the latest backup. All work performed on the database since the last backup is lost.


 Hot Backup:
A hot backup is basically taking a backup of the database while it is still up and running and it must be in archive log mode.We use to setup host back where cannot shut down the database while making a backup copy of the files.Or the cold backup is not an available option.
If a data loss failure does occur, the lost database files can be restored using the hot backup and the online and offline redo logs created since the backup was done. The database is restored to the most consistent state without any loss of  committed transactions.The benefit of taking a hot backup is that the database is still available for use while the backup is occurring and
 you can recover the database to any point in time.


Some Oracle Sql Scripts ,

                    Helpful script to check running sql if we know SID detail.

Alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
Select   .spid,s.sid,s.serial#, s.p1,s.p1text,s.username,s.status, s.last_call_et,p.program,
p.terminal,s.logon_time,s.module,s.osuser,l.SQL_TEXT from V$process p,V$session s,v$sql l where s.paddr = p.addr and l.SQL_ID=s.SQL_ID and l.HASH_VALUE=s.SQL_HASH_VALUE and  .ADDRESS=s.SQL_ADDRESS and s.MODULE='&SID';


                 Helpful script to check running session detail from Toad, 

Alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
select  p.spid,s.sid,s.serial#,s.p1,s.p1text,s.username,s.status,
s.last_call_et,p.program,p.terminal,s.logon_time,s.module,s.osuser,l.SQL_TEXT
,s.TERMINAL from V$process p,V$session s,v$sql l
where s.paddr = p.addr and l.SQL_ID=s.SQL_ID and l.HASH_VALUE=s.SQL_HASH_VALUE  and l.ADDRESS=s.SQL_ADDRESS
and s.MODULE='T.O.A.D.';

               Helpful script to check total number of sql from user .

Select count(SID) "Total number of session",USERNAME,status from v$session where type='USER' group by USERNAME,status ;

                 Helpful script to check session detail if we have PID /OS Process id.

SELECT
           'USERNAME   : ' || s.username     || CHR(10) ||
           'SCHEMA     : ' || s.schemaname   || CHR(10) ||
           'OSUSER     : ' || s.osuser       || CHR(10) ||
           'PROGRAM    : ' || s.program      || CHR(10) ||
           'SPID       : ' || p.spid         || CHR(10) ||
           'SID        : ' || s.sid          || CHR(10) ||
           'SERIAL#    : ' || s.serial#      || CHR(10) ||
           'KILL STRING: ' || '''' || s.sid || ',' || s.serial# || ''''  || CHR(10) ||
           'MACHINE    : ' || s.machine      || CHR(10) ||
           'TYPE       : ' || s.type         || CHR(10) ||
           'TERMINAL   : ' || s.terminal     || CHR(10) ||
           'SQL ID     : ' || q.sql_id       || CHR(10) ||
           'SQL TEXT   : ' || q.sql_text
           FROM v$session s  ,v$process p ,  v$sql     q
WHERE s.paddr  = p.addr
AND   p.spid   = '&PID_FROM_OS'
AND   s.sql_id = q.sql_id(+);

                We can find out Plan for any session if we know sqlid.
SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR(('&&sql_id')));





TableSpace Script

Below script is helpful to check tablepsace  detail.
col "Tablespace" for a22
col "Used MB" for 99,999,999
col "Free MB" for 99,999,999
col "Total MB" for 99,999,999

Select
   fs.tablespace_name                          "Tablespace",
  df.totalspace                               "TOT_SIZE",
  fs.freespace                                "TOT_FREE",
  (round(100 * (fs.freespace / df.totalspace))) pct_Free
from
   (select      tablespace_name,
      round(sum(bytes) / 1048576) TotalSpace
   from
      dba_data_files
   group by
      tablespace_name
   ) df,
   (select
      tablespace_name,
      round(sum(bytes) / 1048576) FreeSpace
   from
      dba_free_space
   group by
      tablespace_name  ) fs
where   (df.tablespace_name = fs.tablespace_name ) and fs.tablespace_name like '%&TBS%' ORDER BY pct_free DESC ;

Friday, February 14, 2014

Linux Command

This article provides practical examples for 50 most frequently used commands in Linux / UNIX.

This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference.

Did I miss any frequently used Linux commands? Leave a comment and let me know.

1-mkdir - make directories
cd - change directories

Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.

2mv- change the name of a directory

Type mv followed by the current name of a directory and the new name of the directory.

 Ex: mv testdir newnamedir

3pwd - print working directory

will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page

 4rmdir - Remove an existing directory

 rm -r

Removes directories and files within the directories recursively.

5chown - change file owner and group

6-ls - Short listing of directory contents

-a        list hidden files

-d        list the name of the current directory

-F        show directories with a trailing '/'

            executable files with a trailing '*'

-g        show group ownership of file in long listing

-i        print the inode number of each file

-l        long listing giving details about files  and directories

-R        list all subdirectories encountered

-t        sort by time modified instead of name

7-cp - Copy files

8-top - Prints a display of system processes that's continually updated until the user presses the q key.

9-uptime - Prints the system uptime.

10-w - Prints the current system users.

11-reboot - Reboots the system (requires root privileges).

12-head files - Prints the first several lines of each specified file.
13-cal month year - Prints a calendar for the specified month of the specified year.

14-cat files - Prints the contents of the specified files.

15-clear - Clears the terminal screen.
16-mv- moves the file data1 to the folder newdata and deletes the old one.
17-df-Shows the disk usage. This will tell you how much disk space you have left on your hard drive as well as the floppy.
18-pwd-Shows what directory (folder) you are in.
In Linux, your home directory is /home/particle

19-man -This command brings up the online Unix
manual.

20-kill-Use kill command to terminate a process

Thursday, February 13, 2014

SAR - System Activity Reporter

System Activity Reporter is an important tool that helps system administrators to get an overview of the server machine with status of different important metrics at different points of time.
If suppose you are having an issue with the system currently, Like some of your customers are unable to list some data from the
Database. The first thing that most of the Linux system administrators do is to recall the same issue when it previously occurred,
 and If you remember the day of its previous occurrence then you can easily compare the internal system statistics with the current  statistics.
SAR is very much helpful in doing exactly that.

The first thing that we need to do is check and confirm whether you have SAR utility installed on the machine.
 Which can be checked by listing all rpm's and finding for this utility.
1 CPU Usage of ALL CPUs (sar -u)

 This gives the cumulative real-time CPU usage of all CPUs. “1 3″ reports for every 1 seconds a total of 3 times.
 Most likely you’ll focus on the last field “%idle” to see the cpu load.
 01:10:01 AM       all     12.92      0.00      0.21      1.37      0.00     85.50
01:20:01 AM       all     12.56      0.00      0.23      0.88      0.00     86.33
01:30:01 AM       all     13.80      0.00      0.21      0.78      0.00     85.21
01:40:01 AM       all      8.15      0.00      0.13      0.39      0.00     91.34
01:50:01 AM       all      4.89      0.00      0.11      0.24      0.00     94.76
02:00:01 AM       all      7.01      0.00      0.14      0.36      0.00     92.49
02:10:01 AM       all     13.55      0.00      0.27      1.85      0.00     84.33
02:20:01 AM       all      9.95      0.00      0.21      0.64      0.00     89.20
02:30:01 AM       all      7.02      0.00      0.16      0.87      0.00     91.95

2-. CPU Usage of Individual CPU or Core (sar -P)
If you have 4 Cores on the machine and would like to see what the individual cores are doing, do the following.

“-P ALL” indicates that it should displays statistics for ALL the individual Cores.

In the following example under “CPU” column 0, 1, 2, and 3 indicates the corresponding CPU core numbers.
01:30:01 AM       all     13.80      0.00      0.21      0.78      0.00     85.21
01:40:01 AM       all      8.15      0.00      0.13      0.39      0.00     91.34
01:50:01 AM       all      4.89      0.00      0.11      0.24      0.00     94.76
02:00:01 AM       all      7.01      0.00      0.14      0.36      0.00     92.49
02:10:01 AM       all     13.55      0.00      0.27      1.85      0.00     84.33
02:20:01 AM       all      9.95      0.00      0.21      0.64      0.00     89.20
02:30:01 AM       all      7.02      0.00      0.16      0.87      0.00     91.95

3- Memory Free and Used (sar -r)
This reports the memory statistics. “1 3″ reports for every 1 seconds a total of 3 times.
Most likely you’ll focus on “kbmemfree” and “kbmemused” for free and used memory.
12:00:01 AM kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
12:10:01 AM    113948  12112648     99.07     35492   9002588  16200712    571064      3.40    204928
12:20:03 AM     81892  12144704     99.33     34468   9061424  16201388    570388      3.40    204120
12:30:01 AM    137436  12089160     98.88     37432   9099808  16201640    570136      3.40    204216
12:40:02 AM    138400  12088196     98.87     38592   9128920  16201872    569904      3.40    204076
12:50:01 AM    122772  12103824     99.00     40156   9139808  16201944    569832      3.40    204632
01:00:01 AM    169380  12057216     98.61     41868   9061508  16202004    569772      3.40    205168

4-Swap Space Used (sar -S)
This reports the swap statistics. “1 3″ reports for every 1 seconds a total of 3 times.
 If the “kbswpused” and “%swpused” are at 0, then your system is not swapping.
 Linux 2.6.18-194.el5 (milli.tenongroove.com)     02/13/2014

 5-Overall I/O Activities (sar -b)

                This reports I/O statistics. “1 3″ reports for every 1 seconds a total of 3 times.

Following fields are displays in the example below.

tps – Transactions per second (this includes both read and write)
rtps – Read transactions per second
wtps – Write transactions per second
bread/s – Bytes read per second
bwrtn/s – Bytes written per second

12:00:01 AM       tps      rtps      wtps   bread/s   bwrtn/s
12:10:01 AM    159.91    108.09     51.82   3141.91   1284.71
12:20:03 AM    359.40    300.74     58.66  41838.06  22521.18
12:30:01 AM    314.82    238.17     76.65  23390.49  13952.02
12:40:02 AM    277.36    255.01     22.34  33625.52   1036.20
12:50:01 AM     99.54     73.69     25.85   2332.04   1779.16
01:00:01 AM    110.22     86.61     23.61   3601.47    946.98

6-6. Individual Block Device I/O Activities (sar -d)

01:00:01 AM    dev8-0     94.28    639.08   1167.44     19.16      0.65      6.85      4.66     43.91
01:00:01 AM   dev8-16    243.98     67.84   2272.06      9.59      1.85      7.57      3.62     88.41
01:10:01 AM    dev8-0     96.15    609.59    675.88     13.37      0.64      6.67      4.62     44.40
01:10:01 AM   dev8-16    114.92   1887.28    751.40     22.96      0.77      6.69      3.54     40.67
01:20:01 AM    dev8-0     93.70    539.33    895.29     15.31      0.58      6.21      4.41     41.28
01:20:01 AM   dev8-16     96.87    144.94   1030.79     12.14      0.72      7.39      3.62     35.05

01:20:01 AM       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
01:30:01 AM    dev8-0     88.23    501.38   1042.23     17.50      0.63      7.18      5.02     44.33
01:30:01 AM   dev8-16     80.55    126.41   1034.64     14.41      0.57      7.07      3.50     28.15
01:40:01 AM    dev8-0     72.41    613.69   1002.74     22.32      0.52      7.23      4.88     35.36
01:40:01 AM   dev8-16    260.85  34977.00  27110.38    238.02     70.49    267.99      2.52     65.80
01:50:01 AM    dev8-0     87.83   1140.87    924.01     23.51      0.59      6.69      4.30     37.76

To identify the activities by the individual block devices (i.e a specific mount point, or LUN, or partition), use “sar -d”

7-7. Display context switch per second (sar -w)

This reports the total number of processes created per second, and total number of context switches per second.
 “1 3″ reports for every 1 seconds a total of 3 times.
 12:00:01 AM   cswch/s
12:10:01 AM    839.84
12:20:03 AM   1150.19
12:30:01 AM   1160.66
12:40:02 AM   1340.34
12:50:01 AM    852.09
01:00:01 AM    826.40
01:10:01 AM    804.37
01:20:01 AM    793.43

8. Reports run queue and load average (sar -q)

This reports the run queue size and load average of last 1 minute, 5 minutes, and 15 minutes.
“1 3″ reports for every 1 seconds a total of 3 times.

12:00:01 AM   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
12:10:01 AM         3       476      3.98      3.92      3.07
12:20:03 AM         1       475      6.53      5.21      3.90
12:30:01 AM         3       474      3.05      3.47      3.72
12:40:02 AM         2       467      3.04      3.20      3.36
12:50:01 AM         2       472      1.76      2.27      2.79
01:00:01 AM         4       476      2.52      2.52      2.61
01:10:01 AM         3       473      2.05      2.35      2.49
01:20:01 AM         4       472      2.32      2.30      2.36

09. Report Sar Data Using Start Time (sar -s)

When you view historic sar data from the /var/log/sa/saXX file using “sar -f” option, it displays all the sar data for
 that specific day starting from 12:00 a.m for that day.

Using “-s hh:mi:ss” option, you can specify the start time. For example, if you specify “sar -s 08:00:00″,
 it will display the sar data starting from 10 a.m (instead of starting from midnight) as shown below.

You can combine -s option with other sar option.


For example, to report the load average on 26th of this month starting from 10 a.m in the morning, combine the -q and -s option as shown below.
08:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
08:10:02 AM     all     19.72      0.00      2.46     10.92      0.00     66.90
08:20:01 AM     all     22.18      0.00      3.13     10.57      0.00     64.12

Average:        all     20.95      0.00      2.80     10.75      0.00     65.51

Wednesday, February 12, 2014

Top Command in Linux

something about top command -

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a
 list of processes or threads currently being managed by the kernel. The types of system summary information shown and the types,
 order and size of information displayed for tasks are all user-configurable.

Sorting with -O (Uppercase Letter ‘O’).

 Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to sort process with PID (Process ID).
 Type any key to return to main top window with sorted PID order as shown in below screen. Press ‘q‘ to quit exit the window.
 Current Sort Field:  K  for window 1:Def
Select sort field via field letter, type any other key to return

  a: PID        = Process Id                                                               not those in column display.  Thus,
  b: PPID       = Parent Process Pid                                                       the TTY & WCHAN fields will violate
  c: RUSER      = Real user name                                                           strict ASCII collating sequence.
  d: UID        = User Id                                                                  (shame on you if WCHAN is chosen)
  e: USER       = User Name
  f: GROUP      = Group Name
  g: TTY        = Controlling Tty
  h: PR         = Priority

2-. Display Specific User Process

 Use top command with ‘u‘ option will display specific User process details.
 [oracle@swati_test ~]$ top
top - 11:13:29 up 124 days, 23:27,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 391 total,   1 running, 390 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8098892k total,  8050776k used,    48116k free,   113992k buffers
Swap: 16217580k total,   241316k used, 15976264k free,  6870532k cached
Which user (blank for all): U
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
 2366 oracle    15   0 12996 1340  812 R  0.3  0.0   0:00.04 top                                                                                                                  
    1 root      15   0 10348  628  568 S  0.0  0.0   0:03.12 init                                                                                                                
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.56 migration/0                                                                                                          
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                                                                                                          
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

3- Highlight Running Process in Top

   Press ‘z‘ option in running top command will display running process in color which may help you to identified running process
   easily.
   [oracle@swati_test ~]$ top
top - 11:15:38 up 124 days, 23:29,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 391 total,   2 running, 389 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8098892k total,  8052064k used,    46828k free,   114832k buffers
Swap: 16217580k total,   241316k used, 15976264k free,  6870516k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
 2369 oracle    15   0 12996 1344  816 R  0.3  0.0   0:00.14 top                                                                                                                  
    1 root      15   0 10348  628  568 S  0.0  0.0   0:03.12 init                                                                                                                
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.56 migration/0                                                                                                          
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                                                                                                          
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                                                                                                          
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:00.70 migration/1

4-  Shows Absolute Path of Processes

Press ‘c‘ option in running top command, it will display absolute path of running process.
top - 11:17:22 up 43 days,  8:45,  2 users,  load average: 8.21, 8.77, 8.92
Tasks: 904 total,   9 running, 895 sleeping,   0 stopped,   0 zombie
Cpu(s): 15.1%us,  2.1%sy,  0.0%ni, 81.9%id,  0.7%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:  16226808k total, 14786320k used,  1440488k free,    18980k buffers
Swap: 37758728k total,   920880k used, 36837848k free, 11425508k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
157616 oracle    20   0 4246m 2.6g 2.5g R 49.8 16.5 108:58.69 oracletest (LOCAL=NO)                                                                                            
172755 oracle    20   0 4528m 1.9g 1.6g S 32.7 12.3  78:40.91 oracletest (LOCAL=NO)                                                                                            
172753 oracle    20   0 4304m 1.7g 1.7g D 30.4 11.3  66:19.20 oracletest (LOCAL=NO)                                                                                            
155644 oracle    20   0 4246m 2.0g 2.0g R 20.8 13.0   9:12.19 oracletest (LOCAL=NO)                                                                                            
156643 oracle    20   0 4262m 2.1g 2.1g R 19.8 13.5 128:06.64 oracletest (LOCAL=NO)

5-
 Change Delay or Set ‘Screen Refresh Interval’ in Top

By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option in running top command and change
 it as desired as shown below.
 top - 11:20:50 up 43 days,  8:49,  2 users,  load average: 8.96, 8.72, 8.85
Tasks: 906 total,   5 running, 901 sleeping,   0 stopped,   0 zombie
Cpu(s): 21.9%us,  2.6%sy,  0.0%ni, 74.8%id,  0.6%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:  16226808k total, 14889092k used,  1337716k free,    20340k buffers
Swap: 37758728k total,   920880k used, 36837848k free, 11522528k cached
Change delay from 10.0 to:
   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
157616 oracle    20   0 4246m 2.6g 2.5g R 84.7 16.5 111:27.25 oracle                                                                                                              
172755 oracle    20   0 4528m 1.9g 1.6g D 68.0 12.3  80:23.74 oracle                                                                                                              
172753 oracle    20   0 4304m 1.8g 1.7g S 57.4 11.3  67:47.44 oracle

 6-Kill running process with argument ‘k’

 You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without
 exiting from top window as shown below.

 7-Sort by CPU Utilisation

 Press (Shift+P) to sort processes as per CPU utilization. See screenshot below.
 Tasks: 913 total,   6 running, 907 sleeping,   0 stopped,   0 zombie
Cpu(s): 14.3%us,  1.5%sy,  0.0%ni, 82.6%id,  1.3%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:  16226808k total, 15050824k used,  1175984k free,    21284k buffers
Swap: 37758728k total,   920880k used, 36837848k free, 11679112k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                            
157616 oracle    20   0 4246m 2.6g 2.5g R 71.5 16.5 112:56.40 oracle                                                                                                              
156862 oracle    20   0 4245m 2.6g 2.6g R 69.6 16.5 108:25.97 oracle                                                                                                              
172753 oracle    20   0 4304m 1.8g 1.7g R 18.0 11.3  68:37.61 oracle                                                                                                              
172755 oracle    20   0 4528m 1.9g 1.6g R 17.4 12.3  81:22.37 oracle

 8- Renice a Process
 You can use ‘r‘ option to change the priority of the process also called Renice.

 9-Save Top Command Results
 Press (Shift+W) to save the running top command results under /root/.toprc.

 10- Getting Top Command Help

 Press ‘h‘ option to obtain the top command help.
 Help for Interactive Commands - procps version 3.2.8
Window 1:Def: Cumulative mode Off.  System: Delay 3.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
  F or O  . Select sort field
  <,>     . Move sort field: '<' next col left; '>' next col right
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u       . Show specific user only
  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W         Write configuration file
  q         Quit
          ( commands shown with '.' require a visible task display window )
Press 'h' or '?' for help with Windows,
any other key to continue

 11-. Exit Top Command After Specific repetition
 Top output keep refreshing until you press ‘q‘. With below command top command will automatically exit after 10 number of repetition



How to create user in MY SQL

Create  a new MySQL user Account mysql > CREATE USER ' newuser '@'localhost' IDENTIFIED BY ' password '...