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

Wednesday, February 26, 2014

TNSnames and LISTENER.ora


Oracle Networking – TNSnames , Listener.ora

        UNDERSTANDING NETWORK CONFIGURATION
Oracle Net is a software component that resides on the client and the Oracle database server Or Oracle DBA Machine. It is responsible for establishing and maintaining the connection between the client application and the server, as well as exchanging messages between them.
For the client application and a database to communicate, the client application must specify location details for the database it wants to connect to and the database must provide some sort of identification, or address.
        WHAT IS AN ORACLE DATABASE LISTENER?
On the database server side,an Oracle Database Listener is an Oracle Database Process which "listen" for for users (clients) connecting to the database. The listener process, either creates a dedicated server process for each user or to a shared server process that handles many users.
It is configured in a file named listener.ora, with a protocol address that identifies the database.
(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=my-server) (PORT=1521)))This example shows a TCP/IP protocol address that specifies the host machine of the listener and a port number.

Here is an example of $ORACLE_HOME/network/admin/listener.ora:

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\Oracle_10g)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = cata1)(PORT = 1521))
)
)
LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = cata1)(PORT = 1522))
)
)
Here 2 listeners are configured for this server.
        CONFIGURE THE CLIENT
When a client configured with the same protocol address broadcasts a request for a connection, the listener on the server machine or Oracle DBAmachine brokers the request and forwards it to the Oracle database.
The client uses a CONNECT DESCRIPTOR to specify the database it wants to connect to. This connect descriptor contains-- a protocol address and --a database service name.
A database can have multiple services defined, so a specific one must be specified for the connection. In the case of the preconfigured database that you installed, there is only one service, the name of which defaults to the global database name.The following example shows a CONNECT DESCRIPTOR that enables client to connect to a database service called live.
SCOTT =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = cata1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = live)
    )
  )


Connection Requests:-
Users initiate a connection request by providing a connect string. A CONNECT STRING includes a username and password, along with a connect identifier.
This connect identifier can be the connect descriptor itself, or a name that resolves to the connect descriptor. One of the most common connect identifiers is a net service name, a simple name for a service.
The following example shows a connect string that uses net service name live as the connect identifier
CONNECT sagar/verma@live



        SOME QUESTIONS:-
Q) If I configured many listeners on my server, how could I see which is used ?
Ans)Using LSNRCTL> show current listener command.
       Other useful commands:-
       lsnrctl status       lsnrctl start       lsnrctl stop

Q)How could I see if the listener is running ?

Monday, March 25, 2013

Linux


Linux

Check number of CPU’s
$cat /proc/cpuinfo
Check memory information
cat /proc/meminfo
Check swap
$swapon -s
Kernel parameter
#/sbin/sysctl -a
cat /etc/sysctl.conf
System error log
/var/log/messages
Nic configuration
ifconfig -a
Useful Links-

Wednesday, March 20, 2013

Oracle Database Health check scripts


Lot of time DBAs are asked to check the health of the Database,Health of the Database can be check in various ways.

Here it goes...

SL No Monitoring Scope Current Status OS Level
1 Physical memory / Load :Load normal, Load averages: 0.35, 0.37, 0.36
2 OS Space threshold ( archive, ora_dump etc.. ) :Sufficient Space available.
Top 10 process consuming memory:No process using exceptional high memory
4 Free volumes available :Sufficient disk space is available on the mount points
5 Filesystem space Under normal threshold
Database level.
6 Check extents / Pro active Space addition:Space is being regularly added.
7 Check alert log for ORA- and warn messages.
8 Major wait events (latch/enqueue/Lib cache pin) No major wait events
9 Max Sessions
10 Long running Jobs 6 inactive sessions running for more than 8 hrs
11 Invalid objects 185
12 Analyze Jobs ( once in a week ) Done on 20-JAN-2008 Time 06:00:06
13 Temp usage / Rollback segment usage Normal
14 Nologging Indexes
15 Hotbackup/Coldbackup Gone fine
16 Redo generation normal
17 PQ proceses Normal
18 I/O Generation Under normal threshold
19 2 PC Pending transactions 0
DR / backup
1 Sync arch Normal
2 Purge arch Normal
3 Recovery status Normal
20)DATABASE HEALTH CHECK SCRIPT: Showing locks and Archive generation details

In Detail DATABASE Health check:
OPERATING SYSTEM:

1)Physical memory/ Load:
1) Free:free command displays amount of total, free and used physical memory (RAM) in the system as well as showing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.
Usage:
$ free -m

2) vmstat:vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity
Usage:
$vmstat 5

3) top:top command displays dynamic real-time view of the running tasks managed by kernel and in Linux system. The memory usage stats by top command include real-time live total, used and free physical memory and swap memory with their buffers and cached memory size respectively
Usage:
$top
4) ps :ps command reports a snapshot on information of the current active processes. ps will show the percentage of memory resource that is used by each process or task running in the system. With this command, top memory hogging processes can be identified.
Usage:
$ps aux

2) OS Space threshold ( archive, ora_dump etc.. ):
Checking the OS space is available in all filesystems,specially the location which is having archive logs ,oracle Database files.We can use the below OS commands:
$df –h
$du –csh *
3) Top 10 process consuming memory:
We can Displaying top 10 memory consuming processes as follows:

ps aux|head -1;ps aux|sort -m

We can use the top command, and press M which orders the process list by memory usage.

4) Free volumes available:

We have to make sure Sufficient disk space is available on the mount points on each OS servers where the Database is up and running.

$df –h

5)Filesystem space:

Under normal threshold.Check the filesystem in the OS side whether the sufficient space is available at all mount points.

DATABASE :

6)Check extents / Pro active Space addition:
Check each of the Data,Index and temporary tablespaces for extend and blocks
Allocation details.

SET LINES 1000
SELECT SEGMENT_NAME,TABLESPACE_NAME,EXTENTS,BLOCKS
FROM DBA_SEGMENTS;

SELECT SEGMENT_NAME,TABLESPACE_NAME,EXTENTS,BLOCKS
FROM DBA_SEGMENTS WHERE TABLESPACE_NAME=’STAR01D’;

7) Check alert log for ORA- and warn messages:

Checking the alert log file regulary is a vital task we have to do.In the alert log files we have to looks for the following things:

1) Look for any of the oracle related errors.
Open the alert log file with less or more command and search for ORA-
This will give you the error details and time of occurrence.

2) Look for the Database level or Tablespace level changes
Monitor the alert log file and search the file for each Day activities happening
In the Database either whether it is bouncing of Database.Increase in the size of the tablespaces,Increase in the size of the Database parameters.In the 11g Database we can look for TNS errors in the alert log file.

8) Major wait events (latch/enqueue/Lib cache pin):

We can check the wait events details with the help of below queries:

SELECT s.saddr, s.SID, s.serial#, s.audsid, s.paddr, s.user#, s.username,
s.command, s.ownerid, s.taddr, s.lockwait, s.status, s.server,
s.schema#, s.schemaname, s.osuser, s.process, s.machine, s.terminal,
UPPER (s.program) program, s.TYPE, s.sql_address, s.sql_hash_value,
s.sql_id, s.sql_child_number, s.sql_exec_start, s.sql_exec_id,
s.prev_sql_addr, s.prev_hash_value, s.prev_sql_id,
s.prev_child_number, s.prev_exec_start, s.prev_exec_id,
s.plsql_entry_object_id, s.plsql_entry_subprogram_id,
s.plsql_object_id, s.plsql_subprogram_id, s.module, s.module_hash,
s.action, s.action_hash, s.client_info, s.fixed_table_sequence,
s.row_wait_obj#, s.row_wait_file#, s.row_wait_block#,
s.row_wait_row#, s.logon_time, s.last_call_et, s.pdml_enabled,
s.failover_type, s.failover_method, s.failed_over,
s.resource_consumer_group, s.pdml_status, s.pddl_status, s.pq_status,
s.current_queue_duration, s.client_identifier,
s.blocking_session_status, s.blocking_instance, s.blocking_session,
s.seq#, s.event#, s.event, s.p1text, s.p1, s.p1raw, s.p2text, s.p2,
s.p2raw, s.p3text, s.p3, s.p3raw, s.wait_class_id, s.wait_class#,
s.wait_class, s.wait_time, s.seconds_in_wait, s.state,
s.wait_time_micro, s.time_remaining_micro,
s.time_since_last_wait_micro, s.service_name, s.sql_trace,
s.sql_trace_waits, s.sql_trace_binds, s.sql_trace_plan_stats,
s.session_edition_id, s.creator_addr, s.creator_serial#
FROM v$session s
WHERE ( (s.username IS NOT NULL)
AND (NVL (s.osuser, 'x') <> 'SYSTEM')
AND (s.TYPE <> 'BACKGROUND') AND STATUS='ACTIVE'
)
ORDER BY "PROGRAM";

