ORACLE DATABASE-REDO lOG FILES

 The contents are of my own testing and deployments. Not guaranteed that these might work in your environment. Please test before usage.


REDO LOG FILES:

  • Redo log files are operating system files used by Oracle to maintain logs of all transactions performed against the database. 
  • The primary purpose of these log files is to allow Oracle to recover changes made to the database in the case of a failure.
  • An Oracle database must have at least two redo log files, and most databases have more than two. These files are written by the LGWR process in a circular fashion; when the last log file is filled, the first log file is reused. 


Example:

If a database has three redo log files, blocks will be written to file1 until it is filled; then that file is closed, and LGWR begins writing to file2 (a log switch).

When file2 is filled, LGWR switches to file3. 

When file3 is filled, file1 is reused, and soon.


Important Notes:

Unused - It newly added redo log group, Until not used.

Current - LGWR enabled, the redo entries transfer from RLBC to this group

Active - ARWR enabled. The redo entries transfer from this group to Archiver

Inactive -  Its completed the Archive process, Ready to reuse.

Clearing - its recreated after clearing the group(alter database clear logfile group1)

Clearing current – it being clearing

 

Member status

Blankfile is in use(now in use)

State contents as incomplete

Deleteno longer use,drop (os level)

Invalid unable to access(created new member)


Views: logfile(group):

SQL> select * from v$log;

SQL> alter  database add logfile group 4 ('/home/oracle/dev/oradata/log/log4a.log') size 50m;

SQL> alter system switch logfile;

SQL> alter database drop logfile group4a;

SQL> alter database clear logfile group 1;

SQL> alter database clear unarchived logfile group 3;

SQL> select group#, status from v$log;

SQL> alter database rename file '/home/oracle/dev/oradata/log/log01.log' to '/home/oracle/dev/oradata/log/log1a.log';


Logfile(member):

SQL> select GROUP#,MEMBER,STATUS from v$logfile;  

SQL> alter database add logfile member '/home/oracle/dev/oradata/log/log4b.log' to group 4

SQL> alter database drop logfile member '/home/oracle/dev/oradata/log/log4b.log';

SQL> select member from v$logfile where group# = 3;

MEMBER

----------------------

/home/oracle/dev/oradata/log/log03.log

Views:

1)V$logfile

2)V$log

3)V$loghistory


Restriction to drop groups:

1)An instance required at least 2 group of online redologfile.

2)An active or current group cannot be dropped.

3)When an online redo lofgile group is dropped, the os file not dropped.

Restriction to drop Members:

1)Can’t drop the last valid member of the group.

2)Can’t drop the current log file member.

3)Can’t drop the unarchived group member.

4)The OMF features group only allowed to drop a member physically.


SQL> desc v$log;

 Name                                                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 GROUP#                                                                                 NUMBER

 THREAD#                                                                                NUMBER

 SEQUENCE#                                                                          NUMBER

 BYTES                                                                                       NUMBER

 BLOCKSIZE                                                                             NUMBER

 MEMBERS                                                                              NUMBER

 ARCHIVED                                                                              VARCHAR2(3)

 STATUS                                                                                   VARCHAR2(16)

 FIRST_CHANGE#                                                               NUMBER

 FIRST_TIME                                                                           DATE

 NEXT_CHANGE#                                                                NUMBER

 NEXT_TIME                                                                           DATE

 CON_ID                                                                                   NUMBER

 

SQL> desc v$logfile;

 Name                                                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 GROUP#                                                                                 NUMBER

 STATUS                                                                                   VARCHAR2(7)

 TYPE                                                                                         VARCHAR2(7)

 MEMBER                                                                                VARCHAR2(513)

 IS_RECOVERY_DEST_FILE                                                VARCHAR2(3)

 CON_ID                                                                                   NUMBER

SQL> select GROUP#,MEMBERS,STATUS from v$log;

 GROUP#    MEMBERS STATUS

---------- ---------- ----------------

                 1                 1 CURRENT

                 2                 1 INACTIVE

                 3                 1 INACTIVE

                 4                 1 INACTIVE

 SQL> alter system switch logfile;

 System altered.

 SQL> alter system switch logfile;

 System altered.

 SQL> select GROUP#,MEMBERS,STATUS from v$log;

  GROUP#    MEMBERS STATUS

---------- ---------- ----------------

                 1                 1 ACTIVE

                 2                 1 INACTIVE

                 3                 1 INACTIVE

                 4                 1 CURRENT

 SQL>  alter system switch logfile;

 System altered.

 SQL> select GROUP#,MEMBERS,STATUS from v$log;

 GROUP#    MEMBERS STATUS

---------- ---------- ----------------

                 1                 1 INACTIVE

                 2                 1 INACTIVE

                 3                 1 CURRENT

                 4                 1 ACTIVE

 

SQL> alter system switch logfile;

 System altered.

 SQL> select GROUP#,MEMBERS,STATUS from v$log;

 

    GROUP#    MEMBERS STATUS

---------- ---------- ----------------

                 1                 1 INACTIVE

                 2                 1 CURRENT

                 3                 1 ACTIVE

                 4                 1 ACTIVE

 SQL> select member, group# from v$logfile;

 SQL> alter database rename file '/home/oracle/dev/oradata/log/log4.log' to '/home/oracle/dev/oradata/log/log4a.log';

 Database altered.

 SQL> alter database add logfile member '/home/oracle/dev/oradata/log/log4c.log' to group 4;

 Database altered.

SQL>  alter database drop logfile member '/home/oracle/dev/oradata/log/log4c.log'

 Database altered


3 Comments

DELETE Statement in ORACLE DB— Step by Step Internal Flow with classroom example.

Imagine your Oracle database like a school, and you’re Teacher decides to remove a student (row) from the classroom(table). Let’s see how the journey works step by step: 1)Classroom = Oracle Table 2)Students = Rows (Records) 3)Class Teacher = Oracle Server Process 4)Attendance Register = Data Dictionary User fires DELETE statement: DELETE FROM students WHERE grade = 'D'; Internal Processing Steps: Client Process Sends DELETE Statement to Server Process The teacher receives a request to remove a student from the classroom. Syntax Check (Parsing) The teacher checks if the request is grammatically correct — proper command, keywords, and a semicolon. Semantic Check Teacher verifies if the classroom exists and whether the condition (like grade = 'D') makes sense. Object Resolution Teacher confirms that the ‘students’ classroom (table) exists in the school records (data dictionary). Optimization Decides the fastest way to find those students — by roll number, grade, or al...