{"id":5109,"date":"2021-06-02T08:29:50","date_gmt":"2021-06-02T08:29:50","guid":{"rendered":"https:\/\/swiv.com.br\/configuring-apply-lag-tolerance-in-an-active-data-guard-environment\/"},"modified":"2026-05-27T20:02:31","modified_gmt":"2026-05-27T19:02:31","slug":"configuring-apply-lag-tolerance-in-an-active-data-guard-environment","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/06\/02\/configuring-apply-lag-tolerance-in-an-active-data-guard-environment\/","title":{"rendered":"Configuring Apply Lag Tolerance in an Active Data Guard environment"},"content":{"rendered":"\n<p>Em ambientes que possuam a op\u00e7\u00e3o de Active Data Guard habilitada, temos um recurso importante para controle de toler\u00e2ncia de Lag (de apply log), materializado em um par\u00e2metro de sess\u00e3o chamado STANDBY_MAX_DATA_DELAY. Neste artigo, vamos explorar em termos pr\u00e1ticos esse item.<\/p>\n\n\n\n<p>Validando ambiente que ser\u00e1 utilizado para testes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;oracle@fornix1 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Tue Jun 1 06:14:22 2021\nVersion 19.3.0.0.0\n \nCopyright (c) 1982, 2019, Oracle.  All rights reserved.\n \n \nConnected to:\nOracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production\nVersion 19.3.0.0.0\n \nSQL&gt; SELECT NAME,OPEN_MODE,DATABASE_ROLE FROM V$DATABASE;\n \nNAME      OPEN_MODE            DATABASE_ROLE\n--------- -------------------- ----------------\nCORTEX    READ WRITE           PRIMARY\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;oracle@fornix2 trace]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Tue Jun 1 06:15:20 2021\nVersion 19.3.0.0.0\n \nCopyright (c) 1982, 2019, Oracle.  All rights reserved.\n \n \nConnected to:\nOracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production\nVersion 19.3.0.0.0\n \nSQL&gt; SELECT NAME,OPEN_MODE,DATABASE_ROLE FROM V$DATABASE;\n \nNAME      OPEN_MODE            DATABASE_ROLE\n--------- -------------------- ----------------\nCORTEX    READ ONLY WITH APPLY PHYSICAL STANDBY\n<\/pre><\/div>\n\n\n<p>Atrav\u00e9s do teste abaixo, no banco Standby, constatamos que este par\u00e2metro n\u00e3o \u00e9 habilitado para usu\u00e1rios administrativos:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SHOW USER;\nUSER is &quot;SYS&quot;\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=30;\nERROR:\nORA-03174: STANDBY_MAX_DATA_DELAY does not apply to SYS users\n<\/pre><\/div>\n\n\n<p>O par\u00e2metro em quest\u00e3o possui 3 valores poss\u00edveis, sendo que o seu valor padr\u00e3o \u00e9 NONE, que significa que a consulta ser\u00e1 exibida no Standby independente se h\u00e1 delay ou n\u00e3o em rela\u00e7\u00e3o ao Primary. Vamos realizar o teste abaixo, criando um tabela e populando-a no Primary:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT NAME,OPEN_MODE,DATABASE_ROLE FROM V$DATABASE;\n \nNAME      OPEN_MODE            DATABASE_ROLE\n--------- -------------------- ----------------\nCORTEX    READ WRITE           PRIMARY\n \nSQL&gt; CREATE TABLE SOE.TESTE1 (DESCRICAO VARCHAR2(20));\n \nTable created.\n \nSQL&gt; INSERT INTO SOE.TESTE1 (DESCRICAO) VALUES (&#039;ACTIVE DATA GUARD&#039;);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n<\/pre><\/div>\n\n\n<p>No standby, logado com um usu\u00e1rio n\u00e3o administrativo, vamos definir o valor do par\u00e2metro para NONE e consultar a tabela recentemente criada:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; SHOW USER;\nUSER is &quot;SOE&quot;\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=NONE;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\n<\/pre><\/div>\n\n\n<p>Por\u00e9m percebemos que n\u00e3o existe Lag no ambiente no momento:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn \/ as sysdba\nConnected.\nSQL&gt; SELECT value &quot;Lag&quot;, datum_time &quot;Received Time&quot;, Time_Computed &quot;Time Computed &quot; FROM V$DATAGUARD_STATS WHERE name like &#039;apply lag&#039;;\n \nLag\n----------------------------------------------------------------\nReceived Time                  Time Computed\n------------------------------ ------------------------------\n+00 00:00:00\n06\/01\/2021 06:24:32            06\/01\/2021 06:24:33\n<\/pre><\/div>\n\n\n<p>Vamos parar o processo de Redo Apply no Standby:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Inserindo mais um registro na tabela do Primary:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; INSERT INTO SOE.TESTE1 (DESCRICAO) VALUES (&#039;SEM REDO APPLY&#039;);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n<\/pre><\/div>\n\n\n<p>Realizando novamente  a consulta no Standby, percebemos que s\u00f3 1 registro \u00e9 exibido:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\n<\/pre><\/div>\n\n\n<p>Constatamos que com o valor NONE, as consultas no Standby continuar\u00e3o a funcionar, mesmo se houver LAG entre o primary e standby (e mesmo que isso signifique diferen\u00e7a de dados):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn \/ as sysdba\nConnected.\nSQL&gt; SELECT value &quot;Lag&quot;, datum_time &quot;Received Time&quot;, Time_Computed &quot;Time Computed &quot; FROM V$DATAGUARD_STATS WHERE name like &#039;apply lag&#039;;\n \nLag\n----------------------------------------------------------------\nReceived Time                  Time Computed\n------------------------------ ------------------------------\n+00 00:02:43\n06\/01\/2021 06:28:02            06\/01\/2021 06:28:03\n<\/pre><\/div>\n\n\n<p>Outra possibilidade de nosso par\u00e2metro seria um valor que representa a quantidade de segundos aceit\u00e1veis para o Lag. Para realizar este teste, vou habilitar novamente o Redo Apply, definir 180 segundos de Delay, e desligar o Redo Apply e acompanhar o desfecho:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;\n \nDatabase altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\nSEM REDO APPLY\n<\/pre><\/div>\n\n\n<p>Parando Redo Apply:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Definindo valor do par\u00e2metro em 180 segundos. Ou seja, conseguiremos consultar informa\u00e7\u00f5es que possuam at\u00e9 esse limite:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=180;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\nSEM REDO APPLY\n \nSQL&gt; conn \/ as sysdba\nConnected.\nSQL&gt; SELECT value &quot;Lag&quot;, datum_time &quot;Received Time&quot;, Time_Computed &quot;Time Computed &quot; FROM V$DATAGUARD_STATS WHERE name like &#039;apply lag&#039;;\n \nLag\n----------------------------------------------------------------\nReceived Time                  Time Computed\n------------------------------ ------------------------------\n+00 00:01:58\n06\/01\/2021 06:33:51            06\/01\/2021 06:33:53\n<\/pre><\/div>\n\n\n<p>Em paralelo vou criar o terceiro registro no Primary:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; INSERT INTO SOE.TESTE1 (DESCRICAO) VALUES (&#039;BSS&#039;);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n<\/pre><\/div>\n\n\n<p>No standby, como o Redo Apply est\u00e1 desligado, s\u00f3 conseguimos ver 2 registros (pois o Lag ainda n\u00e3o atingiu 180 segundos):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\nSEM REDO APPLY\n<\/pre><\/div>\n\n\n<p>Por\u00e9m, uma vez o limite excedido, a mensagem abaixo \u00e9 reportada:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=180;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\nSELECT * FROM SOE.TESTE1\n*\nERROR at line 1:\nORA-03172: STANDBY_MAX_DATA_DELAY of 180 seconds exceeded\n<\/pre><\/div>\n\n\n<p>O \u00faltimo valor poss\u00edvel de nosso par\u00e2metro seria 0, onde o objetivo \u00e9 garantir que a consulta no Standby esteja id\u00eantica caso fosse executada no primary, a menos que haja algum Lag, o que causaria erro. No exemplo abaixo, como a tabela no primary possui 3 registros e no standby apenas 2 (por conta do Redo Apply estar parado), uma mensagem \u00e9 reportada:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nPRIMARY:\n \nSQL&gt; select * from SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\nSEM REDO APPLY\nBSS\n \nSTANDBY:\n \nSQL&gt; SELECT value &quot;Lag&quot;, datum_time &quot;Received Time&quot;, Time_Computed &quot;Time Computed &quot; FROM V$DATAGUARD_STATS WHERE name like &#039;apply lag&#039;;\n \nLag\n----------------------------------------------------------------\nReceived Time                  Time Computed\n------------------------------ ------------------------------\n+00 13:01:11\n06\/01\/2021 19:33:10            06\/01\/2021 19:33:10\n \n \nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=0;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\nSELECT * FROM SOE.TESTE1\n*\nERROR at line 1:\nORA-03172: STANDBY_MAX_DATA_DELAY of 0 seconds exceeded\n<\/pre><\/div>\n\n\n<p>Vamos habilitar o Redo Apply:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; conn \/ as sysdba\nConnected.\nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Realizando novamente a consulta no Standby. Mesmo assim o erro ainda \u00e9 reportado, nos dando a impress\u00e3o que ainda h\u00e1 algum lag (mesmo que nossa consulta de refer\u00eancia mostre que n\u00e3o):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; SELECT value &quot;Lag&quot;, datum_time &quot;Received Time&quot;, Time_Computed &quot;Time Computed &quot; FROM V$DATAGUARD_STATS WHERE name like &#039;apply lag&#039;;\n \nLag\n----------------------------------------------------------------\nReceived Time                  Time Computed\n------------------------------ ------------------------------\n+00 00:00:00\n06\/01\/2021 19:45:30            06\/01\/2021 19:45:31\n \n \nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=0;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\nSELECT * FROM SOE.TESTE1\n                  *\nERROR at line 1:\nORA-00604: error occurred at recursive SQL level 1\nORA-03172: STANDBY_MAX_DATA_DELAY of 0 seconds exceeded\n \n \nSQL&gt; alter session sync with primary;\nERROR:\nORA-03173: Standby may not be synced with primary\n<\/pre><\/div>\n\n\n<p>Logo percebemos que o &#8220;SYNC WITH PRIMARY&#8221; s\u00f3 \u00e9 permitido quando o Transport Service est\u00e1 no modo SYNC, que n\u00e3o \u00e9 o nosso caso:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlog_archive_dest_2                   string      SERVICE=cortexDR ASYNC VALID_F\n                                                 OR=(ONLINE_LOGFILES,PRIMARY_RO\n                                                 LE) DB_UNIQUE_NAME=cortexDR\n<\/pre><\/div>\n\n\n<p>Vou parar o Redo Apply e alterar este par\u00e2metro no prim\u00e1rio:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSTANDBY:\n \nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;\n \nDatabase altered.\n \nPRIMARY:\n \nSQL&gt; ALTER SYSTEM SET log_archive_dest_2=&#039;SERVICE=cortexDR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=cortexDR&#039;;\n \nSystem altered.\n<\/pre><\/div>\n\n\n<p>Ao iniciar Redo Apply no Standby e fazer o teste novamente, o mesmo erro \u00e9 reportado. Desse modo, alteramos o par\u00e2metro &#8220;archive_lag_target&#8221; no banco Primary para o valor 0:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER SYSTEM SET archive_lag_target=0;\n \nSystem altered.\n \nSQL&gt; shu immediate;\nDatabase closed.\nDatabase dismounted.\nORACLE instance shut down.\nSQL&gt; startup;\nORACLE instance started.\n \nTotal System Global Area 2583690520 bytes\nFixed Size                  8899864 bytes\nVariable Size             553648128 bytes\nDatabase Buffers         2013265920 bytes\nRedo Buffers                7876608 bytes\nDatabase mounted.\nDatabase opened.\n<\/pre><\/div>\n\n\n<p>Testando novamente no Standby:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \\&quot;wp-block-syntaxhighlighter-code\\&quot;\"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;\n \nDatabase altered.\n \nSQL&gt; ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;\n \nDatabase altered.\n \nSQL&gt; conn SOE\/soe\nConnected.\nSQL&gt; ALTER SESSION SET STANDBY_MAX_DATA_DELAY=0;\n \nSession altered.\n \nSQL&gt; SELECT * FROM SOE.TESTE1;\n \nDESCRICAO\n--------------------\nACTIVE DATA GUARD\nSEM REDO APPLY\nBSS\n<\/pre><\/div>\n\n\n<p>Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laborat\u00f3rio pessoal para fins de aprendizado.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Em ambientes que possuam a op\u00e7\u00e3o de Active Data Guard habilitada, temos um recurso importante para controle de toler\u00e2ncia de Lag (de apply log), materializado em um par\u00e2metro de sess\u00e3o chamado STANDBY_MAX_DATA_DELAY. Neste artigo, vamos explorar em termos pr\u00e1ticos esse item. Validando ambiente que ser\u00e1 utilizado para testes: Atrav\u00e9s do teste abaixo, no banco Standby, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-5109","post","type-post","status-publish","format-standard","hentry","category-high-availability"],"_links":{"self":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=5109"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5109\/revisions"}],"predecessor-version":[{"id":9116,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5109\/revisions\/9116"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=5109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=5109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=5109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}