The following query provides clues about whether Oracle has been waiting for library cache activities:

Select sid, event, p1raw, seconds_in_wait, wait_time
From v$session_wait
Where event = 'library cache pin'
And state = 'WAITING';

The below Query gives details of Users sessions wait time and state:

SELECT NVL (s.username, '(oracle)') AS username, s.SID, s.serial#, sw.event,
sw.wait_time, sw.seconds_in_wait, sw.state
FROM v$session_wait sw, v$session s
WHERE s.SID = sw.SID
ORDER BY sw.seconds_in_wait DESC;

9) Max Sessions:
There should not be more than 6 inactive sessions running for more than 8 hours in a Database in order to minimize the consumption of CPU and I/O resources.

a)Users and Sessions CPU consumption can be obtained by below query:

Set lines 1000
select ss.username, se.SID,VALUE/100 cpu_usage_seconds
from v$session ss, v$sesstat se, v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID and ss.status='ACTIVE'
and ss.username is not null
order by VALUE desc;


b) Users and Sessions CPU and I/O consumption can be obtained by below query:

-- shows Day wise,User wise,Process id of server wise- CPU and I/O consumption
set linesize 140
col spid for a6
col program for a35 trunc
select p.spid SPID,to_char(s.LOGON_TIME,'DDMonYY HH24:MI') date_login,s.username,decode(nvl(p.background,0),1,bg.description, s.program ) program,
ss.value/100 CPU,physical_reads disk_io,(trunc(sysdate,'J')-trunc(logon_time,'J')) days,
round((ss.value/100)/(decode((trunc(sysdate,'J')-trunc(logon_time,'J')),0,1,(trunc(sysdate,'J')-trunc(logon_time,'J')))),2) cpu_per_day
from V$PROCESS p,V$SESSION s,V$SESSTAT ss,V$SESS_IO si,V$BGPROCESS bg
where s.paddr=p.addr and ss.sid=s.sid
and ss.statistic#=12 and si.sid=s.sid
and bg.paddr(+)=p.addr
and round((ss.value/100),0) > 10
order by 8;

10) Long running Jobs:

We can find out long running jobs with the help of the below query:

col username for a20
col message for a50
col remaining for 9999
select username,to_char(start_time, 'hh24:mi:ss dd/mm/yy') started,
time_remaining remaining, message
from v$session_longops
where time_remaining = 0
order by time_remaining desc;

11) Invalid objects:

We can check the invalid objects with the help of the below query:

select owner||' '||object_name||' '||created||' '||status from dba_objects where status='INVALID';

12) Analyze Jobs ( once in a week ):

We need to analyze the jobs that are running once in a week as a golden rule.
The below steps can be considered for analyzing jobs.

Analyzing a Running Job
The status of a job or a task changes several times during its life cycle. A job can have the following as its status:
Scheduled: The job is created and will run at the specified time.
Running: The job is being executed and is in progress.
Initialization Error: The job or step could not be run successfully. If a step in a job fails initialization, the job status is Initialization Error.
Failed: The job was executed but failed.
Succeeded: The job was executed completely.
Stopped: The user canceled the job.
Stop Pending: The user has stopped the job. The already running steps are completing execution.
Suspended: This indicates that the execution of the job is deferred.
Inactive: This status indicates that the target has been deleted.
Reassigned: The owner of the job has changed.
Skipped: The job was not executed at the specified time and has been omitted.
The running jobs can be found out by the help of below query:

select sid, job,instance from dba_jobs_running;

We can find out the failed jobs and Broken jobs details with the help of the Below query:

select job||' '||schema_user||' '||Broken||' '||failures||' '||what||' '||last_date||' '||last_sec from dba_jobs;

13) Temp usage / Rollback segment/PGA usage:

We can get information of temporary tablespace usage details with the help of below query:
Set lines 1000
SELECT b.tablespace,
ROUND(((b.blocks*p.value)/1024/1024),2)||'M' "SIZE",
a.sid||','||a.serial# SID_SERIAL,
a.username,
a.program
FROM sys.v_$session a,
sys.v_$sort_usage b,
sys.v_$parameter p
WHERE p.name = 'db_block_size'
AND a.saddr = b.session_addr
ORDER BY b.tablespace, b.blocks;

We can get information of Undo tablespace usage details with the help of the below query:
set lines 1000
SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial,
NVL(s.username, 'None') orauser,
s.program,
r.name undoseg,
t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo"
FROM sys.v_$rollname r,
sys.v_$session s,
sys.v_$transaction t,
sys.v_$parameter x
WHERE s.taddr = t.addr
AND r.usn = t.xidusn(+)
AND x.name = 'db_block_size';

We can get the PGA usage details with the help of the below query:
select st.sid "SID", sn.name "TYPE",
ceil(st.value / 1024 / 1024/1024) "GB"
from v$sesstat st, v$statname sn
where st.statistic# = sn.statistic#
and sid in
(select sid from v$session where username like UPPER('&user'))
and upper(sn.name) like '%PGA%'
order by st.sid, st.value desc;
Enter value for user: STARTXNAPP
14)Validating the Backup:

We have to verify the Hotbackup/Coldbackup(or any physical or logical backup) of all the Production and non-production Databases went fine.Make sure you are having a valid backups of all the Databases.Check the Backup locations to make sure the Backup completed on time with the required Backup data.

14)Hotbackup/Coldbackup:
Validating the backup of Database.It should complete on time with the required data for restoring and recovery purpose if required.

15) Redo generation/Archive logs generation details:
We should make sure there should not be frequent log switch happening in a Database.If there are frequent log switches than archive logs might generate more which may decrease the performance of the Database however in a production Database log switches could vary depending upon the Server configuration between 5 to 20.

We can the log switch details with the help of the below query:

Redolog switch Datewise and hourwise:
-------------------------------
set lines 120;
set pages 999;
select to_char(first_time,'DD-MON-RR') "Date",
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') " 00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') " 01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') " 02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') " 03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') " 04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') " 05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') " 06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') " 07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') " 08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') " 09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') " 10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') " 11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') " 12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') " 13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') " 14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') " 15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') " 16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') " 17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') " 18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') " 19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') " 20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') " 21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') " 22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') " 23"
from v$log_history
group by to_char(first_time,'DD-MON-RR')
order by 1
/
Archive logs generations is directly proportional to the number of log switches happening in a Database. If there are frequent log switches than archive logs might generate more which can affect the performance of Database.


We can use the below queries for archive logs generation details:

a)Archive logs by dates:
set lines 1000
select to_char(first_time,'DD-MON-RR') "Date",
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') " 00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') " 01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') " 02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') " 03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') " 04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') " 05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') " 06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') " 07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') " 08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') " 09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') " 10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') " 11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') " 12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') " 13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') " 14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') " 15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') " 16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') " 17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') " 18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') " 19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') " 20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') " 21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') " 22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') " 23"
from v$log_history
group by to_char(first_time,'DD-MON-RR')
order by 1
/
b)Archive log generation details Day-wise :

select to_char(COMPLETION_TIME,'DD-MON-YYYY'),count(*)
from v$archived_log group by to_char(COMPLETION_TIME,'DD-MON-YYYY')
order by to_char(COMPLETION_TIME,'DD-MON-YYYY');

c) Archive log count of the day:

select count(*)
from v$archived_log
where trunc(completion_time)=trunc(sysdate);

count of archived logs generated today on hourly basis:
-------------------------------------------------------
select to_char(first_time,'DD-MON-RR') "Date",
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') " 00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') " 01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') " 02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') " 03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') " 04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') " 05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') " 06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') " 07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') " 08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') " 09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') " 10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') " 11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') " 12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') " 13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') " 14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') " 15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') " 16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') " 17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') " 18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') " 19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') " 20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') " 21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') " 22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') " 23"
from v$log_history
where to_char(first_time,'DD-MON-RR')='16-AUG-10'
group by to_char(first_time,'DD-MON-RR')
order by 1
/

