Thursday 30 May 2013

Difference Between Archive, Redo and Undo Logs.

Difference Between Archive, Redo and Undo Logs.

Difference between Redo and Undo logs

Redo information, in a nutshell, is stored ONLY for recovery purposes (whether instance recovery or database recovery) whereas UNDO has extended functionality and usage. Redo stores undone changes as well. To be prcise, redo = do again (roll forward) and undo = erase the changes (roll back). I'll try and explain couple of scenarios.

Redo log stores all information about changes to database blocks. You insert 1000 rows--Oracle will generate redo and store it in log buffer (which will be later written into redo logs and then archived logs for recovery purposes). And the changes will be stored in UNDO (in case you want to rollback the insert later). Not only that. You now update 1000 rows and commit it. Oracle does not "have to necessarily" mark those blocks as committed. Instead it updates the data block(s) with a reference to the undo segment information. In fact Oracle only marks that UNDO segment slot as committed at this point and not necessarily the data block. Now a different session throws a select query on the table and Oracle duly visits that data block but the data block header will say now that there is an uncommitted change in the block(s). Here comes UNDO in play. Oracle will now go to the UNDO segment header and check the slot where it will say it's committed--so it will go back to the data block and do a cleanout of dirty blocks (delayed clean out). Another scenario is, you throw a query on a million record table and while it's visiting the required blocks........another session comes and updates some of the blocks that you need. Now Oracle will have to look at the datablock header and then go to UNDO and get that information. So UNDO has much more to do than the redo.

Now, coming to your second question, I think it will be much easier to explain now after the first question. Database files will have to store only the committed transactions, in an ideal situation. Otherwise, you cannot recover your database in case of disaster. On the other hand, REDO doesn't care whether it's a committed transaction or an uncommitted transaction. It has to store all changes to the blocks. Now if your database crashes, all the transactions will be applied to your database files using archived logs (or redo logs based on the DR situation) and then uncommitted transactions will be undone (rolled back).





Rememeber database files are online and they are written to by DBWR process. So we have database files, redo log files and archive log files.
In order to avoid scanning the entire log when doing a recovery, database performs checkpoints that summarize the status of the database. This checkpoint operation provides a shortcut to recovery. At checkpoint time, the database knows that all dirty pages have been written to disk (i.e. database files). At time of recovery, the log (that includes both completed and incomplete transactions) is used to bring the database back to a consistent state. The system locates the time of last checkpoint and finds that position in the log file. It then rolls forward all completed (read commited) transactions that occurred after the last checkpoint, and rolls back all transactions that were not committed, but began before the last checkpoint. So that is where online redo log files are used.

Now imagine you had to back up your 100+GB database every 10 minutes. That would be a waste of space! So you take a backup of your database at time t and the archiver process backups redo logs periodically to archive logs so that redo log files can be overwritten and RMAN will use the last backup plus the archive log files to recover your database to point in time.

Now I mentioned checkpoint process. The Checkpoint Process regularly initiates a checkpoint, which uses DBWR to write all dirty blocks back to the datafiles, thus synchronizing the database. Imagine a single checkpoint is running and all redo log files have been used up. At this point, Oracle will wait until all the previously queued dirty blocks have been written from the buffer to disc (database files) before any of the redo log files can be considered redundant and available for re-use (i.e. can be overwritten). This will result in the following message in the alert.log:

Thread 1 advanced to log sequence 17973
  Current log# 3 seq# 17973 mem# 0: /oracle/data/HAM1/log3aHAM1.dbf
  Current log# 3 seq# 17973 mem# 1: /oracle/data/HAM1/log3bHAM1.dbf
Thread 1 cannot allocate new log, sequence 17974
Checkpoint not complete
  Current log# 3 seq# 17973 mem# 0: /oracle/data/HAM1/log3aHAM1.dbf
  Current log# 3 seq# 17973 mem# 1: /oracle/data/HAM1/log3bHAM1.dbf
Thread 1 advanced to log sequence 17974

I am sure you have done the following:

alter database mount;
 
Database altered.


When you mount a database, Oracle associates the started instance with the database. Oracle control files are opened and read. However no verification such as rollback/recovery is carried out

alter database open;
  
Database altered.


An open command opens data files, redo logs, it performs database consistency and auto recovery. At this stage the database is now ready to be used by all valid users.

A checkpoint process is an integral part of database logging and recovery. The operation itself is known as "checkpoint." A checkpoint writes both the log records , plus writing dirty (modified) data buffers to disk. It is essential that a checkpoint forces the flushing of log records from redo buffers to redo log filese. This makes sense in that if we flushed the modified data buffers to disk and do not flush the log records to disk and the system crashed, we would have modified records on disk with no log information associated with them. We need to flush the log buffers before writing modified data buffers so that the database integrity from a transactional point of view is maintained. BTW, a buffer is a database block, which happens to be in memory. A checkpoint causes the latest SCN to be written (updated) into the datafile header and control files.

The checkpoint frequency is affected by different parameters and equally importantly the size of redo logs. A change of redo log file will force a checkpoint in the database. Checkpoint is a resource intensive activity and it needs to be kept to a reasonable number to ensure an optimum recovery time and little or no impact on the database activity. You should use big enough redo logs - to reduce normal checkpoint frequency.

The following events trigger a checkpoint.
) Redo log switch (alter system switch logfile).
2) LOG_CHECKPOINT_TIMEOUT has expired
3) LOG_CHECKPOINT_INTERVAL has been reached
4) Manaul checkpoint force (alter system checkpoint)


