{"id":4219,"date":"2025-06-15T09:37:05","date_gmt":"2025-06-15T09:37:05","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4219"},"modified":"2026-09-26T13:08:08","modified_gmt":"2026-09-26T07:38:08","slug":"opening-a-physical-standby-database","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/opening-a-physical-standby-database\/","title":{"rendered":"Opening a Physical Standby Database"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. Real-time Query<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What is Real-time Query?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-time Query<\/strong> allows you to <strong>run read-only queries<\/strong> on a <strong>physical standby database<\/strong> <strong>while redo apply is running in the background<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This means your standby can <strong>serve reporting and analytics workloads<\/strong> in <strong>real-time<\/strong>, offloading the primary database and maximizing resource usage.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83c\udff7\ufe0f This feature is available <strong>only with Oracle Active Data Guard (licensed)<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Why Use Real-time Query?<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Benefit<\/th><th>Explanation<\/th><\/tr><\/thead><tbody><tr><td>\u2705 Reporting on standby<\/td><td>Run reports without affecting primary DB<\/td><\/tr><tr><td>\u2705 Real-time data access<\/td><td>Queries see changes as redo is applied<\/td><\/tr><tr><td>\u2705 High availability<\/td><td>Offload workload and still be disaster-ready<\/td><\/tr><tr><td>\u2705 RAC support<\/td><td>Can use Oracle RAC on the standby too<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Requirements Before You Start<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Requirement<\/th><th>Detail<\/th><\/tr><\/thead><tbody><tr><td>Oracle Edition<\/td><td>Enterprise Edition with Active Data Guard license<\/td><\/tr><tr><td>Compatible Parameter<\/td><td>Must be <code>11.0.0<\/code> or higher<\/td><\/tr><tr><td>Role<\/td><td>Physical standby only (not logical)<\/td><\/tr><tr><td>Redo Transport<\/td><td><strong>SYNC<\/strong> mode recommended for accuracy<\/td><\/tr><tr><td>Archive Log<\/td><td>Database must be in <code>ARCHIVELOG<\/code> mode<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Enable Real-time Query<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s how you can enable real-time query on a physical standby:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step-by-step Guide<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- 1. Cancel managed recovery (stop redo apply)\nALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;\n\n-- 2. Open standby database in read-only mode\nALTER DATABASE OPEN;\n\n-- 3. Restart redo apply in background (real-time apply)\nALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;<\/code><\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Now your standby is <strong>open for read-only access<\/strong> and <strong>applying redo<\/strong> at the same time \u2014 this is called <strong>\u201cReal-time Query mode\u201d<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">How to Check if It\u2019s Working<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT open_mode FROM V$DATABASE;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected Result:<\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>OPEN_MODE<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>READ ONLY WITH APPLY<\/td><td>Standby is open and applying redo<\/td><\/tr><tr><td>READ ONLY<\/td><td>Open, but not applying redo<\/td><\/tr><tr><td>MOUNTED<\/td><td>Not open for queries<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Monitor Apply Lag (How behind is the standby?)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT name, value, datum_time, time_computed \nFROM V$DATAGUARD_STATS \nWHERE name = 'apply lag';<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This tells you <strong>how much delay<\/strong> exists between the primary and standby.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Control Query Freshness with STANDBY_MAX_DATA_DELAY<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, Oracle lets you query even if the standby is slightly behind. But you can <strong>control how &#8220;fresh&#8221; the data must be<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Value<\/th><th>Effect<\/th><\/tr><\/thead><tbody><tr><td><code>NONE<\/code> (default)<\/td><td>No delay check \u2014 show whatever is there<\/td><\/tr><tr><td><code>0<\/code><\/td><td>Query only if standby is 100% up-to-date<\/td><\/tr><tr><td><code>n<\/code> (in seconds)<\/td><td>Allow queries if lag is under <code>n<\/code> seconds<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\ud83d\udd27 Example:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SESSION SET STANDBY_MAX_DATA_DELAY = 3;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This tells Oracle: &#8220;Let me run the query only if the data is <strong>at most 3 seconds old<\/strong>.&#8221;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f If not satisfied, Oracle throws: <code>ORA-03172: standby data not consistent<\/code><\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Want to Wait Until Standby Catches Up?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can force the session to <strong>wait until standby is caught up<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SESSION SYNC WITH PRIMARY;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is useful if you&#8217;re okay to <strong>wait a bit<\/strong> and want <strong>guaranteed consistency<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also <strong>automate this with a trigger<\/strong>, like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TRIGGER adg_logon_sync_trigger\nAFTER LOGON ON SCHEMA\nBEGIN\n  IF SYS_CONTEXT('USERENV','DATABASE_ROLE') = 'PHYSICAL STANDBY' THEN\n    EXECUTE IMMEDIATE 'ALTER SESSION SYNC WITH PRIMARY';\n  END IF;\nEND;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">What if Data Block is Corrupted?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Real-time query supports <strong>automatic block media recovery<\/strong>. If a block is corrupted, Oracle <strong>fetches a good copy from the primary<\/strong> automatically.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Manual Recovery (if needed):<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>RECOVER BLOCK FOR FILE 5 BLOCK 1234;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Real-time Query: Important Notes<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Note<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>Real-time apply must be running<\/td><td>Otherwise queries won\u2019t see latest data<\/td><\/tr><tr><td>SYNC is better<\/td><td>For best accuracy and consistency<\/td><\/tr><tr><td>Only physical standby supported<\/td><td>Logical standby doesn\u2019t support real-time apply<\/td><\/tr><tr><td>Requires Active Data Guard<\/td><td>Needs additional license<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Summary<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Real-time Query<\/th><\/tr><\/thead><tbody><tr><td>Allows read-only queries on standby<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Redo Apply continues in background<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Data freshness control<\/td><td>\u2705 With <code>STANDBY_MAX_DATA_DELAY<\/code><\/td><\/tr><tr><td>Auto block repair<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Licensing required<\/td><td>\u2705 Active Data Guard<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. Using SQL and PL\/SQL on Active Data Guard Standbys<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What\u2019s New in 19c?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Starting with <strong>Oracle 19c<\/strong>, Active Data Guard now allows <strong>SQL and PL\/SQL operations<\/strong> on physical standby databases \u2014 including <strong>DML<\/strong> and <strong>top-level PL\/SQL blocks<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This means you can now:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Perform occasional <strong>inserts, updates, and deletes<\/strong><\/li>\n\n\n\n<li>Run <strong>PL\/SQL procedures\/functions<\/strong><\/li>\n\n\n\n<li>Automatically <strong>recompile invalid PL\/SQL objects<\/strong><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f But remember \u2014 these operations are <strong>redirected to the primary<\/strong>, not executed on the standby itself.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d Why Allow DML &amp; PL\/SQL on a Standby?<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Advantage<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\u2705 Read-mostly apps supported<\/td><td>Ideal for apps that mostly read but occasionally write<\/td><\/tr><tr><td>\u2705 Query + small write support<\/td><td>You don\u2019t need to switch over to primary<\/td><\/tr><tr><td>\u2705 Simplifies development<\/td><td>Developers can work on the standby with fewer restrictions<\/td><\/tr><tr><td>\u2705 Automatic redirection<\/td><td>Oracle forwards changes to the primary for you<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">DML Operations on Active Data Guard Standby<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How Does It Work?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>DML (e.g. <code>INSERT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>) is <strong>automatically forwarded<\/strong> to the <strong>primary database<\/strong><\/li>\n\n\n\n<li>The standby <strong>waits<\/strong> for the change to be applied<\/li>\n\n\n\n<li><strong>Read consistency is maintained<\/strong> (you can see your own uncommitted changes)<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">This is useful for <strong>interactive dashboards<\/strong>, minor edits, or mixed workloads.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Setup: Enable DML Redirection<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Level<\/th><th>Method<\/th><\/tr><\/thead><tbody><tr><td>System-level (global)<\/td><td><code>ALTER SYSTEM SET ADG_REDIRECT_DML = TRUE;<\/code> <em>(requires restart)<\/em><\/td><\/tr><tr><td>Session-level (preferred for testing)<\/td><td><code>ALTER SESSION ENABLE ADG_REDIRECT_DML;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- On the standby\nALTER SESSION ENABLE ADG_REDIRECT_DML;\n\n-- Run a DML\nINSERT INTO employees VALUES (201, 'John', 'Doe', 5000);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 This DML is <strong>sent to primary<\/strong>, executed there, and the result is shipped back.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Until committed on the primary, <strong>only this session<\/strong> sees the change. Other sessions on standby will see it <strong>after commit<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">DML: Best Practices &amp; Warnings<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Point<\/th><th>Detail<\/th><\/tr><\/thead><tbody><tr><td>\u274c Avoid heavy DMLs<\/td><td>Too many writes on standby = overhead on primary<\/td><\/tr><tr><td>\ud83d\udeab No XA transactions<\/td><td>Distributed transactions (XA) are not supported<\/td><\/tr><tr><td>\ud83d\udd04 Use session-level config for safety<\/td><td>Avoid making it default unless needed<\/td><\/tr><tr><td>\u2705 Great for small, low-impact writes<\/td><td>Think: logging, bookmarks, temp notes, etc.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">PL\/SQL Execution on Standby<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can now run <strong>top-level PL\/SQL blocks<\/strong> (procedures\/functions) on Active Data Guard standby.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These too are <strong>automatically redirected<\/strong> to the <strong>primary<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udca1 \u201cTop-level\u201d means: directly run blocks \u2014 not anonymous PL\/SQL inside SQL tools.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Enabling PL\/SQL Redirection<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SESSION ENABLE ADG_REDIRECT_PLSQL;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 Only works at the <strong>session level<\/strong><br>\ud83d\udd39 Only for <strong>top-level calls<\/strong> (not dynamic SQL or bind variables)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PL\/SQL Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Assume this procedure exists on both primary &amp; standby\nCREATE OR REPLACE PROCEDURE update_sal (\n  emp_id IN NUMBER,\n  sal IN NUMBER\n) AS\nBEGIN\n  UPDATE employees SET salary = sal WHERE employee_id = emp_id;\nEND;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Use it on the standby:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SESSION ENABLE ADG_REDIRECT_DML;  -- Required if PL\/SQL uses DML\nALTER SESSION ENABLE ADG_REDIRECT_PLSQL;\n\nEXEC update_sal(105, 6000);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Oracle will redirect the call to the primary, execute it, and return the result.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automatic Recompilation of Invalid PL\/SQL Objects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If a <strong>PL\/SQL object becomes invalid<\/strong> (e.g., because of a table change), Oracle can <strong>recompile it automatically<\/strong> on the primary \u2014 <strong>even from the standby<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How It Works<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The PL\/SQL is invalid<\/li>\n\n\n\n<li>You attempt to use it on standby<\/li>\n\n\n\n<li>Oracle <strong>redirects the recompilation to the primary<\/strong><\/li>\n\n\n\n<li>When done, it ships back the valid object<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Requirement<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Must be enabled to allow this:\nALTER SYSTEM SET ADG_REDIRECT_DML = TRUE;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Recompilation Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose the <code>update_sal<\/code> procedure becomes invalid due to a table change:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Table altered on primary:\nALTER TABLE employees ADD COLUMN department_id NUMBER;\n\n-- On standby\nALTER SESSION ENABLE ADG_REDIRECT_DML;\nEXEC update_sal(105, 6000);  -- Automatically recompiles on primary, then executes<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle detects the invalid PL\/SQL, <strong>redirects the DDL<\/strong>, recompiles, and then executes your call.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Supported<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>DML Redirection<\/td><td>\u2705<\/td><td>Auto-forwards to primary<\/td><\/tr><tr><td>PL\/SQL Redirection<\/td><td>\u2705<\/td><td>Top-level only, no binds<\/td><\/tr><tr><td>Automatic PL\/SQL Recompilation<\/td><td>\u2705<\/td><td>Triggered on first use<\/td><\/tr><tr><td>XA Transactions<\/td><td>\u274c<\/td><td>Not supported<\/td><\/tr><tr><td>Mass Writes<\/td><td>\ud83d\udeab Not Recommended<\/td><td>Use for small, occasional writes<\/td><\/tr><tr><td>Licensing<\/td><td>\u2714\ufe0f Requires Active Data Guard<\/td><td>Oracle EE + license<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. Using Temporary Tables on Active Data Guard Instances<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What Are Temporary Tables?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Temporary tables<\/strong> are special tables used to hold session-specific or transaction-specific data. Data in these tables is:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Private to your session<\/strong><\/li>\n\n\n\n<li><strong>Automatically deleted<\/strong> after a session or transaction ends<\/li>\n\n\n\n<li><strong>Not written to disk permanently<\/strong><\/li>\n\n\n\n<li>Perfect for <strong>reporting<\/strong>, <strong>intermediate calculations<\/strong>, or <strong>scratch work<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd04 Types of Temporary Tables<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Type<\/th><th>Description<\/th><th>Lifetime<\/th><th>Where Stored<\/th><\/tr><\/thead><tbody><tr><td><strong>Global Temporary Tables (GTTs)<\/strong><\/td><td>Metadata is stored in the data dictionary; rows are session- or transaction-specific<\/td><td>Session or transaction<\/td><td>Disk + memory<\/td><\/tr><tr><td><strong>Private Temporary Tables (PTTs)<\/strong><\/td><td>Metadata &amp; data stored <strong>in memory only<\/strong><\/td><td>Session<\/td><td>Memory only<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Can We Use These on Active Data Guard (ADG)?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Yes! Starting with Oracle 12c and enhanced in 19c+, you can create and use:<\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Table Type<\/th><th>Supported on ADG?<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>Global Temporary Tables<\/td><td>\u2705<\/td><td>Full DML &amp; DDL supported<\/td><\/tr><tr><td>Private Temporary Tables<\/td><td>\u2705<\/td><td>Metadata stored in memory; safe on read-only standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Global Temporary Tables (GTT) on ADG<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">DML on GTT: How It Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Even though ADG is <strong>read-only<\/strong>, Oracle allows DML on GTTs because it uses a feature called <strong>Temporary Undo<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udccc Key Concept: Temporary Undo<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>What is it?<\/td><td>Stores undo for temporary tables in the <strong>temp tablespace<\/strong>, not undo tablespace<\/td><\/tr><tr><td>Why allowed?<\/td><td><strong>Doesn&#8217;t generate redo<\/strong> \u2192 safe on standby<\/td><\/tr><tr><td>Where is it always enabled?<\/td><td>Always ON in <strong>ADG standby<\/strong><\/td><\/tr><tr><td>How to enable on Primary?<\/td><td>Set <code>TEMP_UNDO_ENABLED = TRUE<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2705 This reduces <strong>redo traffic<\/strong> and improves performance for both primary and standby.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Example: DML on Global Temporary Table<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- On the ADG standby\nCREATE GLOBAL TEMPORARY TABLE temp_sales (\n   id NUMBER, \n   amount NUMBER\n) ON COMMIT PRESERVE ROWS;\n\n-- Insert data (allowed!)\nINSERT INTO temp_sales VALUES (1, 1000);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Works perfectly! Data is <strong>session-specific<\/strong> and no redo is generated.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Benefits of Temporary Undo on ADG<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Benefit<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\u2705 Less redo on primary<\/td><td>Because temporary undo isn\u2019t logged in redo<\/td><\/tr><tr><td>\u2705 Less network usage<\/td><td>Less redo to ship to standby<\/td><\/tr><tr><td>\u2705 Supports reporting apps<\/td><td>Useful for BI tools or temporary staging logic<\/td><\/tr><tr><td>\u2705 Fast scratch space<\/td><td>Without permanent writes to disk<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Restrictions on GTT in ADG<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Limitation<\/th><th>Explanation<\/th><\/tr><\/thead><tbody><tr><td>\ud83d\udd12 <code>COMPATIBLE &gt;= 12.0.0<\/code> required<\/td><td>For temporary undo feature<\/td><\/tr><tr><td>\ud83d\udeab No temp BLOBs\/CLOBs<\/td><td>Unsupported<\/td><\/tr><tr><td>\ud83d\udeab No distributed transactions with GTT<\/td><td>Can\u2019t modify GTT and remote DB in same transaction<\/td><\/tr><tr><td>\u26a0\ufe0f <code>EXPLAIN PLAN<\/code> uses GTT internally<\/td><td>May conflict with remote DML in same session<\/td><\/tr><tr><td>\u274c TEMP_UNDO_ENABLED has no effect on standby<\/td><td>It\u2019s always ON automatically<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">DDL on GTTs: Create\/Drop<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can issue <strong>CREATE<\/strong> and <strong>DROP<\/strong> GTT statements from the ADG standby.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are <strong>redirected<\/strong> to the <strong>primary<\/strong>, executed there, and <strong>reflected back<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udd01 Managed recovery must be in <strong>real-time apply mode<\/strong> and standby must be <strong>in sync<\/strong>.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Create GTT on ADG<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- On standby, create table\nCREATE GLOBAL TEMPORARY TABLE temp_orders (\n   order_id NUMBER, \n   region VARCHAR2(20)\n) ON COMMIT PRESERVE ROWS;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Oracle transparently redirects this DDL to the primary, executes it, and reflects the change to the standby.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd12 Note on DDL Redirection<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Condition<\/th><th>Requirement<\/th><\/tr><\/thead><tbody><tr><td>\ud83d\udfe2 Standby apply must be running<\/td><td>With <strong>real-time apply<\/strong> enabled<\/td><\/tr><tr><td>\ud83d\udfe2 Standby must be <strong>synced<\/strong> with primary<\/td><td>No large lag<\/td><\/tr><tr><td>\ud83d\udee0\ufe0f Still can do DDL from primary<\/td><td>ADG standby sees it when caught up<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Private Temporary Tables (PTT) on ADG<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What Makes PTTs Special?<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\u2705 Fully in-memory<\/td><td>No disk metadata \u2192 OK on read-only DB<\/td><\/tr><tr><td>\ud83d\udd12 Session-bound<\/td><td>Auto-dropped when session ends<\/td><\/tr><tr><td>\ud83d\udd27 Lightweight<\/td><td>Ideal for quick calculations or filtering<\/td><\/tr><tr><td>\ud83c\udd95 Introduced in<\/td><td>Oracle 18c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Create PTT on ADG<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- On ADG standby\nCREATE PRIVATE TEMPORARY TABLE ora$ptt_sales (\n   product_id NUMBER,\n   amount NUMBER\n);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 No redo, no disk writes \u2014 safe and fast on ADG.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2757Table names must start with <code>ORA$PTT_<\/code> or <code>ORA$<\/code> by default<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Feature Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>GTT<\/th><th>PTT<\/th><\/tr><\/thead><tbody><tr><td>Allowed on ADG?<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Undo generates redo?<\/td><td>\u274c No (stored in temp tablespace)<\/td><td>\u274c No (in-memory)<\/td><\/tr><tr><td>Metadata stored?<\/td><td>\u2705 On disk<\/td><td>\u274c In memory only<\/td><\/tr><tr><td>Supports DML?<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Auto dropped?<\/td><td>\u274c No (must drop manually)<\/td><td>\u2705 Yes (end of session)<\/td><\/tr><tr><td>Requires TEMP_UNDO_ENABLED?<\/td><td>\u2705 (on primary)<\/td><td>\u274c Not needed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcccSummary: Best Practices<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Task<\/th><th>Recommendation<\/th><\/tr><\/thead><tbody><tr><td>Use GTTs for heavy reporting apps<\/td><td>\u2705 Ideal for session temp staging<\/td><\/tr><tr><td>Prefer PTTs for one-off analytics or filters<\/td><td>\u2705 Very fast &amp; in-memory<\/td><\/tr><tr><td>Always keep standby in sync<\/td><td>\u2705 Required for DDL redirection<\/td><\/tr><tr><td>Avoid BLOB\/CLOB in GTTs<\/td><td>\u274c Not supported<\/td><\/tr><tr><td>Avoid distributed transactions + GTT<\/td><td>\u26a0\ufe0f Causes errors<\/td><\/tr><tr><td>Use real-time apply mode<\/td><td>\u2705 Required for DDL visibility on standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. IM Column Store in an Active Data Guard Environment<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What Is the IM Column Store?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>In-Memory Column Store (IM column store)<\/strong> is a feature that stores table data in a <strong>compressed columnar format in memory<\/strong>, enabling super-fast analytical queries and reporting by scanning only the relevant columns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Starting with <strong>Oracle 12c Release 2 (12.2.0.1)<\/strong>, Oracle supports the <strong>IM column store<\/strong> on <strong>Active Data Guard (ADG) standby databases<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use IM Column Store on ADG?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using the IM column store on a standby database has several key benefits:<\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Benefit<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\ud83d\udd04 Offload Analytics<\/td><td>Run reporting workloads directly on the standby, reducing load on the primary<\/td><\/tr><tr><td>\u26a1 Faster Query Performance<\/td><td>Columnar format allows fast scans, filters, and aggregations<\/td><\/tr><tr><td>\ud83d\udce6 Double Memory Utilization<\/td><td>You can populate <strong>different data sets<\/strong> in the primary and standby IM stores, effectively doubling IM memory usage across both<\/td><\/tr><tr><td>\ud83d\udcbe Reduced I\/O<\/td><td>Since data is in memory, disk access is minimized<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration Steps<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Step<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>1\ufe0f\u20e3 Ensure version is 12.2.0.1 or above<\/td><td>IM support on ADG begins from this version<\/td><\/tr><tr><td>2\ufe0f\u20e3 Configure memory for IM column store<\/td><td>Use <code>INMEMORY_SIZE<\/code> parameter on both primary and standby<\/td><\/tr><tr><td>3\ufe0f\u20e3 On standby, set parameter for MIRA support<\/td><td><code>ENABLE_IMC_WITH_MIRA = TRUE<\/code> if using multi-instance redo apply (RAC)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Example Configuration (Simplified)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- On standby database\nALTER SYSTEM SET INMEMORY_SIZE = 2G SCOPE=SPFILE;\nALTER SYSTEM SET ENABLE_IMC_WITH_MIRA = TRUE SCOPE=BOTH;\n\n-- Restart the standby instance to activate IM column store<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Practical Benefits in an ADG Setup<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Scenario<\/th><th>Value<\/th><\/tr><\/thead><tbody><tr><td>\ud83e\uddfe Heavy BI reporting on standby<\/td><td>Leverages in-memory scanning speed<\/td><\/tr><tr><td>\ud83d\udcca Different IM population on standby<\/td><td>Run standby-specific analytics<\/td><\/tr><tr><td>\ud83e\udde0 Free up primary memory<\/td><td>Offload less-used datasets to standby&#8217;s IM store<\/td><\/tr><tr><td>\ud83e\uddea Test new in-memory strategies<\/td><td>Use standby as a low-risk experimentation ground<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Limitations to Be Aware Of<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Limitation<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\ud83d\udeab In-Memory Expressions<\/td><td>Only learned from <strong>queries run on primary<\/strong><\/td><\/tr><tr><td>\ud83d\udeab In-Memory ILM policies<\/td><td>Triggered <strong>only by primary activity<\/strong><\/td><\/tr><tr><td>\ud83d\udeab In-Memory FastStart<\/td><td>\u274c Not supported on standby<\/td><\/tr><tr><td>\ud83d\udeab In-Memory Join Groups<\/td><td>\u274c Not supported on standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Supported on ADG Standby?<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>IM Column Store<\/td><td>\u2705 Yes<\/td><td>From Oracle 12.2 onwards<\/td><\/tr><tr><td>Different IM contents per DB<\/td><td>\u2705 Yes<\/td><td>Great for load balancing<\/td><\/tr><tr><td>In-Memory Expressions<\/td><td>\u274c No<\/td><td>Only primary learns expressions<\/td><\/tr><tr><td>ILM policies<\/td><td>\u274c No<\/td><td>Only primary tracks access<\/td><\/tr><tr><td>In-Memory FastStart<\/td><td>\u274c No<\/td><td>Not supported<\/td><\/tr><tr><td>In-Memory Join Groups<\/td><td>\u274c No<\/td><td>Not supported<\/td><\/tr><tr><td>MIRA (Multi-Instance Redo Apply) support<\/td><td>\u2705 Yes<\/td><td>Set <code>ENABLE_IMC_WITH_MIRA = TRUE<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Best Practices<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Task<\/th><th>Recommendation<\/th><\/tr><\/thead><tbody><tr><td>Enable IM column store on standby<\/td><td>\u2705 For high-speed analytics<\/td><\/tr><tr><td>Use different IM contents<\/td><td>\u2705 To maximize memory usage<\/td><\/tr><tr><td>Monitor ADG lag<\/td><td>\u2705 To ensure real-time reporting accuracy<\/td><\/tr><tr><td>Avoid relying on ILM or Join Groups<\/td><td>\u274c These are not supported on standby<\/td><\/tr><tr><td>Use for read-mostly, reporting, and BI<\/td><td>\u2705 Ideal workload on ADG standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. In-Memory External Tables in an Active Data Guard Environment<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What Are In-Memory External Tables?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>In-Memory External Tables<\/strong> combine the <strong>speed of Oracle In-Memory (IM) column store<\/strong> with the <strong>flexibility of external tables<\/strong> (tables that reference data outside the database\u2014e.g., flat files on disk). They allow high-speed analytics on <strong>external data<\/strong> as if it&#8217;s part of the database, using in-memory columnar format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With <strong>Active Data Guard<\/strong>, this feature is now available <strong>on standby databases<\/strong> as well\u2014great for <strong>offloading analytics<\/strong> from primary!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits in ADG Environment<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Benefit<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\ud83d\udd04 Query Offloading<\/td><td>Run external table queries on standby instead of primary<\/td><\/tr><tr><td>\u26a1 Parallel Load &amp; Query<\/td><td>External data is loaded <strong>in parallel<\/strong> into IM column store for fast querying<\/td><\/tr><tr><td>\ud83e\udde0 Columnar Analytics<\/td><td>Uses compressed column format for fast filtering, scans, and joins<\/td><\/tr><tr><td>\ud83d\udcbd Less Disk I\/O<\/td><td>Queries are satisfied from memory rather than disk reads<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Key Behavior &amp; Configuration Notes<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\u2705 Supported in ADG<\/td><td>In-memory external tables can be queried on the standby<\/td><\/tr><tr><td>\u2699\ufe0f Parallel Query<\/td><td>External table segments are loaded <strong>in parallel<\/strong> on both primary and standby<\/td><\/tr><tr><td>\ud83d\udd01 IM Segment Behavior<\/td><td>Using <code>INMEMORY<\/code> or <code>NO INMEMORY<\/code> can release or control IM segment usage on standby<\/td><\/tr><tr><td>\u274c FOR SERVICE Subclause Not Supported<\/td><td>The <code>FOR SERVICE<\/code> clause in <code>INMEMORY ... DISTRIBUTE<\/code> is <strong>not supported<\/strong> on primary or standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">How It Works (High-Level Flow)<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Step<\/th><th>Action<\/th><\/tr><\/thead><tbody><tr><td>1\ufe0f\u20e3<\/td><td>Define an external table and enable <code>INMEMORY<\/code><\/td><\/tr><tr><td>2\ufe0f\u20e3<\/td><td>External table is loaded into <strong>IM column store<\/strong> in parallel<\/td><\/tr><tr><td>3\ufe0f\u20e3<\/td><td>Queries on standby use this <strong>in-memory external data<\/strong>, accelerating performance<\/td><\/tr><tr><td>4\ufe0f\u20e3<\/td><td>You can manage memory use with <code>NO INMEMORY<\/code> or similar directives<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Example Syntax (Simplified)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE ext_sales (\n  sale_id    NUMBER,\n  sale_date  DATE,\n  amount     NUMBER\n)\nORGANIZATION EXTERNAL\n(\n  TYPE ORACLE_LOADER\n  DEFAULT DIRECTORY ext_data_dir\n  ACCESS PARAMETERS (\n    RECORDS DELIMITED BY NEWLINE\n    FIELDS TERMINATED BY ','\n    MISSING FIELD VALUES ARE NULL\n    (\n      sale_id, sale_date DATE \"YYYY-MM-DD\", amount\n    )\n  )\n  LOCATION ('sales_data.csv')\n)\nINMEMORY;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will load <code>sales_data.csv<\/code> into <strong>IM column store<\/strong>, and the same table can be queried <strong>on the standby database<\/strong> with excellent performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Important Limitations<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Limitation<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>\u274c <code>FOR SERVICE<\/code> clause not supported<\/td><td>You cannot use <code>FOR SERVICE<\/code> with <code>INMEMORY ... DISTRIBUTE<\/code> in primary or standby<\/td><\/tr><tr><td>\ud83d\udd01 Segment control<\/td><td>Using <code>NO INMEMORY<\/code> will <strong>unload<\/strong> the IM external table segment from memory<\/td><\/tr><tr><td>\ud83d\uddc3\ufe0f External table limitations still apply<\/td><td>Read-only, limited DML, metadata must be accessible to standby if needed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature<\/th><th>Supported on Standby?<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>In-Memory External Tables<\/td><td>\u2705 Yes<\/td><td>Loaded and queried in parallel<\/td><\/tr><tr><td>Parallel Query<\/td><td>\u2705 Yes<\/td><td>Fully supported<\/td><\/tr><tr><td>INMEMORY clause<\/td><td>\u2705 Yes<\/td><td>Supported with normal usage<\/td><\/tr><tr><td>NO INMEMORY clause<\/td><td>\u2705 Yes<\/td><td>Unloads segment from memory<\/td><\/tr><tr><td>FOR SERVICE clause<\/td><td>\u274c No<\/td><td>Not supported on either primary or standby<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Task<\/th><th>Recommendation<\/th><\/tr><\/thead><tbody><tr><td>Use IM external tables for reporting<\/td><td>\u2705 Offload heavy file-based analytics to standby<\/td><\/tr><tr><td>Manage memory with NO INMEMORY when needed<\/td><td>\u2705 Helps control memory usage on standby<\/td><\/tr><tr><td>Avoid <code>FOR SERVICE<\/code> clause<\/td><td>\u274c Not supported in ADG setup<\/td><\/tr><tr><td>Use parallel queries on standby<\/td><td>\u2705 Takes full advantage of IM performance<\/td><\/tr><tr><td>Ensure external files are accessible if needed<\/td><td>\u2705 Especially if standby needs to reference them directly<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">6. Using Sequences in Oracle Active Data Guard<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle Active Data Guard supports <strong>global sequences<\/strong> (created with default <code>CACHE<\/code> and <code>NOORDER<\/code>) and <strong>session sequences<\/strong>. These sequences can be safely accessed on standby databases with proper caching and setup. This allows read-mostly standby databases to perform limited inserts or operations requiring unique IDs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 Global Sequences on Standby<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How They Work<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When a <strong>standby database<\/strong> accesses a <strong>global sequence<\/strong> for the first time, it <strong>requests a range<\/strong> of sequence numbers from the <strong>primary<\/strong>.<\/li>\n\n\n\n<li>The <strong>primary database<\/strong> allocates a non-overlapping range based on the <strong>CACHE size<\/strong>, and updates the dictionary.<\/li>\n\n\n\n<li>Standby consumes the assigned range. Once exhausted, it requests a new one.<\/li>\n\n\n\n<li>Ensures <strong>unique values across all standbys and the primary<\/strong>.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udca1 <strong>Supported only for sequences with <code>CACHE<\/code> and <code>NOORDER<\/code>.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Best Practices<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2757 <strong>Always specify <code>CACHE<\/code> with a high enough value<\/strong> to minimize frequent round-trips to the primary.<\/li>\n\n\n\n<li>\u2757 <code>ORDER<\/code> or <code>NOCACHE<\/code> sequences <strong>are not supported<\/strong> on standby.<\/li>\n\n\n\n<li>\u2705 Define <code>LOG_ARCHIVE_DEST_n<\/code> on terminal standby pointing back to the primary (needed for redo transport for metadata changes).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Multi-Standby Environment<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: On Primary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE GLOBAL TEMPORARY TABLE gtt (a INT);\n\nCREATE SEQUENCE g CACHE 10;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: On Standby 1<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>INSERT INTO gtt VALUES (g.NEXTVAL);\n-- 1\n\nINSERT INTO gtt VALUES (g.NEXTVAL);\n-- 2\n\nSELECT * FROM gtt;\n-- A = 1, 2 (standby 1 gets sequence 1\u201310)<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: On Primary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT g.NEXTVAL FROM dual;\n-- 11\nSELECT g.NEXTVAL FROM dual;\n-- 12 (primary gets 11\u201320)<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: On Standby 2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>INSERT INTO gtt VALUES (g.NEXTVAL);\n-- 21\nINSERT INTO gtt VALUES (g.NEXTVAL);\n-- 22\n\nSELECT * FROM gtt;\n-- A = 21, 22 (standby 2 gets 21\u201330)<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2\ufe0f\u20e3 Session Sequences on Standby<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What Are Session Sequences?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Special type of sequence: values are <strong>unique only within a session<\/strong>, not across sessions.<\/li>\n\n\n\n<li>Not persistent across sessions.<\/li>\n\n\n\n<li>Created on <strong>primary<\/strong> but can be accessed from <strong>read-only<\/strong> or <strong>read\/write<\/strong> databases (including standby).<\/li>\n\n\n\n<li>Useful with <strong>global temporary tables<\/strong> having session-level visibility.<\/li>\n\n\n\n<li>Ignores <code>CACHE<\/code>\/<code>NOCACHE<\/code> and <code>ORDER<\/code>\/<code>NOORDER<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Creating &amp; Altering Session Sequences<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u2705 Create a session sequence:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE SEQUENCE s SESSION;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert global to session:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SEQUENCE s SESSION;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert session to global:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER SEQUENCE s GLOBAL;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Using Session Sequences<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">On Primary<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE GLOBAL TEMPORARY TABLE gtt (a INT);\n\nCREATE SEQUENCE s SESSION;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">On Standby &#8211; Session 1<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>INSERT INTO gtt VALUES (s.NEXTVAL);\n-- 1\nINSERT INTO gtt VALUES (s.NEXTVAL);\n-- 2\n\nSELECT * FROM gtt;\n-- A = 1, 2<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">On Standby &#8211; Session 2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>INSERT INTO gtt VALUES (s.NEXTVAL);\n-- 1\nINSERT INTO gtt VALUES (s.NEXTVAL);\n-- 2\n\nSELECT * FROM gtt;\n-- A = 1, 2 (values are local to this session)<\/code><\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Result: Each session gets its <strong>own private range<\/strong> starting from 1.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Notes &amp; Restrictions<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Aspect<\/th><th>Global Sequence<\/th><th>Session Sequence<\/th><\/tr><\/thead><tbody><tr><td>Accessible on standby<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Unique across system<\/td><td>\u2705 Yes<\/td><td>\u274c Only within session<\/td><\/tr><tr><td>Persistence<\/td><td>\u2705 Yes<\/td><td>\u274c Session only<\/td><\/tr><tr><td>Supports CACHE\/ORDER<\/td><td>\u2705 Yes<\/td><td>\u274c Ignored<\/td><\/tr><tr><td>Defined on primary<\/td><td>\u2705 Yes<\/td><td>\u2705 Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>global sequences<\/strong> with <code>CACHE<\/code> (not <code>NOCACHE<\/code>) for consistent values across all databases.<\/li>\n\n\n\n<li>Use <strong>session sequences<\/strong> for lightweight, session-specific ID generation with temp tables.<\/li>\n\n\n\n<li>Be aware of <strong>round-trips<\/strong> from standby to primary when cache is exhausted.<\/li>\n\n\n\n<li>Monitor cache size and redo transport when using sequences on standby.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">7. Using the Result Cache on Physical Standby Databases<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In an <strong>Active Data Guard<\/strong> environment, <strong>query result caching<\/strong> can be enabled on <strong>physical standby databases<\/strong> to improve performance for repeated queries. This reduces computation time for queries that repeatedly access the same data, without impacting the performance of the standby.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Default Behavior<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>By default, <strong>query results are <em>not cached<\/em><\/strong> on a physical standby database.<\/li>\n\n\n\n<li>Enabling result caching must be done <strong>explicitly for each table<\/strong> involved in recurring queries.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How It Works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Oracle allows the <strong>result cache<\/strong> to store <strong>query results<\/strong> for <strong>enabled tables<\/strong> on physical standby databases.<\/li>\n\n\n\n<li>A query result will be cached <strong>only if all dependent tables<\/strong> used in the query are <strong>enabled<\/strong> for result cache using the clause: sqlCopyEdit<code>RESULT_CACHE (STANDBY ENABLE)<\/code><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\udd38 <strong>Views<\/strong> are <strong>not cached<\/strong>, even if their underlying tables are enabled.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc When Is Result Cache Used?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A query will utilize the standby result cache only if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It\u2019s run on a <strong>physical standby<\/strong> in <strong>Active Data Guard mode<\/strong>.<\/li>\n\n\n\n<li>All the <strong>tables involved<\/strong> in the query are enabled for result cache.<\/li>\n\n\n\n<li>The query is <strong>repeatable<\/strong> (i.e., returns the same result between redo apply intervals).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Enabling Result Cache on Standby Tables<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Modify Existing Table<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To enable result cache for an existing table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER TABLE employee RESULT_CACHE (STANDBY ENABLE);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. During Table Creation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To enable result cache while creating the table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE employee (\n  emp_id NUMBER,\n  ename VARCHAR2(50),\n  sal   NUMBER\n) RESULT_CACHE (STANDBY ENABLE);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You may also see this written as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>RESULT_CACHE (STABLE ENABLE);<\/code><\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><code>STABLE<\/code> tells Oracle the data does not change frequently and is safe to cache.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Important Notes<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Feature \/ Behavior<\/th><th>Details<\/th><\/tr><\/thead><tbody><tr><td>Applies to<\/td><td>Tables only<\/td><\/tr><tr><td>Views<\/td><td>\u274c Not supported (even if base tables are cached)<\/td><\/tr><tr><td>Multi-table queries<\/td><td>\u2705 Supported only if <em>all<\/em> involved tables are result-cache enabled<\/td><\/tr><tr><td>PDB Support<\/td><td>\u2705 Each PDB in a CDB has its own result cache<\/td><\/tr><tr><td>Query Hints<\/td><td>Same syntax and behavior as on the primary<\/td><\/tr><tr><td>Other <code>RESULT_CACHE<\/code> attributes<\/td><td>Work the same on standby as on primary<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2705 Enable result cache for <strong>tables used in frequent queries<\/strong> on the standby.<\/li>\n\n\n\n<li>\u2757 Ensure <em>all tables<\/em> in multi-table queries are <strong>enabled<\/strong> for standby cache.<\/li>\n\n\n\n<li>\u274c Don\u2019t rely on result cache for <strong>views<\/strong> or <strong>volatile data<\/strong>.<\/li>\n\n\n\n<li>\ud83d\udd04 Consider query patterns and use hints (e.g., <code>\/*+ RESULT_CACHE *\/<\/code>) if needed.<\/li>\n\n\n\n<li>\ud83d\udcca Monitor cache performance if using it extensively across multiple PDBs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Result caching on standby can significantly <strong>boost performance<\/strong> for repetitive read queries.<\/li>\n\n\n\n<li>You must <strong>explicitly enable<\/strong> this feature on <strong>each table<\/strong> using the <code>STANDBY ENABLE<\/code> clause.<\/li>\n\n\n\n<li>Only works for <strong>tables<\/strong>, not <strong>views<\/strong>, and requires <strong>Active Data Guard<\/strong>.<\/li>\n\n\n\n<li>Works <strong>per-PDB<\/strong> in container databases.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. Real-time Query What is Real-time Query? Real-time Query allows you to run read-only queries on a physical standby database while redo apply is running in the background. This means your standby can serve reporting and analytics workloads in real-time, offloading the primary database and maximizing resource usage. \ud83c\udff7\ufe0f This feature is available only with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[988,1225],"tags":[],"class_list":["post-4219","post","type-post","status-publish","format-standard","hentry","category-data-guard","category-database"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=4219"}],"version-history":[{"count":3,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4219\/revisions"}],"predecessor-version":[{"id":4223,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4219\/revisions\/4223"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=4219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}