16)I/O Generation:
We can find out CPU and I/O generation details for all the users in the Database with the help of the below query:
-- Show IO per session,CPU in seconds, sessionIOS.
set linesize 140
col spid for a6
col program for a35 trunc
select p.spid SPID,to_char(s.LOGON_TIME,'DDMonYY HH24:MI') date_login,s.username,decode(nvl(p.background,0),1,bg.description, s.program ) program,
ss.value/100 CPU,physical_reads disk_io,(trunc(sysdate,'J')-trunc(logon_time,'J')) days,
round((ss.value/100)/(decode((trunc(sysdate,'J')-trunc(logon_time,'J')),0,1,(trunc(sysdate,'J')-trunc(logon_time,'J')))),2) cpu_per_day
from V$PROCESS p,V$SESSION s,V$SESSTAT ss,V$SESS_IO si,V$BGPROCESS bg
where s.paddr=p.addr and ss.sid=s.sid
and ss.statistic#=12 and si.sid=s.sid
and bg.paddr(+)=p.addr
and round((ss.value/100),0) > 10
order by 8;
To know what the session is doing and what kind of sql it is using:

-- what kind of sql a session is using
set lines 9999
set pages 9999

select s.sid, q.sql_text from v$sqltext q, v$session s
where q.address = s.sql_address
and s.sid = &sid order by piece;

eg: sid=1853

17)Sync arch:
In a Dataguard environment we have to check primary is in sync with the secondary Database.This we can check as follows:
The V$ MANAGED_STANDBY view on the standby database site shows you the activities performed by
both redo transport and Redo Apply processes in a Data Guard environment
SELECT PROCESS, CLIENT_PROCESS, SEQUENCE#, STATUS FROM V$MANAGED_STANDBY;
In some situations, automatic gap recovery may not take place and you will need to perform gap recovery manually. For example, you will need to perform gap recovery manually if you are using logical standby databases and the primary database is not available.
The following sections describe how to query the appropriate views to determine which log files are missing and perform manual recovery.
On a physical standby database
To determine if there is an archive gap on your physical standby database, query the V$ARCHIVE_GAP view as shown in the following example:
SQL> SELECT * FROM V$ARCHIVE_GAP;

If it displays no rows than the primary Database is in sync with the standy Database.If it display any information with row than manually we have to apply the archive logs.

After you identify the gap, issue the following SQL statement on the primary database to locate the archived redo log files on your primary database (assuming the local archive destination on the primary database is LOG_ARCHIVE_DEST_1):
Eg:
SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1 AND SEQUENCE# BETWEEN 7 AND 10;
Copy these log files to your physical standby database and register them using the ALTER DATABASE REGISTER LOGFILE statement on your physical standby database. For example:
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_7.arc';
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_8.arc';

After you register these log files on the physical standby database, you can restart Redo Apply. The V$ARCHIVE_GAP fixed view on a physical standby database only returns the next gap that is currently blocking Redo Apply from continuing. After resolving the gap and starting Redo Apply, query the V$ARCHIVE_GAP fixed view again on the physical standby database to determine the next gap sequence, if there is one. Repeat this process until there are no more gaps.

On a logical standby database:
To determine if there is an archive gap, query the DBA_LOGSTDBY_LOG view on the logical standby database. For example, the following query indicates there is a gap in the sequence of archived redo log files because it displays two files for THREAD 1 on the logical standby database. (If there are no gaps, the query will show only one file for each thread.) The output shows that the highest registered file is sequence number 10, but there is a gap at the file shown as sequence number 6:
SQL> COLUMN FILE_NAME FORMAT a55
SQL> SELECT THREAD#, SEQUENCE#, FILE_NAME FROM DBA_LOGSTDBY_LOG L
2> WHERE NEXT_CHANGE# NOT IN
3> (SELECT FIRST_CHANGE# FROM DBA_LOGSTDBY_LOG WHERE L.THREAD# = THREAD#)
4> ORDER BY THREAD#,SEQUENCE#;

THREAD# SEQUENCE# FILE_NAME
---------- ---------- -----------------------------------------------
1 6 /disk1/oracle/dbs/log-1292880008_6.arc
1 10 /disk1/oracle/dbs/log-1292880008_10.arc

Copy the missing log files, with sequence numbers 7, 8, and 9, to the logical standby system and register them using the ALTER DATABASE REGISTER LOGICAL LOGFILE statement on your logical standby database. For example:
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE '/disk1/oracle/dbs/log-1292880008_10.arc';

After you register these log files on the logical standby database, you can restart SQL Apply.

The DBA_LOGSTDBY_LOG view on a logical standby database only returns the next gap that is currently blocking SQL Apply from continuing. After resolving the identified gap and starting SQL Apply, query the DBA_LOGSTDBY_LOG view again on the logical standby database to determine the next gap sequence, if there is one. Repeat this process until there are no more gaps.
Monitoring Log File Archival Information:
Step 1 Determine the current archived redo log file sequence numbers.
Enter the following query on the primary database to determine the current archived redo log file sequence numbers:
SQL> SELECT THREAD#, SEQUENCE#, ARCHIVED, STATUS FROM V$LOG
WHERE STATUS='CURRENT';
Step 2 Determine the most recent archived redo log file.
Enter the following query at the primary database to determine which archived redo log file contains the most recently transmitted redo data:
SQL> SELECT MAX(SEQUENCE#), THREAD# FROM V$ARCHIVED_LOG GROUP BY THREAD#;
Step 3 Determine the most recent archived redo log file at each destination.
Enter the following query at the primary database to determine which archived redo log file was most recently transmitted to each of the archiving destinations:
SQL> SELECT DESTINATION, STATUS, ARCHIVED_THREAD#, ARCHIVED_SEQ#
2> FROM V$ARCHIVE_DEST_STATUS
3> WHERE STATUS <> 'DEFERRED' AND STATUS <> 'INACTIVE';

DESTINATION STATUS ARCHIVED_THREAD# ARCHIVED_SEQ#
------------------ ------ ---------------- -------------
/private1/prmy/lad VALID 1 947
standby1 VALID 1 947
The most recently written archived redo log file should be the same for each archive destination listed. If it is not, a status other than VALID might identify an error encountered during the archival operation to that destination.
Step 4 Find out if archived redo log files have been received.
You can issue a query at the primary database to find out if an archived redo log file was not received at a particular site. Each destination has an ID number associated with it. You can query the DEST_ID column of the V$ARCHIVE_DEST fixed view on the primary database to identify each destination's ID number.
Assume the current local destination is 1, and one of the remote standby destination IDs is 2. To identify which log files are missing at the standby destination, issue the following query:
SQL> SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM
2> (SELECT THREAD#, SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=1)
3> LOCAL WHERE
4> LOCAL.SEQUENCE# NOT IN
5> (SELECT SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND
6> THREAD# = LOCAL.THREAD#);

THREAD# SEQUENCE#
--------- ---------
1 12
1 13
1 14

18)Purge arch:
We have to make sure the archive logs files are purged safely or move to Tape drive or any other location in order to make space for new archive logs files in the Archive logs destination locations.

19)Recovery status:
In order to do recover make sure you are having latest archive logs,so that you can restore and do the recovery if required.


20) MY DATABASE HEALTH CHECK SCRIPT:
/* SCRIPT FOR MONITORING AND CHECKING HEALTH OF DATABASE-USEFUL FOR PRODUCTION DATABASES */

-- SHOWS RUNNING JOBS
select 'RUNNING JOBS', sid, job,instance from dba_jobs_running;
set lines 1000
-- SHOWS ARCHIVE LOGS GENERAION DETAILS HOURLY AND DATE WISE BASIS
select 'ARCHIVE LOG REPORT',to_char(first_time,'DD-MON-RR') "Date",
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'99') " 00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'99') " 01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'99') " 02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'99') " 03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'99') " 04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'99') " 05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'99') " 06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'99') " 07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'99') " 08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'99') " 09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'99') " 10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'99') " 11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'99') " 12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'99') " 13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'99') " 14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'99') " 15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'99') " 16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'99') " 17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'99') " 18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'99') " 19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'99') " 20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'99') " 21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'99') " 22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'99') " 23"
from v$log_history
group by to_char(first_time,'DD-MON-RR')
order by 1
/
-- WHAT ALL THE SESSIONS ARE GETTING BLOCKED
select 'SESSIONS BLOCKED',process,sid, blocking_session from v$session where blocking_session is not null;
-- WHICH SESSION IS BLOCKING WHICH SESSION
set lines 9999
set pages 9999
select s1.username || '@' || s1.machine
|| ' ( SID=' || s1.sid || ' ) is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;
-- SHOWS BLOCK CHANGES DETAILS AND PHYSICAL READS DETAIL
select a.sid,b.username,block_gets,consistent_gets,physical_reads,block_changes
from V$SESS_IO a,V$SESSION b
where a.sid=b.sid and block_changes > 10000 order by block_changes desc;
-- show IO per session / CPU in seconds. sessionIOS.sql
set linesize 140
col spid for a6
col program for a35 trunc
select p.spid SPID,to_char(s.LOGON_TIME,'DDMonYY HH24:MI') date_login,s.username,decode(nvl(p.background,0),1,bg.description, s.program ) program,ss.value/100 CPU,physical_reads disk_io,(trunc(sysdate,'J')-trunc(logon_time,'J')) days,round((ss.value/100)/(decode((trunc(sysdate,'J')-trunc(logon_time,'J')),0,1,(trunc(sysdate,'J')-trunc(logon_time,'J')))),2) cpu_per_day
from V$PROCESS p,V$SESSION s,V$SESSTAT ss,V$SESS_IO si,V$BGPROCESS bg
where s.paddr=p.addr and ss.sid=s.sid
and ss.statistic#=12 and si.sid=s.sid
and bg.paddr(+)=p.addr
and round((ss.value/100),0) > 10
order by 8;
-- SCRIPT TO IDENTIFY LONG RUNNING STATEMENTS
rem LONGOPS.SQL
rem Long Running Statements
rem Helmut Pfau, Oracle Deutschland GmbH
set linesize 120
col opname format a20
col target format a15
col units format a10
col time_remaining format 99990 heading Remaining[s]
col bps format 9990.99 heading [Units/s]
col fertig format 90.99 heading "complete[%]"
select sid,
opname,
target,
sofar,
totalwork,
units,
(totalwork-sofar)/time_remaining bps,
time_remaining,
sofar/totalwork*100 fertig
from v$session_longops
where time_remaining > 0
/
-- ACTIVE SESSIONS IN DATABASE
select 'ACTIVE SESSION', sid, serial#,machine, osuser,username,status from v$session where username!='NULL' and status='ACTIVE';
-- WHAT SQL A SESSION IS USING
set lines 9999
set pages 9999
select s.sid, q.sql_text from v$sqltext q, v$session s
where q.address = s.sql_address
and s.sid = &sid order by piece;

