Wednesday, March 30, 2016

Archive Redo Log

An Oracle database can run in one of two modes. By default, the database is created in NOARCHIVELOG mode. Oracle Database lets you save filled groups of redo log files to one or more offline destinations using its ARCH process, known collectively as the archived redo log, or more simply the archive log. The process of turning redo log files into archived redo log files is called archiving.

When in NOARCHIVELOG mode the database runs normally, but there is no capacity to perform any type of point in time recovery operations or online backups. Thus, you have to shutdown the database to back it up, and when you recover the database you can only recover it to the point of the last backup. While this might be fine for a development environment, the big corporate types tend to frown when a weeks worth of current production accounting data is lost forever. We can check the status of the archiving mode of a database suing hte following query:

SQL> archive log list;
SQL> select log_mode from v$database;
we can also with the below commnad to find the process:
$ ps -ef|grep -i _arc


The use of ARCHIVELOG mode requires some configuration of the database. First you must put the database in ARCHIVELOG mode and you must also configure the ARCH process, and prepare the archived redo log destination directories.


At first we need to set required parameters for archive. Then we will have to change the mode.

#Configuring the database for ARCHIVELOG Mode

By default in Oracle Database 10g and beyond, Oracle will send archived redo logs to the flash recovery(Starting in Oracle 11g release 2, Oracle has re-named the flash recovery area to be the fast recovery area, ostensibly to remove confusion with the flashback database.) area and we recommend this configuration.

By default default teo parameters are set for Archiving operation. We can use the alter system command to set these parameters if we want to change the default values. To properly setup the flash recovery area(fast recovery area), you will want to set two parameters as seen in the following list:

[ To check current parameter value: SHOW PARAMETER DB_RECOVERY_FILE_DEST ]
db_recovery_file_dest - ORACLE_BASE/flash_recovery_area - This is the location of the flash recovery area(fast recovery area). 
db_recovery_file_dest_size - 2g - This is the maximum size that can be used by the flash recovery area(fast recovery area).  If this size limit is exceeded, you must clear out space or database operations will eventually stall.


Use the alter system command to set these parameters if you do not want to use the default values.  Its recommended that the db_recovery_file_dest parameter be set to a directory location that is separate from the location of the Oracle software, your redo logs, and your data files.  You do not want to accidentally fill up ORACLE_HOME or cause performance issues due to contention.

When the flash recovery area(fast recovery area) is configured, a directory for the database will be created in the location defined by the db_recovery_file_dest parameter.  For example, our database has a directory called:

\u01\Oracle\product\flash_recovery_area\ACCLIST

Under this directory are individual directories for various file types such as ARCHIVELOG where the archived redo logs will reside.

In earlier versions of Oracle you had to enable a special Oracle process called ARCH by setting another parameter. Oracle Database 10g does not require this. When the database is in ARCHIVELOG mode, it will start the ARCH process automatically.

#Putting the database in ARCHIVELOG Mode

Once you have configured the flash recovery area(fast recovery area), you can put the database in ARCHIVELOG mode. Unfortunately, this requires that the database be shutdown first with the shutdown command (however, from earlier in the chapter, we note that shutdown immediate is the best option). Once you have shutdown the database, you will start the database in mount mode with the startup mount command. Then put the database in ARCHIVELOG mode, and finally open the database. Here is an example of how this all works from the command line:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  272629760 bytes
Fixed Size                   788472 bytes
Variable Size             103806984 bytes
Database Buffers          167772160 bytes
Redo Buffers                 262144 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.

Once the database is in ARCHIVELOG mode, it will start generating archived redo logs. It's always a good idea to make sure that the archived redo logs are getting generated. To do this, first force a log switch with the alter system switch logfile command. Then check the flash recovery area(fast recovery area) to make sure an archived redo log is created.



Archived Redo Log Data Dictionary Views

Oracle provides data dictionary views for the archived redo logs as seen in this list:

v$archived_log - Information about archived redo logs.
v$parameter - Shows the location of the flash recovery area(fast recovery area) where archived redo logs are created.
v$log_history - Contains information on previous redo logs

NOTE:  In RAC, a separate set of archive log files is created by each instance. Since each RAC instance has its own redo log files, the corresponding archive log files are produced when the log switch takes place. The archive log files may be written to a local file system or to a cluster file system. Oracle does not insist upon a particular type of file system. Writing to a clustered file system has the added advantage of being available to archive all the nodes.


No comments: