Tuesday, 23 September 2014

Managing the Online Redo Logs

                  The online redo logs are Oracle’s means of ensuring that all the changes made by the users are logged, in case there’s a failure before those changes can be written to permanent storage. Thus, redo logs are fundamental for the recovery process.
Oracle organizes its redo log files in redo log groups, and you need to have at least two different groups of redo logs with at least one member in each. You need to have at least two redo groups, because even when one redo log is being archived, the log writer should be able to write to an active redo log. Although your database will run just fine with only one member in each redo log group, Oracle strongly recommends that you multiplex the online redo logs. Multiplexing simply means that you maintain more than one member in each of your redo log groups. All members of a redo log group are identical—multiplexing is designed to protect against the loss of a single copy of a log file. When you multiplex the online redo log files, the log writer writes simultaneously to all the members of a group.

Creating Online Redo Log Groups:- 

Below command will add a new Redolog Group and its members.
Syntax:
 SQL> alter database add logfile group 4 ('logfile_location/log01.log','logfile_location/log01.log') size 10M;
Example: 
SQL> alter database add logfile group 4 
('/oradata/oracle/datafiles/catalog/redo04.log',
 '/oradata/oracle/datafiles/catalog/redo05.log') size 10M;

Adding Member to a existing Group:-

Syntax:-
SQL> alter database add logfile member 
'Log_file_location/name.log' to group 1;
Example:-
sql>alter database add logfile member
'
/oradata/oracle/datafiles/catalog/redo01_02.log' to group 1;
Note: We don't have to specify the size for new redo log member being added to group 1 the new member will simply be sized the same as the existing members of the group.

Rename Redolog Files:-

1. Shut down the database and start it up in the mount mode:
SQL> shutdown immediate
SQL> startup mount
 
2. Move the files to the new location with an operating system command:
$ mv /oradata/oracle/datafile/redo01.log /u01/datafiles/redo001.log

3. Use the ALTER DATABASE RENAME datafile command to rename the file within the control file:
SQL> alter database rename file '/oradata/oracle/datafile/redo01.log'
to '/u01/datafiles/redo001.log';

Dropping Online Redo Logs:-

You can drop an entire redo log group by using the following command:
SQL> alter database drop logfile group 4;

To drop a single member of an online redo log group, use this command:
SQL> alter database drop logfile member
 '/u01/datafiles/mul_redo01.log';

If the redo log file you want to drop is active, Oracle won’t let you drop it. You need to use the following command to switch the log file first, after which you can drop it:
SQL> alter system switch logfile;

Online Redo Log Corruption:-

You can set the DB_BLOCK_CHECKSUM initialization parameter to make sure Oracle checks for corruption in the redo logs before they’re archived. 
If the online redo logs are corrupted, the file can’t be archived, and one solution is to just drop and re-create them. But if there are only two log groups, you can’t do this, as Oracle insists on having a minimum of two online redo log groups at all times. However, you can create a new (3rd) redo log group, and then drop the corrupted redo log group. Also, you can’t drop an online redo log file if the log file is part of the current group. Your strategy then would be to reinitialize the log file by using the following statement:
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
If the log group has not been archived yet, you can use the following statement:
SQL> ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 1;

Monitoring the Redo Logs:-

You can use two key dynamic views, V$LOG and V$LOGFILE, to monitor the online redo logs.
The V$LOGFILE view provides the full filename of the redo logs, their status, and type

SQL>select * from v$logfile;
 
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- -------------------------------------------------- ---
3  ONLINE /oradata/oracle/datafiles/catalog/redo03.log NO
2  ONLINE /oradata/oracle/datafiles/catalog/redo02.log NO
1  ONLINE /oradata/oracle/datafiles/catalog/redo01.log NO

The V$LOG view gives detailed information about the size and status of the redo logs, as well as showing whether the logs have been archived:
SQL> select group#, sequence#, bytes/1024/1024, archived, members from v$log;

GROUP# SEQUENCE# BYTES ARC MEMBERS
---------- ---------- --------------- --- ----------    
1             0             50       YES       1
2            55            50       NO        1
3           54             50       YES       1


No comments:

Post a Comment

Ask your Questions....