No,the checkpoint process doesn't, It's job checkpointing process by updating the file headers of the data files.The Database Block Writer (DBWn) responsible for writing dirty blocks to disk.Basically chekpointing is the process of two sub process.

1) Write Dirty buffer from database buffer cache to datafile which is done by DBWR.
2) CKPT update alls datafile header with the SCN to memorize that i have written alls data buffer block from database buffer cache to that time when it occurs by SCN.

Regards,

Suresh R
oracle dba .

Kill oracle session process in linux and windows platforms

Kill oracle session process in linux and windows platforms :
In various critical situations Oracle DBA has to decide to kill existing session or kill the background process of Oracle database. At this moment remote Oracle DBA should need to terminate session/process called as termination of session of any instance.

If you want kill or terminate process using only operating system command only.How can you kill process in Unix?

In linux and unix :


We can check running processes in Unix and Linux using "ps" command. We are able to get process id from said command.

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

Now use "kill" command with "-9" syntax to kill process id as given below example.kill command with -9 for ensure not blocking command and surity if execution of "kill" command.

$kill -9 1451

In Windows oracle kill cmd :


For using ORAKILL utility we should need process id from sqlplus. ORAKILL utility is shipped with Oracle software itself. When we install Oracle software same time ORAKILL also is being installed in ORACLE_HOME\bin folder. It can kill process same as "kill -9" command in Unix/Linux. But one drowback of this utility that is we need process id using sqlplus and from v$process,v$session data dictionary views as follows.

SQL> select a.username, b.spid from v$session a, v$process b where a.paddr = b.addr and a.username ='SCOTT';

USERNAME SPID.
-------- ----
SCOTT 1456 

Now we can kill server process of 1456 of scott user using ORAKILL utility from command line of Windows as follows.

C:\> orakill instance_name spid

Example
C:\> orakill orcl 1456

We will get following message in our command prompt of windows.
"Kill of thread id 1456 in instance ORCL successfully signalled[sic]."

In Windows task kill cmd :


But if sometime SQL*Plus doesn't working like database stuck or instance hang situation. We need to terminate Oracle instance. But we are unable to execute command using SQL*Plus "shutdown abort" or our shutdown abort command also stuck in Windows. Then how can we terminate instance? Yes, we can restart instance service from service menu. But if we want to use only command line then how to terminate instance or kill instance or background process.

We can use TASKKILL command for terminating instance. Using tasklist command we can get thread id of Oracle.exe and using TASKKILL command we can terminate or kill instance in command line as follows.

C:\>tasklist 
Image Name PID Session Name Session# Mem Usage
=============== ======== ======== ============
System Idle Process 0 Console 0 16 K
oracle.exe 1456 Console 0 282,100 K
smss.exe 636 Console 0 420 K 

C:\>taskkill /pid 1456 /T 


Best of luck.

Thanks & Regards,

Suresh R
oracle dba.

Oracle 10g installation on rhel5

PRE INSTALLATION STEPS
  

Connecting through Xmanager ;

DISPLAY=IP Adress(Your desktop):0.0; export DISPLAY


Checking below RPMs:

rpm -q compat-db.x86_64 compat-libstdc++-33.i386 compat-libstdc++-33.x86_64 cpp.x86_64 elfutils-libelf.i386 elfutils-libelf.x86_64 gcc-c++.x86_64 gcc.x86_64  glibc-devel.i386 glibc-devel.x86_64  glibc-headers.x86_64 glibc.i686 glibc.x86_64 ksh.x86_64 libaio-devel.i386 libaio-devel.x86_64 libaio.i386 libaio.i386 libaio.x86_64 libaio.x86_64 libstdc++.i386 libstdc++.x86_64 make.x86_64 setarch.x86_64 sysstat.x86_64  

libXp-1.0.0-8.i386.rpm


Creating OS User :

root:home/oracle]groupadd  dba
root:home/oracle]useradd -g dba oracle


1) create group and user in root

2)set the following kernel parameters in /etc/sysctl.conf

kernel.shmall = 4294967296
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144
net.core.wmem_max = 262144
3)execute sysctl -p to check kernel parameter

4)add following line in /etc/pam.d/login
session    required     /lib/security/pam_limits.so



5) add the following lines in /lib/security/pam_limits.so
oracle           soft    nproc            2047
oracle           hard    nproc            16384
oracle           soft    nofile           1024
oracle           hard    nofile           65536

INSTALLATION STEP


Create directories where the Oracle Software and database will be installed.
mkdir -p /ortldbbin/oracle/product/10.2.0/db_1
chown -R oracle:oinstall /ortldbbin/
chmod -R 775 /u01


6)RUN IN USER

./media/cdrecorder/home/oracle/Desktop/database/runInstaller

POST INSTALLATION STEPS

7)RUN ./home/oracle/orainventory /orainstRoot.sh
8)RUN ./home/oracle/oracle/product/10.2.0/db_1/root.sh

9)setting oracle environment save the following
GO TO THE FOLLOWING DIRECTORY
/home/oracle/
RUN
vi .bash_profile

ADD SCRIPT
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=/home/oracle/product/10.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_SID=ORCL


Any clarification :


Thanks & Regards,

Suresh R
oracle dba.


Difference between Physical and logical Standby Database

Oracle provides two types of standby databases:
1. Physical Standby Database
Standby database is called “physical” if the physical structure of stand by exactly matches with stand by structure. Archived redo log transferred from primary database will be directly applied to the stand by database.
2. Logical Standby Database
Stand by database is called “logical”, the physical structure of both
databases do not match and from the archived redo log we create SQL statements then these statements will be applied to stand by database.


Thanks & Regards,
Suresh R
oracle dba.