eg:SID=1844
I would like to add one more script which will tell me details regarding the Size of the Database used,occupied and available and Tablespace usage
details along with hit ratio of various SGA components which can be very helpfull
to monitor the performance of the Databases.

Database_monitor.sql:

ttitle "1. :============== Tablespace Usage Information ==================:" skip 2
set linesize 140
col Total format 99999.99 heading "Total space(MB)"
col Used format 99999.99 heading "Used space(MB)"
col Free format 99999.99 heading "Free space(MB)"
break on report
compute sum of Total space(MB) on report
compute sum of Used space(MB) on report
compute sum of Free space(MB) on report
select a.tablespace_name, round(a.bytes/1024/1024,2) Total,
round( nvl( b.bytes,0)/1024/1024,2) Used,
round(nvl(c.bytes, 0)/1024/1024,2) Free ,
round(nvl(b.bytes,0)*100/nvl(a.bytes,0),2) "% Used"
from sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
where a.tablespace_name=b.tablespace_name(+)
and b.tablespace_name=c.tablespace_name(+);

ttitle "2. :============== Hit Ratio Information ==================:" skip 2
set linesize 80
clear columns
clear breaks
set pagesize 60 heading off termout off echo off verify off
REM
col val1 new_val lib noprint
select 100*(1-(SUM(Reloads)/SUM(Pins))) val1
from V$LIBRARYCACHE;

ttitle off
col val2 new_val dict noprint
select 100*(1-(SUM(Getmisses)/SUM(Gets))) val2
from V$ROWCACHE;

ttitle off
col val3 new_val phys_reads noprint
select Value val3
from V$SYSSTAT
where Name = 'physical reads';

ttitle off
col val4 new_val log1_reads noprint
select Value val4
from V$SYSSTAT
where Name = 'db block gets';

ttitle off
col val5 new_val log2_reads noprint
select Value val5
from V$SYSSTAT
where Name = 'consistent gets';

ttitle off
col val6 new_val chr noprint
select 100*(1-(&phys_reads / (&log1_reads + &log2_reads))) val6
from DUAL;

ttitle off
col val7 new_val avg_users_cursor noprint
col val8 new_val avg_stmts_exe noprint
select SUM(Users_Opening)/COUNT(*) val7,
SUM(Executions)/COUNT(*) val8
from V$SQLAREA;
ttitle off
set termout on
set heading off
ttitle -
center 'SGA Cache Hit Ratios' skip 2

select 'Data Block Buffer Hit Ratio : '||&chr db_hit_ratio,
' Shared SQL Pool ',
' Dictionary Hit Ratio : '||&dict dict_hit,
' Shared SQL Buffers (Library Cache) ',
' Cache Hit Ratio : '||&lib lib_hit,
' Avg. Users/Stmt : '||
&avg_users_cursor||' ',
' Avg. Executes/Stmt : '||
&avg_stmts_exe||' '
from DUAL;

ttitle "3. :============== Sort Information ==================:" skip 2

select A.Value Disk_Sorts,
B.Value Memory_Sorts,
ROUND(100*A.Value/
DECODE((A.Value+B.Value),0,1,(A.Value+B.Value)),2)
Pct_Disk_Sorts
from V$SYSSTAT A, V$SYSSTAT B
where A.Name = 'sorts (disk)'
and B.Name = 'sorts (memory)';

ttitle "4. :============== Database Size Information ==================:" skip 2


select sum(bytes/1024/1024/1024) Avail from sm$ts_avail union all select sum(bytes/1024/1024/1024) Used from sm$ts_used union all select sum(bytes/1024/1024/1024) Free from sm$ts_free;


Hope this helps you in monitoring your Databases.

Thursday, September 18, 2008

CREATING PARTITONS & FILESYSTEM in LINUX

Introduction

This post describes how to create a partitons in linux and use it. Creating a new partition for use is a 4 step process.

1. You identify a disk and create a partition using fdisk
2. You create a file system on that disk and assign a label
3. You create an entry in /etc/fstab to make partition persistant accrose reboot
4. You mount the partition for access to the user.

Lets start with creating a partition from a disk.

Creating Partition and filesystem

In my system I have /dev/sda as primary device and following are the different partitions

[root@10.176.87.179]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 2.9G 350M 2.4G 13% /
/dev/sda7 487M 18M 444M 4% /home
/dev/sda6 965M 18M 898M 2% /data
/dev/sda3 2.9G 1.7G 1.1G 62% /usr
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/hdc 2.8G 2.8G 0 100% /cdrom

The total size for all these partitions (except cdrom) comes to 7.5G. Addition to that I have 1G swap partition created on /dev/sda5

[root@10.176.87.179]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 1020088 0 -1

So that makes it 8.5G. Total size of /dev/sda is 10G. This leaves 1.5G free for creating another partition.

1) create a partition using fdisk

fdisk -l will give the list of existing partition

[root@10.176.87.179]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 395 3068415 83 Linux
/dev/sda3 396 777 3068415 83 Linux
/dev/sda4 778 1305 4241160 5 Extended
/dev/sda5 778 904 1020096 82 Linux swap / Solaris
/dev/sda6 905 1031 1020096 83 Linux
/dev/sda7 1032 1095 514048+ 83 Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table

For creating a partition, we can use fdisk followed by device name.

[root@10.176.87.179]# fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (1096-1305, default 1096):
Using default value 1096
Last cylinder or +size or +sizeM or +sizeK (1096-1305, default 1305): +1G

