<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gakash on Medium]]></title>
        <description><![CDATA[Stories by Gakash on Medium]]></description>
        <link>https://medium.com/@gakash1503?source=rss-98e36ed599c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ljjxoVHOSj6VILtR</url>
            <title>Stories by Gakash on Medium</title>
            <link>https://medium.com/@gakash1503?source=rss-98e36ed599c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:33:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gakash1503/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How redo logs switch approach Really Works: Algorithms uses by database]]></title>
            <link>https://medium.com/@gakash1503/how-redo-logs-switch-approach-really-works-algorithms-uses-by-database-f495f45e80ba?source=rss-98e36ed599c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f495f45e80ba</guid>
            <category><![CDATA[buffer]]></category>
            <category><![CDATA[redolog]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[transaction-log]]></category>
            <dc:creator><![CDATA[Gakash]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 11:03:22 GMT</pubDate>
            <atom:updated>2026-08-23T11:03:22.043Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Oracle</strong> uses a circular sequential reuse mechanism, while the ability to reuse a group depends on its recovery and archive state — not a simple round-robin algorithm alone. Oracle documents that a normal log switch occurs when the current redo log fills, can also be forced manually or by ARCHIVE_LAG_TARGET, and that a group must be reusable before LGWR can write into it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LENATvxIU6KBRtxV" /><figcaption>Photo by <a href="https://unsplash.com/@sunder_2k25?utm_source=medium&amp;utm_medium=referral">Sunder Muthukumaran</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine your database is processing thousands of transactions every second.</p><p>Every INSERT, UPDATE, and DELETE generates redo. That redo continuously flows into the current online redo log group. Eventually, Oracle stops writing to that group and begins writing into another one.</p><p>Most people simply say:</p><p>“Redo log becomes full, so Oracle switches.” That’s correct — but incomplete.</p><p>The real question is: How does Oracle decide which redo log group comes next, and under what conditions can it actually reuse that group?</p><p>This article explains the internal logic behind Oracle redo log switching using practical examples and real Oracle terminology.</p><p>What is an online redo log?</p><p>Before understanding log switching, we need to understand the object being switched.</p><p>An Oracle database contains multiple online redo log groups. Each group contains one or more redo log members. A group is the logical unit Oracle switches between.</p><p>A member is simply a physical copy of that group’s redo for multiplexing and protection.</p><p>For example:</p><p>Group</p><p>Members</p><p>Group 1</p><p>redo01a.log, redo01b.log</p><p>Group 2</p><p>redo02a.log, redo02b.log</p><p>Group 3</p><p>redo03a.log, redo03b.log</p><p>Oracle writes identical redo into every member belonging to the same group. The switch always happens between groups, not individual members. Oracle’s documentation describes redo groups and members as the logical and physical organization of the online redo log. <br>Database</p><p>The myth: Is redo switching Round Robin?</p><p>Many interview answers say:</p><p>Oracle uses Round Robin.</p><p>That is partially true.</p><p>A better explanation is:</p><p>Oracle writes redo groups in a circular sequential order, but it can only reuse the next group if that group has become reusable.</p><p>So the algorithm is not simply:</p><p>It is actually:</p><p>The important word is reusable.</p><p>That is the key Oracle internally evaluates before completing a switch. Oracle documentation explains that online redo logs are reused in sequence, but reuse depends on whether the log is still needed for recovery and, in ARCHIVELOG mode, whether it has been archived.</p><p>The internal redo log switching algorithm</p><p>Let’s simplify Oracle’s behavior into an algorithm.</p><p>Step 1: LGWR writes redo continuously</p><p>Every transaction generates redo records.</p><p>Those records enter the Redo Log Buffer.</p><p>LGWR continuously flushes them into the CURRENT redo log group.</p><p>At this point, Oracle is not thinking about another group.</p><p>It simply keeps writing sequentially.</p><p>Step 2: Oracle detects a switch condition</p><p>A switch does not happen randomly.</p><p>There are three major triggers.</p><p>Trigger A — Current redo becomes full</p><p>This is the default and most common condition.</p><p>Oracle reaches the physical end of the redo log file.</p><p>Example:</p><p>This is Oracle’s normal behavior. <br>Oracle Docs</p><p>Trigger B — DBA manually forces it</p><p>A DBA may execute:</p><p>ALTER SYSTEM SWITCH LOGFILE;</p><p>This immediately requests Oracle to move to the next redo group even if the current log is only partially filled. Oracle officially supports forced log switches for maintenance and operational requirements. <br>Oracle Docs</p><p>Trigger C — ARCHIVE_LAG_TARGET</p><p>Oracle can also force periodic switches using the initialization parameter:</p><p>ARCHIVE_LAG_TARGET</p><p>Example:</p><p>According to Oracle documentation, this parameter causes Oracle to force a log switch after the configured interval, while a value of 0 disables the time-based switching feature.</p><p>Step 3: Oracle identifies the next redo group</p><p>Suppose we have four groups.</p><p>If Group 2 is current, Oracle’s next candidate is Group 3.</p><p>Not Group 1.</p><p>Not the smallest group.</p><p>Not the emptiest group.</p><p>It follows the redo thread sequence maintained internally by Oracle. Oracle documents log switches as advancing from one online redo log to another with sequence numbers identifying each filled log.</p><p>Step 4: Can Oracle actually reuse that group?</p><p>This is where the real algorithm begins.</p><p>Oracle checks the status of the candidate group.</p><p>The important statuses are:</p><p>CURRENT</p><p>Currently writing<br>LGWR is actively writing redo into this group.</p><p>ACTIVE</p><p>Still needed<br>The redo is still required for instance recovery because checkpoint processing has not progressed far enough.</p><p>INACTIVE</p><p>Reusable<br>The redo is no longer required for instance recovery and can become available for reuse, subject to archiving requirements in ARCHIVELOG mode.</p><p>A very common misconception is:</p><p>ACTIVE means Oracle is writing.</p><p>That’s wrong.</p><p>CURRENT means Oracle is writing.</p><p>ACTIVE means Oracle may still need that redo for crash recovery.</p><p>INACTIVE is the status that generally allows reuse. Oracle’s redo management documentation distinguishes current, active, and inactive redo log states and explains reuse requirements.</p><p>Visualizing the reuse decision</p><p>Imagine this situation.</p><p>Oracle wants to move from Group 1 → Group 2.</p><p>But Group 2 is still ACTIVE.</p><p>Even though Group 3 looks reusable, Oracle doesn’t simply skip the sequence.</p><p>Instead, it waits until Group 2 becomes reusable.</p><p>That waiting produces one of the most famous Oracle wait events.</p><p>Why does checkpoint incomplete happen?</p><p>This deserves its own section because it is often misunderstood.</p><p>Suppose Group 2 contains redo describing changes that are still only present in memory.</p><p>The corresponding dirty data blocks haven’t yet been written into the datafiles.</p><p>Oracle cannot overwrite redo that might still be necessary to recover those dirty buffers. Therefore LGWR waits.</p><p>The database reports:</p><p>log file switch (checkpoint incomplete)</p><p>The important takeaway is:</p><p>The problem is not that LGWR cannot switch. The real problem is that DBWR has not progressed enough for the checkpoint to make the next redo group reusable.</p><p>A log switch initiates checkpoint activity, and the checkpoint-incomplete wait occurs when Oracle cannot yet reuse the target redo log because recovery requirements have not been satisfied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zih3CEM41afiy0NY" /><figcaption>Photo by <a href="https://unsplash.com/@wildmax?utm_source=medium&amp;utm_medium=referral">Massimo Botturi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Why does archiving needed happen?</p><p>Now consider a database running in ARCHIVELOG mode.</p><p>When a redo log becomes full, ARCn must archive it before Oracle can reuse it later.</p><p>If the next required redo group has not been archived yet, LGWR cannot reuse it.</p><p>Oracle then reports:</p><p>log file switch (archiving needed)</p><p>This usually points toward archive destination issues, slow archive I/O, insufficient archive processes, or archive storage problems rather than checkpoint progress. Oracle’s wait-event reference explicitly defines this wait as LGWR waiting because the log it needs to switch into has not yet been archived.</p><p>ACTIVE vs INACTIVE vs CURRENT</p><p>This is one of the most searched Oracle interview questions.</p><p>Status</p><p>Meaning</p><p>Can LGWR write?</p><p>CURRENT</p><p>Currently receiving redo</p><p>Yes</p><p>ACTIVE</p><p>Needed for crash recovery</p><p>No</p><p>INACTIVE</p><p>Recovery no longer needs it</p><p>Yes, if archive requirements are satisfied</p><p>This distinction is fundamental for understanding log switches and troubleshooting Oracle performance.</p><p>Does Oracle skip a redo group?</p><p>This is an excellent interview question.</p><p>Example</p><p>Suppose the sequence is:</p><p>Current = G2</p><p>Oracle wants G3 next.</p><p>Now imagine:</p><p>Group</p><p>Status</p><p>G1 : INACTIVE</p><p>G2 : CURRENT</p><p>G3 : ACTIVE</p><p>G4 : INACTIVE</p><p>Will Oracle jump directly to G4? — &gt; No.</p><p>Oracle advances according to the redo thread sequence and waits until the required next group becomes reusable rather than treating the groups as an arbitrary pool. The practical result is that a blocked target group can stall the switch even if another later group appears reusable.</p><p>This is why simply saying Round Robin is not enough.</p><p>The better terminology is: Sequential circular reuse with recovery validation.</p><p>Understanding checkpoint in relation to log switch</p><p>Another misconception is: Checkpoint causes log switch.</p><p>Actually it’s the opposite relationship. A log switch initiates checkpoint activity.</p><p>But checkpoints can also happen independently.</p><p>A log switch starts a checkpoint, but a checkpoint does not necessarily mean a log switch occurred. <br>Oracle</p><p>Visualizing it:</p><p>Complete internal lifecycle, Now let’s combine everything into one flow.</p><p>This diagram represents the practical internal logic a DBA should remember.</p><p>Real production example</p><p>Imagine an OLTP banking database.</p><p>Configuration:</p><p>Group No. || Size</p><p>Group 1 || 500 MB</p><p>Group 2 || 500 MB</p><p>Group 3 || 500 MB</p><p>Group 4 || 500 MB</p><p>The database generates approximately 500 MB redo every few minutes.</p><p>Initially:</p><p>Group || Status</p><p>CURRENT || INACTIVE</p><p>INACTIVE || ACTIVE</p><p>LGWR fills Group 1.</p><p>Oracle evaluates Group 2.</p><p>Group 2 is INACTIVE.</p><p>Switch succeeds immediately.</p><p>Now:</p><p>Group || Status</p><p>ACTIVE || CURRENT</p><p>INACTIVE || ACTIVE</p><p>Later Group 2 fills.</p><p>Oracle moves toward Group 3.</p><p>Again successful.</p><p>Eventually Oracle reaches Group 4.</p><p>If Group 4 is still ACTIVE because DBWR hasn’t completed checkpoint processing, the switch pauses.</p><p>Applications begin waiting.</p><p>Alert log may show:</p><p>Thread 1 cannot allocate new log<br>Checkpoint not complete</p><p>This doesn’t mean the redo logs are corrupted.</p><p>It means Oracle has reached the next group in sequence but cannot reuse it yet because recovery still depends on it. Oracle documents this relationship between redo reuse, checkpoint progress, and log switch waits.</p><p>Hangs sessions?<br>How ARCHIVELOG changes the algorithm</p><p>Without ARCHIVELOG:</p><p>G1 → G2 → G3 → reuse G1</p><p>Once recovery no longer needs G1, Oracle can overwrite it.</p><p>With ARCHIVELOG:</p><p>G1 fills<br> ↓<br>ARCn archives G1<br> ↓<br>G1 becomes eligible for reuse</p><p>The archive operation becomes an additional requirement.</p><p>So reuse requires two things conceptually:</p><p>Oracle’s documentation states that in ARCHIVELOG mode a filled redo log must be archived before it can be reused, while recovery status also determines whether the group is available. <br>Oracle Docs</p><p>SQL queries every DBA should know<br>Check redo log status</p><p>SELECT<br> GROUP#,<br> THREAD#,<br> SEQUENCE#,<br> BYTES/1024/1024 AS SIZE_MB,<br> MEMBERS,<br> STATUS,<br> ARCHIVED<br>FROM V$LOG<br>ORDER BY GROUP#;</p><p>Interpretation:</p><p>CURRENT → LGWR is writing.</p><p>ACTIVE → Still required for recovery.</p><p>INACTIVE → Candidate for reuse.</p><p>ARCHIVED → Archive completed.</p><p>Oracle exposes redo group state through V$LOG, which is the primary dynamic performance view used to inspect group status and sequence information.</p><p>Check redo members<br>SELECT<br> GROUP#,<br> MEMBER<br>FROM V$LOGFILE<br>ORDER BY GROUP#;</p><p>This helps verify multiplexed redo members.</p><p>Example:</p><p>Group</p><p>/redo1a.log</p><p>/redo1b.log</p><p>2</p><p>/redo2a.log</p><p>/redo2b.log</p><p>Remember:</p><p>Oracle switches groups, not members.</p><p>Check log switch history<br><strong>SELECT<br> THREAD#,<br> SEQUENCE#,<br> FIRST_TIME,<br> NEXT_TIME<br>FROM V$LOG_HISTORY<br>ORDER BY SEQUENCE# DESC;</strong></p><p>This query is extremely useful when investigating:</p><p>Frequent log switches</p><p>GoldenGate lag timing</p><p>Batch workload</p><p>Archive generation</p><p>Force a switch<br>ALTER SYSTEM SWITCH LOGFILE;</p><p>Useful during:</p><p>Backup preparation, Archive generation, Redo maintenance, Testing</p><p>Oracle documents forced log switching as a supported administrative operation. <br>Troubleshooting frequent log switches Frequent switches aren’t automatically a problem. The question is whether they’re causing waits.</p><p>Alert log:</p><p>Thread 1 advanced to log sequence 12891<br>Thread 1 advanced to log sequence 12892<br>Thread 1 advanced to log sequence 12893</p><p>This alone is normal.</p><p>Alert log:</p><p>Redo logs too small</p><p>DBWR unable to flush dirty buffers quickly</p><p>Slow storage</p><p>Heavy write workload</p><p>Insufficient checkpoint progress</p><p>Oracle’s performance guidance emphasizes investigating checkpoint progress rather than assuming LGWR itself is the root cause. <br>tanelpoder.com</p><p>Alert log:</p><p>Cannot allocate new log<br>Archiving needed</p><p>Investigate:</p><p>Archive destination full</p><p>ARCn processes</p><p>Archive I/O</p><p>FRA space</p><p>Network destination if remote archiving</p><p>Oracle specifically identifies archive destination capacity and archiver throughput as common causes of the archiving needed wait.</p><p>Q1. Which algorithm does Oracle use for redo log switching?</p><p>Answer: Oracle uses a sequential circular reuse mechanism for online redo log groups. It advances through groups in redo thread order, but reuse depends on whether the next group is eligible for reuse based on recovery and archive requirements. <br>Oracle Docs</p><p>Q2. What triggers a redo log switch?</p><p>Answer: Three common triggers:</p><p>Current redo log becomes full.</p><p>DBA executes ALTER SYSTEM SWITCH LOGFILE.</p><p>ARCHIVE_LAG_TARGET forces a time-based switch. <br>Oracle Docs</p><p>Q3. Does checkpoint cause log switch?</p><p>Answer: No, A log switch initiates checkpoint activity, but checkpoints can occur independently without causing a redo log switch.</p><p>Q4. Difference between ACTIVE and CURRENT?</p><p>Answer: CURRENT → LGWR is currently writing redo.</p><p>ACTIVE → Not currently being written, but still needed for crash recovery.</p><p>INACTIVE → No longer needed for instance recovery and generally available for reuse, subject to ARCHIVELOG requirements. <br>Oracle Docs</p><p>Q5. Why does checkpoint incomplete occur?</p><p>Answer: Because Oracle reaches the next redo group in sequence, but that group is still required for recovery since checkpoint processing has not advanced enough to make it reusable. LGWR waits for checkpoint completion before the switch can proceed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f495f45e80ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>