{"id":3447,"date":"2021-04-02T08:18:07","date_gmt":"2021-04-02T08:18:07","guid":{"rendered":"https:\/\/swiv.com.br\/skipping-and-un-skipping-object-from-logical-standby-replication\/"},"modified":"2026-05-27T20:02:49","modified_gmt":"2026-05-27T19:02:49","slug":"skipping-and-un-skipping-object-from-logical-standby-replication","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/04\/02\/skipping-and-un-skipping-object-from-logical-standby-replication\/","title":{"rendered":"Skipping and Un-skipping object from Logical Standby replication"},"content":{"rendered":"\n<p>Para relembrar, nosso Data Guard com Logical Standby replicar\u00e1 todos os objetos, exceto em 3 situa\u00e7\u00f5es: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Objetos de schemas internos (como SYS e SYSTEM): \u00e9 poss\u00edvel checarmos essa lista usando a query abaixo no primary:<\/li><\/ul>\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 DISTINCT(OWNER) FROM DBA_LOGSTDBY_SKIP WHERE STATEMENT_OPT=&#039;INTERNAL SCHEMA&#039;;\n \nOWNER\n--------------------------------------------------------------------------------\nAPPQOSSYS\nDBSNMP\nGSMCATUSER\nSYS\nSYSTEM\nXS$NULL\nANONYMOUS\nDBSFWUSER\nGGSYS\nGSMUSER\nREMOTE_SCHEDULER_AGENT\n \nOWNER\n--------------------------------------------------------------------------------\nSYSBACKUP\nCTXSYS\nGSMROOTUSER\nSYSRAC\nAUDSYS\nDVF\nDVSYS\nOJVMSYS\nSI_INFORMTN_SCHEMA\nDIP\nGSMADMIN_INTERNAL\n \nOWNER\n--------------------------------------------------------------------------------\nORDPLUGINS\nLBACSYS\nMDSYS\nOLAPSYS\nORDDATA\nSYSKM\nORACLE_OCM\nOUTLN\nSYS$UMF\nORDSYS\nSYSDG\n \nOWNER\n--------------------------------------------------------------------------------\nWMSYS\nXDB\n \n35 rows selected.\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\"><li>Objetos que possuam algum datatype incompat\u00edvel (que podem ser coletados nas views DBA_LOGSTDBY_UNSUPPORTED e LOGSTDBY_UNSUPPORTED_TABLES):<\/li><\/ul>\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 OWNER,TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED;\n \nOWNER\n--------------------------------------------------------------------------------\nTABLE_NAME\n--------------------------------------------------------------------------------\nSOE\nBSS\n<\/pre><\/div>\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 LOGSTDBY_UNSUPPORTED_TABLES;\n \nOWNER\n--------------------------------------------------------------------------------\nTABLE_NAME\n--------------------------------------------------------------------------------\nSOE\nBSS\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\"><li>Regras criadas de forma expl\u00edcita pelo DBA, por vari\u00e1veis motivos. \u00c9 sobre essa terceita categoria que irei explorar neste artigo.<\/li><\/ul>\n\n\n\n<p>Para isso, vamos criar uma tabela de testes no ambiente primary, vide abaixo:<\/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 Fri Apr 2 04:47:12 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; CREATE TABLE SOE.MERCURIO ( ID NUMBER PRIMARY KEY, NOME VARCHAR2(30)) ;\n \nTable created.\n \nSQL&gt; INSERT INTO SOE.MERCURIO VALUES (1, &#039;STRING A&#039;) ;\n \n1 row created.\n \nSQL&gt; INSERT INTO SOE.MERCURIO VALUES (2, &#039;STRING B&#039;) ;\n \n1 row created.\n \nSQL&gt; INSERT INTO SOE.MERCURIO VALUES (3, &#039;STRING C&#039;) ;\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; ALTER SYSTEM SWITCH LOGFILE;\n \nSystem altered.\n<\/pre><\/div>\n\n\n<p>Confirmando que o SQL Apply j\u00e1 replicou o objeto para o Logical Standby:<\/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@fornix2 trace]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 04:48:41 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 OBJECT_NAME, OBJECT_TYPE FROM DBA_OBJECTS WHERE OBJECT_NAME=&#039;MERCURIO&#039;;\n \nOBJECT_NAME\n--------------------------------------------------------------------------------\nOBJECT_TYPE\n-----------------------\nMERCURIO\nTABLE\n<\/pre><\/div>\n\n\n<p>Criando regra de Skipp desta tabela 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=\"\">\n&#x5B;oracle@fornix1 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 04:53:53 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; exec DBMS_LOGSTDBY.SKIP(stmt=&gt;&#039;DML&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n \nSQL&gt; exec DBMS_LOGSTDBY.SKIP(stmt=&gt;&#039;SCHEMA_DDL&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n<\/pre><\/div>\n\n\n<p>Criando a regra tamb\u00e9m no Standby (realizando o stop e start do SQL Apply):<\/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@fornix2 trace]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 04:54:48 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; ALTER DATABASE STOP LOGICAL STANDBY APPLY;\n \nDatabase altered.\n \nSQL&gt; exec DBMS_LOGSTDBY.SKIP(stmt=&gt;&#039;DML&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n \nSQL&gt; exec DBMS_LOGSTDBY.SKIP(stmt=&gt;&#039;SCHEMA_DDL&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n \nSQL&gt; ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Com a query abaixo \u00e9 poss\u00edvel listarmos todos os objetos e regras que est\u00e3o criados para obedecer o skipp:<\/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 OWNER, STATEMENT_OPT , NAME, USE_LIKE, ESC from DBA_LOGSTDBY_SKIP WHERE OWNER=&#039;SOE&#039;;\n \nOWNER\n--------------------------------------------------------------------------------\nSTATEMENT_OPT\n--------------------------------------------------------------------------------\nNAME\n--------------------------------------------------------------------------------\nU E\n- -\nSOE\nDML\nMERCURIO\nY\n \n \nOWNER\n--------------------------------------------------------------------------------\nSTATEMENT_OPT\n--------------------------------------------------------------------------------\nNAME\n--------------------------------------------------------------------------------\nU E\n- -\nSOE\nSCHEMA_DDL\nMERCURIO\nY\n<\/pre><\/div>\n\n\n<p>Adicionando 2 registros na tabela 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.MERCURIO VALUES (4, &#039;STRING D&#039;) ;\n \n1 row created.\n \nSQL&gt; INSERT INTO SOE.MERCURIO VALUES (5, &#039;STRING E&#039;) ;\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; ALTER SYSTEM SWITCH LOGFILE;\n \nSystem altered.\n<\/pre><\/div>\n\n\n<p>Importante salientar que a regra de Skipp n\u00e3o impede que os dados sejam emitidos do primary para o standby, mas sim que o Standby n\u00e3o aplique o SQL Apply que contempla a regra. Mesmo aguardando um tempo, percebemos que os 2 novos registros n\u00e3o s\u00e3o replicados ao standby (o que era esperado):<\/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@fornix2 trace]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:01:25 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 count(*) from SOE.MERCURIO;\n \n  COUNT(*)\n----------\n         3\n<\/pre><\/div>\n\n\n<p>Como criamos regras tamb\u00e9m para opera\u00e7\u00f5es de DDL nesta tabela, farei um truncate na mesma 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=\"\">\n&#x5B;oracle@fornix1 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:02:37 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; TRUNCATE TABLE SOE.MERCURIO;\n \nTable truncated.\n \nSQL&gt; ALTER SYSTEM SWITCH LOGFILE;\n \nSystem altered.\n<\/pre><\/div>\n\n\n<p>Esta opera\u00e7\u00e3o tamb\u00e9m n\u00e3o foi replicada ao Standby:<\/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@fornix2 trace]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:04:48 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 count(*) from SOE.MERCURIO;\n \n  COUNT(*)\n----------\n         3\n<\/pre><\/div>\n\n\n<p>O UN-SKIPP requer a cria\u00e7\u00e3o de um DB_LINK no standby apontando para o primary, que permitir\u00e1 o &#8220;instantiate&#8221; da tabela, que nada mais seria que a sua replica\u00e7\u00e3o total ao destino:<\/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@fornix2 admin]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:10:05 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; CREATE PUBLIC DATABASE LINK BRUNO_LINK CONNECT TO system IDENTIFIED BY oracle USING &#039;CORTEX&#039;;\n \nDatabase link created.\n \nSQL&gt; select sysdate from dual@BRUNO_LINK ;\n \nSYSDATE\n-------------------\n2021-04-02:05:10:14\n<\/pre><\/div>\n\n\n<p>Removendo a regra 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=\"\">\n&#x5B;oracle@fornix1 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:11:37 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; exec DBMS_LOGSTDBY.UNSKIP(stmt=&gt;&#039;DML&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n \nSQL&gt; exec DBMS_LOGSTDBY.UNSKIP(stmt=&gt;&#039;SCHEMA_DDL&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n<\/pre><\/div>\n\n\n<p>Removendo a regra 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=\"\">\n&#x5B;oracle@fornix2 admin]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:12:15 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; ALTER DATABASE STOP LOGICAL STANDBY APPLY;\n \nDatabase altered.\n \nSQL&gt; exec DBMS_LOGSTDBY.UNSKIP(stmt=&gt;&#039;DML&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n \nSQL&gt; exec DBMS_LOGSTDBY.UNSKIP(stmt=&gt;&#039;SCHEMA_DDL&#039;,schema_name=&gt;&#039;SOE&#039;,object_name =&gt;&#039;MERCURIO&#039;);\n \nPL\/SQL procedure successfully completed.\n<\/pre><\/div>\n\n\n<p>Como havia truncado a tabela na origem, vou adicionar algumas linhas 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=\"\">\n&#x5B;oracle@fornix1 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:13:32 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; INSERT INTO SOE.MERCURIO VALUES (1, &#039;STRING A&#039;) ;\nINSERT INTO SOE.MERCURIO VALUES (2, &#039;STRING B&#039;) ;\nINSERT INTO SOE.MERCURIO VALUES (3, &#039;STRING C&#039;) ;\n1 row created.\n \nSQL&gt;\n1 row created.\n \nSQL&gt;\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n<\/pre><\/div>\n\n\n<p>No standby, realizando o instantiate da tabela:<\/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@fornix2 admin]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Fri Apr 2 05:14:42 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; EXEC DBMS_LOGSTDBY.INSTANTIATE_TABLE (SCHEMA_NAME =&gt; &#039;SOE&#039;, TABLE_NAME =&gt; &#039;MERCURIO&#039;, DBLINK =&gt; &#039;BRUNO_LINK&#039;);\n \nPL\/SQL procedure successfully completed.\n<\/pre><\/div>\n\n\n<p>Inicializando o SQL Apply e confirmando que a tabela foi replicada com sucesso:<\/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 START LOGICAL STANDBY APPLY IMMEDIATE;\n \nDatabase altered.\n \nSQL&gt; SELECT COUNT(*) FROM SOE.MERCURIO;\n \n  COUNT(*)\n----------\n         3\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>Para relembrar, nosso Data Guard com Logical Standby replicar\u00e1 todos os objetos, exceto em 3 situa\u00e7\u00f5es: Objetos de schemas internos (como SYS e SYSTEM): \u00e9 poss\u00edvel checarmos essa lista usando a query abaixo no primary: Objetos que possuam algum datatype incompat\u00edvel (que podem ser coletados nas views DBA_LOGSTDBY_UNSUPPORTED e LOGSTDBY_UNSUPPORTED_TABLES): Regras criadas de forma expl\u00edcita [&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-3447","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\/3447","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=3447"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions"}],"predecessor-version":[{"id":9191,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3447\/revisions\/9191"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=3447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=3447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=3447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}