Command (m for help): p

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 395 3068415 83 Linux
/dev/sda3 396 777 3068415 83 Linux
/dev/sda4 778 1305 4241160 5 Extended
/dev/sda5 778 904 1020096 82 Linux swap / Solaris
/dev/sda6 905 1031 1020096 83 Linux
/dev/sda7 1032 1095 514048+ 83 Linux
/dev/sda8 1096 1218 987966 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

The above step creates a raw partition. Here it prompted for

Command (m for help):
and we entered “n”. “n” here means new partition. Then it asked for starting cylinder. By default it takes the cylinder in continuation. Else if we leave some cylinders in between that slot will be empty and we wont be able to use those unless if we want to create the partition of exact that size. So better to accept the default and create a partition in continuous cylinders.

Next input it ask is the end cylinder number. Usually its hard to calculate the number of cylinders depending on the size of slot we need. So we can directly enter the size of slot as +1G or +500M. Here G, M and K can be used representing GB, MB and KB. Remember to use + at the start.

Once these inputs are given, we can use “p” to print the partition list and see if its going to create correct partition. Please note that till now nothing has happened. We are just checking our setting by typing “p”. After checking when we type “w” that time its going to start creating a partition. So we can backoff any time using “quit” until we type “w”.

2) create a file system on that partition and assign a label

For creating a partition, following command is used.

mkfs.ext3

Following are the main and important options

-b -> This represent the block size to be used.
-i -> This represent the block/inode ratio.

inode is a pointer to each and every file in linux. For every file there is an inode. usually its not a good idea to give same number of inodes as number of blocks.

Example:

Partition size = 1000M
block size = 2K
Number of blocks = 500K (1000M/2K)

For each file created, however small it is, its going to use atleast 1 block. And for each file we need 1 inode value.

Now if there are 500K blocks, its not a good idea to give 500K as inode value. Because we are not going to have 500K files. If you thing about it usually in a normal file system some of the file will be larger then 2K (block size). In that case single file will occupy more number of blocks and but still number of inode used for that file will be only 1.

Another disadvantage of giving more number of inode values is that, it will take more space for storing those many values in inode table.

For more options on mkfs.ext3 command, see the man pages.

Lets try creating a file system.

[root@10.176.87.179]# mkfs.ext3 -b 2048 -i 4096 /dev/sda8
mke2fs 1.39 (29-May-2006)
Could not stat /dev/sda8 — No such file or directory

The device apparently does not exist; did you specify it correctly?

OK. Now we got this error. The reason we got this error is because, even though we created a partition, our kernel does not know about it.

When we create a partition, an entry goes in the partition table of that device. This partition table is maintained in the 1st sector of that device. During booting kernel reads the partition table and loads it in memory.

So does that mean that we need to reboot out system? Apperantly reboot can solve our problem, but we can solve the same without reboot as well. We have a command called partprob which will ask kernel to read the partition table on the device and load into memory. Doing that, kernel will know about new partition.

You can list the current partition which kernel is aware of using /proc/partitions file. /proc is a virtual file system in memory. This contains all the information which kernel is aware of and which is used by kernel.

[root@10.176.87.179]# cat /proc/partitions
major minor #blocks name

8 0 10485760 sda
8 1 104391 sda1
8 2 3068415 sda2
8 3 3068415 sda3
8 4 1 sda4
8 5 1020096 sda5
8 6 1020096 sda6
8 7 514048 sda7
8 16 5242880 sdb

So we can see here that partition sda8 is not loaded in memory. Now lets run partprobe command.

[root@10.176.87.179]# partprobe

Now if we see /proc/partitions we see sda8

[root@10.176.87.179]# cat /proc/partitions
major minor #blocks name

8 0 10485760 sda
8 1 104391 sda1
8 2 3068415 sda2
8 3 3068415 sda3
8 4 1 sda4
8 5 1020096 sda5
8 6 1020096 sda6
8 7 514048 sda7
8 8 987966 sda8
8 16 5242880 sdb

Now try the mkfs.ext3 command.

[root@10.176.87.179]# mkfs.ext3 -b 2048 -i 4096 -L /oracle /dev/sda8
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
247008 inodes, 493982 blocks
24699 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=506462208
31 block groups
16384 blocks per group, 16384 fragments per group
7968 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

So it has created the required file system.
-L is used to give label to that partition. This is not a mandatory option.

3) Create an entry in /etc/fstab to make partition persistant accrose reboot

Now to make this partition get mounted automatically when the system reboots, we should make entry in /etc/fstab file. /etc/fstab is the file which kernel reads during booting and mount the file system mentioned in this file.

This file has entry in following format



Device Name -> Name of the partition which needs to be mounted
Mount Point -> Directory which is to be used as moint point
File system Type -> Type used for creating file system. ext3 in our case.
Mount Option -> Various options used during mount. Check man page for mkfs command to check various mount options.
Dump Frequency -> 0 - never dump, 1 - daily, 2 - every other day etc. This is a sort of taking backup.
File System Check order -> Order in which file system is checked while the system boots. 0 - ignore, 1 - always for root etc.

So here is our entry will look like

[root@10.176.87.179]# cat /etc/fstab | grep oracle
LABEL=/oracle /oracle ext3 defaults 0 0

4) mount the partition for access to the user.

[root@10.176.87.179]# mkdir /oracle
[root@10.176.87.179]# mount -a
[root@10.176.87.179]# cd /oracle
[root@10.176.87.179]# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/sda8 935M 24M 863M 3% /oracle

mount -a is going to mount all the devices present in /etc/fstab file. You can also mount /dev/sda8 using following command

[root@12.123.58.123]# mount /dev/sda8 /oracle

Reference : Unix, Solaris, Linux, AIX, HP-UX Commands

As you know, there exists vast array of commands that enable you to do a multitude of tasks.

Depending on what you need to accomplish, you use only a certain subset of these commands.

These subsets differ from user to user and from need to need. However, there are a commands

that you commonly use. You need these commands either to answer your own questions or to

provide answers to the queries of the support professionals.



Linux Command Reference :

http://www.oracle.com/technology/pub/articles/calish_file_commands.html

http://www.oracle.com/technology/pub/articles/advanced-linux-commands/part1.html

http://www.oracle.com/technology/pub/articles/advanced-linux-commands/part2.html

Common Linux Commands Pocket Guide



HP-UX Command Reference :

http://docs.hp.com/en/hpuxman_pages.html



AIX Command Reference :

http://www.ibm.com/developerworks/aix/library/au-dutta_cmds.html



Solaris Command Reference :

http://www.sun.com/bigadmin/shellme



Unix Command Reference :

Common UNIX Commands Pocket Guide



Command Reference for all Operating System :

http://www.tomshardware.com/ucg



Comparative Study of Commands in all Platforms :

http://www.unixguide.net/unixguide.shtml



Admittedly, a list such as this can be helpful in quickly answering some of your own questions. However,

it does not cover everything that you might need. You can extend the usefulness of such a list by adding

other commands that answer additional questions not addressed here.

RPM (RedHat Package Manager)

Introduction

This post gives a brief introduction about RPM (RedHat Package Manager).

rpm is a command line utility installed when the linux OS is installed. rpm exe is located in /bin

rpm executable is installed as a part of rpm-4.4.2-47.el5.i386.rpm package.

Following are the various options with rpm command.

rpm main options

rpm -i -> Install the package. If the package is present it wont install and will say “nothing to do”, even if we are trying to install a higher version of package. If the package is not present it will install the same.

If you use -v and -h with -i option rpm gives “preety” output. Example

[root@station5 Server]# rpm -i zsh-4.2.6-1.i386.rpm

[root@station5 Server]# rpm -ivh zsh-html-4.2.6-1.i386.rpm
warning: zsh-html-4.2.6-1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing… ########################################### [100%]
1:zsh-html ########################################### [100%]

i -> Install
v -> Verbose
h -> Hash (for progress bar)

rpm -U -> Upgrade the package. If a new version of package is present then it will upgrade an existing installed version. If package is not applied before then it will apply. So upgrade works whether or not package is installed in OS.
rpm -F -> Freshen the package. This works only for the packages that are installed. If a new version of some package comes for any of the install package, then freshen will install the latest version. But a new version of package comes which is not yet installed in the OS, the freshen will not instal the latest version.
rpm -e -> Uninstalling a package. -e (erase) will remove a package from your system. The package name must be the installed package name and not the rpm file name. Example: rpm -e zip

RPM support FTP and HTTP. Example
[root@station5 Server]# rpm -ivh ftp://server1.example.com/pub/zsh-html-4.2.6-1.i386.rpm

Installing a new kernel using rpm

Installing a new kernel is different process. Usually as explained above when a new version of package comes, we go for -U option which is upgrade. Now with upgrade what exactly happens is that rpm will remove all the existing files and installed the latest rpm package with latest files, Except for configuration files which are backed up with extension .rpmsave.

Kernel is the core of operating system. So when we install new kernel we are not sure whether it will be stable and will work without any issues. So for installing kernel package we use rpm -i (install option). When rpm sees that its the kernel file we are installing it does not overwrite the existing kernel file instead it will create a new kernel files and a new kernel will be installed without removing the old kernel. It will also update grub.conf file with the details of new kernel and when you reboot the system your new kernel will take effect.

Example: Installing a new kernel

[root@station5 errata]# ls -rlt /boot
total 5142
-rw-r–r– 1 root root 1791572 Oct 11 2007 vmlinuz-2.6.18-53.el5
-rw-r–r– 1 root root 903969 Oct 11 2007 System.map-2.6.18-53.el5
-rw-r–r– 1 root root 64551 Oct 11 2007 config-2.6.18-53.el5
-rw-r–r– 1 root root 87586 Oct 11 2007 symvers-2.6.18-53.el5.gz
drwx—— 2 root root 12288 Aug 25 16:37 lost+found
-rw——- 1 root root 2369794 Aug 25 16:41 initrd-2.6.18-53.el5.img
drwxr-xr-x 2 root root 1024 Aug 25 19:41 grub
[root@station5 errata]#

[root@station5 errata]# rpm -ivh kernel-2.6.18-92.el5.i686.rpm
warning: kernel-2.6.18-92.el5.i686.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing… ########################################### [100%]
1:kernel ########################################### [100%]
[root@station5 errata]# cd /boot
[root@station5 boot]# ls -lrt
total 10315
-rw-r–r– 1 root root 1791572 Oct 11 2007 vmlinuz-2.6.18-53.el5
-rw-r–r– 1 root root 903969 Oct 11 2007 System.map-2.6.18-53.el5
-rw-r–r– 1 root root 64551 Oct 11 2007 config-2.6.18-53.el5
-rw-r–r– 1 root root 87586 Oct 11 2007 symvers-2.6.18-53.el5.gz
-rw-r–r– 1 root root 1806388 Apr 29 22:56 vmlinuz-2.6.18-92.el5
-rw-r–r– 1 root root 912686 Apr 29 22:56 System.map-2.6.18-92.el5
-rw-r–r– 1 root root 65406 Apr 29 22:56 config-2.6.18-92.el5
-rw-r–r– 1 root root 91734 Apr 29 22:56 symvers-2.6.18-92.el5.gz
drwx—— 2 root root 12288 Aug 25 16:37 lost+found
-rw——- 1 root root 2369794 Aug 25 16:41 initrd-2.6.18-53.el5.img
-rw——- 1 root root 2386531 Aug 25 20:23 initrd-2.6.18-92.el5.img
drwxr-xr-x 2 root root 1024 Aug 25 20:23 grub
[root@station5 boot]#

It will update grub.conf as well

title Red Hat Enterprise Linux Server (2.6.18-92.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-92.el5.img
title Oracle OS
root (hd0,0)
kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/sda3 rhgb quiet
initrd /initrd-2.6.18-53.el5.img

The default becomes the upgraded kernel.

You can decide which will be the default kernel using following file

[root@station5 boot]# cat /etc/sysconfig/kernel
# UPDATEDEFAULT specifies if new-kernel-pkg should make
# new kernels the default
UPDATEDEFAULT=yes

# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel

If UPDATEDEFAULT parameter is set to “yes” then newly installed kernel becomes default. If this is set to no then newly installed kernel will not be the default.

Other rpm Options

Following are the various usage of rpm command.

1) If a package is installed or not

[root@localhost Server]# rpm -qa zip
zip-2.31-1.2.2

2) A particular file is installed from which package

[root@localhost bluetooth]# rpm -qf /lib/modules/2.6.18-53.el5/kernel/net/bluetooth/bluetooth.ko
kernel-2.6.18-53.el5

3) List of files in a package

[root@localhost bluetooth]# rpm -ql zip
/usr/bin/zip
/usr/bin/zipcloak
/usr/bin/zipnote
/usr/bin/zipsplit
/usr/share/doc/zip-2.31
/usr/share/doc/zip-2.31/BUGS
/usr/share/doc/zip-2.31/CHANGES
/usr/share/doc/zip-2.31/LICENSE
/usr/share/doc/zip-2.31/MANUAL
/usr/share/doc/zip-2.31/README
/usr/share/doc/zip-2.31/TODO
/usr/share/doc/zip-2.31/WHATSNEW
/usr/share/doc/zip-2.31/WHERE
/usr/share/doc/zip-2.31/algorith.txt
/usr/share/man/man1/zip.1.gz

4) Package general information

[root@localhost bluetooth]# rpm -qi zip
Name : zip Relocations: (not relocatable)
Version : 2.31 Vendor: Red Hat, Inc.
Release : 1.2.2 Build Date: Thu 13 Jul 2006 10:33:56 AM IST
Install Date: Fri 29 Aug 2008 06:24:54 AM IST Build Host: hs20-bc2-2.build.redhat.com
Group : Applications/Archiving Source RPM: zip-2.31-1.2.2.src.rpm
Size : 302524 License: distributable
Signature : DSA/SHA1, Thu 18 Jan 2007 09:58:07 PM IST, Key ID 5326810137017186
Packager : Red Hat, Inc.
URL : http://www.info-zip.org/pub/infozip/Zip.html
Summary : A file compression and packaging utility compatible with PKZIP.
Description :
The zip program is a compression and file packaging utility. Zip is
analogous to a combination of the UNIX tar and compress commands and
is compatible with PKZIP (a compression and file packaging utility for
MS-DOS systems).

Install the zip package if you need to compress files using the zip
program.

5) Check prerequisits for a package

[root@localhost Server]# rpm -qa zip –requires
libc.so.6
libc.so.6(GLIBC_2.0)
libc.so.6(GLIBC_2.1)
libc.so.6(GLIBC_2.2)
libc.so.6(GLIBC_2.3)
libc.so.6(GLIBC_2.3.4)
libc.so.6(GLIBC_2.4)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)

6) Capability provided by rpm package

[root@localhost Server]# rpm -qa kernel –provides
kernel = 2.6.18
kernel-drm = 4.3.0
kernel-i686 = 2.6.18-53.el5
kernel(rhel5_gfs2_ga) = dc42db4764487d4d1e0e658af7ec2eef3c29d91e
kernel(rhel5_fs_lockd_ga) = 321666a6612cc9aa0ed9208fd0159456c9b1ffe3
kernel(rhel5_drivers_hwmon_ga) = 73ec105e064d9b09c6d44c6584f517b73a7d80ab
kernel(rhel5_net_core_ga) = 5aae342a66dcbcc14a7c1c001624f73a13620809
kernel(rhel5_drivers_net_ga) = f740f67835c214eb69aa8c623cb18a6c2ebcdc12
– output truncated –

7) To see the package revision history. The changes occured till now in that rpm package file

[root@localhost Server]# rpm -qa zip –changelog
* Thu Jul 13 2006 Jesse Keating - 2.31-1.2.2
- rebuild

* Sat Feb 11 2006 Jesse Keating - 2.31-1.2.1
- bump again for double-long bug on ppc(64)

* Wed Feb 08 2006 Jesse Keating - 2.31-1.2
- rebuilt for new gcc4.1 snapshot and glibc changes

– output truncated –

8) To check the scripts that runs upon installation or removal of rpm package

[root@localhost Server]# rpm -qa kernel –scripts
postinstall scriptlet (using /bin/sh):
if [ `uname -i` == "x86_64" -o `uname -i` == "i386" ]; then
if [ -f /etc/sysconfig/kernel ]; then
/bin/sed -i -e ’s/^DEFAULTKERNEL=kernel-smp$/DEFAULTKERNEL=kernel/’ /etc/sysconfig/kernel || exit $?
fi
fi
/sbin/new-kernel-pkg –package kernel –mkinitrd –depmod –install 2.6.18-53.el5 || exit $?
if [ -x /sbin/weak-modules ]
then
/sbin/weak-modules –add-kernel 2.6.18-53.el5 || exit $?
fi
preuninstall scriptlet (using /bin/sh):
/sbin/new-kernel-pkg –rminitrd –rmmoddep –remove 2.6.18-53.el5 || exit $?
if [ -x /sbin/weak-modules ]
then
/sbin/weak-modules –remove-kernel 2.6.18-53.el5 || exit $?
fi

9) Verifying the installed package.

One can verify the installed package using rpm -V option. Verifying an installed package will compare the file size, permissions, type, owner, MD5 checksum and modified time against RPM database.

[root@localhost Server]# rpm -V zip-2.31-1.2.2.i386
[root@localhost Server]# rpm -V kernel
[root@localhost Server]#

rpm -Va will verify all the installed packages.
Example:
[root@localhost Server]# rpm -Va
S.5….T c /etc/sysconfig/system-config-securitylevel
…….T c /etc/kdump.conf
..5….T c /etc/pki/nssdb/secmod.db
SM5….T c /etc/sysconfig/iptables-config

rpm -Vp will check the integrity of installed package against rpm file and not with database

RHEL 5 BOOT SEQUENCE & GRUB

Having worked on Apps and database administration, its time to broaden the scope. I will be discussing few topics on RHEL (RedHat Entrprise Linux) system administration. Hope this will help beginners to gain knowledge about the most matured open source operating system available in the world.

Lets have a very quick review of how the Linux boots. Here are the very brief steps.

1) When a PC is booted it starts running a BIOS program which is a memory resident program on an EEPROM integrated circuit. The BIOS program will eventually try to read the first sector on a booting media such as a hard or floppy drive. The boot sector contains a small program that the BIOS will load and attempt to pass run control to. This program will attempt to read the operating system from the disk and run it.

2) The small program containing in the boot sector that BIOS will load and attempt to pass control to is called bootloader. This is a small program residing in the 1st sector of primary partition. Primary partition by default is always /boot. This directory will have all files required for bootup.

The boot loader program is present in 2 stages in Linux.

Stage 1: Small stage and resides in MBR (Master boot record) or boot sector. This is the once we were taking above - A small program residing in the 1st sector of primary partition /boot.

Stage 2: This is the complete bootup program present in /boot partiton and is called from first stage.

So 1st stage is present in MBR and just called for stage 2.

This MBR sector is 512 bytes size. The first 446 bytes contains the GRUB program (1st stage).

3) GRUB program reads the configuration file /boot/grub/grub.conf during boot time. Since this file is present in /boot partition, this partition should be present in file system that GRUB will understand, because it has to read the file before OS starts. So /boot mount point should be formated with either ext2 or ext3.

We will discuss about GRUB file shortly after finishing this brief booting sequence steps.

So once control comes to GRUB program it executes and you will see a red spashing windown comes up which gives the countdown in seconds like

Booting up Redhat Enterprise Linux in 5..4..3.. Secs

Now before the conuntdown ends, you can press either space or enter. Once you press that, you will see a table on a screen with list of operating systems present in that server. Example if you have installed Windows initially and then you installed Linux this table will show both OS in the option.

But to get this list of OS you need to enter space or enter, else it will bootup the default operating system which will be Linux.

This showing up of operating system list can be controlled by parameter hiddenmenu present in GRUB config file. We will see this in a short while. Also you can control the time for which it should countdown (timeout parameter in GRUB file).

GRUB will load the specific kernel into the RAM (which kernel to load is passed to GRUB in its script) and uncompress the kernel program in RAM. Once it uncompresses, the control is taken over by kernel and job of GRUB script ends here.

4) The kernel initialization files generates output which may not be possible to see on screen as it scrolls quickly but can be seen in log message file /var/log/dmesg which contains the snapsot of these kernel messages taken just after control is passed to init.

Many packages and device drivers present in kernel program are called. Device drivers will check all there respective hardware devices if they are available. If successful in locating devices, the driver will initialize and usually log output to kernel message buffer.

kernel of Linux is made light weight and hence will load only the required module and packages. But if some of the modules also needs to be loaded along with the kernel, its not a good idea to make it a part of kernel. Instead in redhat those additional modules are included in initrd file, which is then temporarily mounted by kernel on a RAM disk to make modules available for initialization process. This file initrd is password as one of the arguement in GRUB file for loading the kernel. We will see this arguement when we see GRUB file.

After all essential drivers are loaded, kernel will mount the root filesystem in read-only mode so that no process while booting should make any changes to any file on disk.

The first process is then created and loaded and control is passed from kernel to that process. This first process that gets created is called “init”. This process is having PID=1 and its the initialization process. This will intialize the system.

5) Init process created above will read its configuration file /etc/inittab. This file stores the information like initial run level, system initialization script, run level specific scripts, trap certain key sequences etc.
We will discuss about this file in my next post when I will explain run levels.

The final file that is run in boot sequence is /etc/rc.d/rc.local

So if we have to make any customization or call a custom script, we can call from this file. Example if we want to start a database when our server boots up we can add a script in /etc/rc.d/rc.local to start a database.

Having a brief idea about boot sequence for Linux, lets see the content of GRUB config file

/boot/grub/grub.conf

The GRUB file in RHEL is present in /boot/grub/grub.conf

Following is the content of this file

# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(sd0,0)/grub/splash.xpm.gz
hiddenmenu
title Enterprise (2.6.9-55.0.0.0.2.ELhugemem)
root (sd0,0)
kernel /vmlinuz-2.6.9-55.0.0.0.2.ELhugemem ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-55.0.0.0.2.ELhugemem.img
title Enterprise-smp (2.6.9-55.0.0.0.2.ELsmp)
root (sd0,0)
kernel /vmlinuz-2.6.9-55.0.0.0.2.ELsmp ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-55.0.0.0.2.ELsmp.img
title Enterprise-up (2.6.9-55.0.0.0.2.EL)
root (sd0,0)
kernel /vmlinuz-2.6.9-55.0.0.0.2.EL ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-55.0.0.0.2.EL.img

lets understand meaning of each parameter here.

default -> This gives the default operating system to be booted in case the user is not giving any choice. Example if there are 2 OS installed on a server (lets say Linux and Windows, linux with number 0 and windows with number 1) then default=0 will boot Linux by default. The number is decided by the sequence in which these OS are listed in grub.conf above.

If we see the lines starting with “title”, these are the list of OS installed on server and this list (only the title) will be displayed at the time of booting when control goes from BIOS to GRUB. Since its present in grub.conf 1st stage of bootloader program will display this OS list.

In above file default=0 will pick “Enterprise (2.6.9-55.0.0.0.2.ELhugemem)” OS by default.

timeout -> This gives the time for which countdown will continue or time for which the list of OS should be displayed before taking default option. Example in out case timeout=5 means it will show the option for 5 seconds.

splashimage -> This option gives a red spashing window of redhat linux while showing the list of OS or while booting. If you remove this file it will show a black window.

hiddenmenu -> This options will hide the list of OS installed on server. It will only show the countdown. If you press enter or space (as explained previously in point 3 of boot sequence) then it will show the list of OS. If you remove this option by default while booting it will show the list of OS installed.

title -> As explained just now these are the title to be shown during booting from where you can select. You can change title to anything that you want. Example “My OS”. This will show “My OS” as one of the option during booting.

root (sd0,0) -> This tells us that the boot loader program is present in 1st disk (sd0 indicate 1st hard disk) and 1st partition (,0 indicates 1st partition). So here we are telling where exactly is the bootloader program.

kernel /vmlinuz-2.6.9-55.0.0.0.2.ELhugemem ro root=LABEL=/ rhgb quiet

kernel is a parameter, /vmlinuz-2.6.9-55.0.0.0.2.ELhugemem is a value -> This is the name of kernel file to be used.

ro -> opens the filesystem in readonly mode during booting. If we remove this arguement it will open the filesystem in read write mode.

rhgb -> This is redhar graphical boot. This parameters gives a graphical progress bar while booting. If we remove this then it will give a traditional black window with many [ OK ] messages.

root=LABEL=/ -> This gives the location of root directory where all the installation has happened. this is usaully /. We can also give device name directly example in my case the device name is /dev/sda2. So we can give root=/dev/sda2
This will also work.

quiet -> This will hide details while booting up and will show only few message ehgb mode or in traditional mode. Only few [ OK ] messages will be displayed corresponding to services that are getting started. Else if we remove this parameter many more detailed messages will be displayed.

initrd /initrd-2.6.9-55.0.0.0.2.ELsmp.img -> This gives the extended modules which we want to load while booting. As I explained that not all modules are part of kernel, in order to keep it light. So if additional extended modules needs to be intalled then we need to give this file as input.

SETTING CRON JOB & ANACRON in LINUX

Introduction

cron is a scheduling utility used by normal user to schedule recurring events. cron exists for every user. We can place any program of any script which we want to schedule to run periodically in side cron. We can also give the timing information for the script to run.

Placing entry in crontab

We can place the entry in cron using “crontab -e” command. -e arguement is for edit.
Entry in cron tab needs to be plcaed in specific format. Following is the required format.

(Script Name and arguement to script)
0-59 0-23 1-31 1-12 0-7 (Script Name and arguement to scrip)

Example:

To run script every sunday at 1:00 PM

00 13 * * 0 (Script to be executed)

* indicates all values. So above setting will execute script at 13:00 hours on all days of month and in all months and on sunday. The last 0 indicates sunday. The days of week start from 0 (or 7) which means sunday, 1 means monday etc, 6 means saturday.

To run the script on 10th Day of every 3rd month at 5:30 AM

30 05 10 3,6,9,12 * (script to be executed)

So above setting will run the script on 10th day of 3rd, 6th, 9th and 12th month of year at 5:30 AM.

When ever a user creates a cron a file gets created in /var/spool/cron directory by the name of that user. If you cat this file you will see all the crons setup by that user.

A user can list the cron using crontab -l

Example:

[avdeo@localhost ~]$ crontab -l
00 10 * * * echo “Message” > /dev/null

You can remove the cron using “crontab -r” command.

Crons for root (sysadmin)

When linux is installed, by defauly some crons get installed. These are the system crons. These crons are required by system for carrying out some system maintenance activities. Example, some of the system maintenance activity.

System crons are installed in a file called /etc/crontab

-bash-3.00$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

The format of this file is different then user cron.

Example, if we see the following line

02 4 * * * root run-parts /etc/cron.daily

Here the first 5 values are similar to the normal cron value. The 6th value is the username which will be used to run the comamnd in the seventh field. run-parts is the script present in /usr/bin directory. This script take 1 arguements. In this case the arguement we are passing is /etc/cron.daily.
/etc/cron.daily is the directory which contains several script that needs to be run daily. So any script which needs to be run daily as a root can be put in this directory. Also we have directories like /etc/cron.hourly, /etc/cron.weekly, /etc/cron.monthly etc

So all the scripts in /etc/cron.daily directory will run daily at 4:02 AM.

Anacron

Anacron is another utility that runs the jobs which didnt run because the server was down. For example if there are certain critical jobs which are scheduled to run daily and should never be skipped and suppose that server was down at the time these critical jobs are scheduled in cron to run. Then in such cases cron will not run these script at later point of time when the server comes up. Cron only run the script at specified time. once that time limit is skipped, the programs are run only on next cycle.
Anacron is the utility which can rescue at such situation.

This is how the anacron works:

When the cron runs the run-parts script from /etc/crontab for cron.daily, cron.weekly, cron.monthly, the first command that it runs is 0anacron. This command sets a time stamp in the files present in /var/spool/anacron

-bash-3.00$ ls -lrt /var/spool/anacron/cron*
-rw——- 1 root root 9 Sep 1 04:42 /var/spool/anacron/cron.monthly
-rw——- 1 root root 9 Sep 14 04:33 /var/spool/anacron/cron.weekly
-rw——- 1 root root 9 Sep 15 04:04 /var/spool/anacron/cron.daily

Example if we see the file /var/spool/anacron/cron.daily we see yesterdays time stamp.

[root@localhost ]# cat /var/spool/anacron/cron.daily
20080916

This is the time stamp when the command in /etc/cron.daily was last run.

On boot up, anacron command runs and check these files present in /var/spool/anacron/ directory and check the time stamp.

Anacron has its own config file /etc/anacrontab. This file tells which script should be run at what time interval. The config file looks as shown below.

-bash-3.00$ cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

1 65 cron.daily run-parts /etc/cron.daily
7 70 cron.weekly run-parts /etc/cron.weekly
30 75 cron.monthly run-parts /etc/cron.monthly

Here the first column gives the frequency with which the script in /etc/cron* directories should run.
If the script have not run at this frequency (as decided by last time stamp in /vatr/spool/anacron/cron* file) then anacron will wait for few minutes (as given by the second column in /etc/anacrontab file above) and then run the commands, thus ensuring that if a server was down during the time that cron should have run these commands, they are, nonethless, run.

Tuesday, July 8, 2008

LINUX POCKET GUIDE

THIS IS GUIDE IS VERY MUCH HELPFUL FOR LEARNING LINUX WITHIN A SHORT DURATION

Saturday, June 14, 2008

Linux BASICS

Linux How-To

Although i have been working with Oracle Application all various Unix flavors my favorite one has been Linux. In today's post i will shift focus from Oracle Applications and discuss some tips for doing some frequently used tasks on the Operating System.

This post is my first in a series of posts which i intend to put up here on the operating system. Although most of you would be using these quite frequently I just though of putting them in one place.

Finding Your Linux Release
The first set you would require to do most of the times as an Applications DBA before you start installing or troubleshooting is to find out the version of Linux you are running.
This you can get from a static file redhat-release located in the /etc directory

view /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant Update 2)

NFS mounting on Linux

Most often it is required to do a NFS mount of your disks across different servers. This particularly useful for doing Applications Installations and Patching. There are two aspects of configuration involved here. One is the sever that is the which is sharing the file system and the other is client which the host that is mounting the shared file system.

Supposing you want to mount a u01/sam on Node_A to Node_B

Configurations on Node_A
edit the /etc/exports file
vi /etc/exports
add the filesystem to mount
/u01/sam ro Node_B

you can either use the option ro which means read only or in case you wish to allow node_b to write into the filesystem use the rw option which is read writeable.

The change in exports file takes effect only after the restart of your NFS service daemon. use the service command to do that.

# service nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]

Configuration for Node_B
On Node_B simply create the mount point to hold the shared file system and mount it using the mount command.

#mkdir sam
#mount -t nfs Node_A:/u01/sam /sam

Setting Kernel Parameters

Most oracle products require certain kernel parameters to be set as a pre requisite for installation. Common kernel parameters include parameters for shared memory .

The /etc/sysctl.conf file takes care of your kernel parameters.
#vi /etc/sysctl.conf
kernel.shmmax = 2147483648
kernel.shmmni = 128
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000

However changes made to this file take effect only after the next reboot.

The sysctl command can be used to set the kernel parameter at runtime in linux.

sysctl -w kernel.shmmax=2147483648

You must however make the change in the /etc/sysctl.conf so that it is permanent.

Increasing the Swap space at runtime
Imagine this, you start the OUI and your pre installation check fails due to insufficient swap space. Now I agree that you got to check all this before starting the installation but just in case you missed it. You could always increase it on the fly.

Check the memory on your server
# free -m
total used free shared buffers cached
Mem: 8117 3204 4913 0 77 2648
-/+ buffers/cache: 478 7639
Swap: 101 0 101

Now say you need to increase it by 500 MB for your server, first locate a place you can spare this 500 MB in my case i found it in /u01

Use the dd command to create a swapfile
#cd /u01
# dd if=/dev/zero of=swapfile bs=1024 count=512000
512000+0 records in
512000+0 records out
# ls -ltr
drwx------ 2 root root 16384 May 1 2006 lost+found
-rw-r--r-- 1 root root 524288000 Nov 28 13:58 swapfile

Next issue the following two commands
# mkswap swapfile
Setting up swapspace version 1, size = 524283 kB
# swapon swapfile

Now check you memory again
# free -m
total used free shared buffers cached
Mem: 8117 2176 5941 0 45 1975
-/+ buffers/cache: 155 7962
Swap: 601 0 601

Bingo! here is your increased SWAP.

To make this change permanent add the line in your etc/fstab
/u01/swapfile swap swap defaults 0 0