{"id":5167,"date":"2021-06-03T08:35:45","date_gmt":"2021-06-03T08:35:45","guid":{"rendered":"https:\/\/swiv.com.br\/convert-the-physical-standby-database-to-snapshot-database-using-sql-plus\/"},"modified":"2026-05-27T20:02:31","modified_gmt":"2026-05-27T19:02:31","slug":"convert-the-physical-standby-database-to-snapshot-database-using-sql-plus","status":"publish","type":"post","link":"https:\/\/swiv.com.br\/index.php\/2021\/06\/03\/convert-the-physical-standby-database-to-snapshot-database-using-sql-plus\/","title":{"rendered":"Converting the Physical Standby Database to Snapshot Database (using SQL *Plus)"},"content":{"rendered":"\n<p>Em muitas situa\u00e7\u00f5es, precisamos validar algum deploy importante em nosso ambiente produtivo, para ver se sua implementa\u00e7\u00e3o ser\u00e1 bem sucedida e se n\u00e3o trar\u00e1 malef\u00edcios (at\u00e9 em termos de performance) para o banco como um todo. Nesses casos, podemos utilizar um recurso muito interessante: Snapshot Databases, que faz parte da licen\u00e7a do Enterprise Edition. Neste caso, conseguimos realizar opera\u00e7\u00f5es de altera\u00e7\u00f5es no Snap, como DDLs, DMLs,etc, e durante sua vida \u00fatil, os Redos do primary s\u00e3o apenas transmitidos ao standby, mas n\u00e3o aplicados. No momento da cria\u00e7\u00e3o do Snapshot Database, um Guaranteed Restore Point (GRP) \u00e9 criado nos bastidores, para que nos permita realizar a convers\u00e3o depois para Standby Database. Neste artigo vamos demonstrar como realizar essa opera\u00e7\u00e3o utilizando o SQL *Plus.<\/p>\n\n\n\n<p>Validando ambiente primary e standby que ser\u00e3o usados:<\/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 Thu Jun 3 05:23: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 DB_UNIQUE_NAME,DATABASE_ROLE,OPEN_MODE FROM V$DATABASE;\n \nDB_UNIQUE_NAME                 DATABASE_ROLE    OPEN_MODE\n------------------------------ ---------------- --------------------\ncortex                         PRIMARY          READ WRITE\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 ~]$ sqlplus \/ as sysdba\n \nSQL*Plus: Release 19.0.0.0.0 - Production on Thu Jun 3 05:23:59 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 DB_UNIQUE_NAME,DATABASE_ROLE,OPEN_MODE FROM V$DATABASE;\n \nDB_UNIQUE_NAME                 DATABASE_ROLE    OPEN_MODE\n------------------------------ ---------------- --------------------\ncortexDR                       PHYSICAL STANDBY MOUNTED\n<\/pre><\/div>\n\n\n<p>O processo em si \u00e9 muito simples. Vamos parar o processo de Redo Apply do Standby, conforme abaixo:<\/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>Devemos garantir que o Standby esteja em mount state (que j\u00e1 \u00e9 o meu caso), e disparar o comando de convers\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; ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Agora podemos abrir o Standby em read\/write mode:<\/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 OPEN;\n \nDatabase altered.\n<\/pre><\/div>\n\n\n<p>Podemos notar que o database role \u00e9 exibido como snapshot, al\u00e9m de j\u00e1 termos garantido que o ambiente tenha o Flashback Database habilitado:<\/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 DATABASE_ROLE, OPEN_MODE, FLASHBACK_ON FROM V$DATABASE;\n \nDATABASE_ROLE    OPEN_MODE            FLASHBACK_ON\n---------------- -------------------- ------------------\nSNAPSHOT STANDBY READ WRITE           YES\n<\/pre><\/div>\n\n\n<p>Simulando a execu\u00e7\u00e3o de DDL e DML no Snapshot 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; CREATE TABLE SOE.VALIDACAO (DESCRICAO VARCHAR2(40));\n \nTable created.\n \nSQL&gt; INSERT INTO SOE.VALIDACAO (DESCRICAO) VALUES (&#039;SNAP STANDBY&#039;);\n \n1 row created.\n \nSQL&gt; COMMIT;\n \nCommit complete.\n \nSQL&gt; SELECT * FROM SOE.VALIDACAO;\n \nDESCRICAO\n----------------------------------------\nSNAP STANDBY\n<\/pre><\/div>\n\n\n<p>Podemos notar que os Redos gerados pelo primary ainda n\u00e3o enviados ao Standby, mas como dito no in\u00edcio do artigo, os mesmos n\u00e3o s\u00e3o aplicados. Ser\u00e3o usados depois para a convers\u00e3o do Snapshot Database para Standby Database:<\/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 DB_UNIQUE_NAME,DATABASE_ROLE,OPEN_MODE FROM V$DATABASE;\n \nDB_UNIQUE_NAME                 DATABASE_ROLE    OPEN_MODE\n------------------------------ ---------------- --------------------\ncortex                         PRIMARY          READ WRITE\n \nSQL&gt; ALTER SYSTEM SWITCH LOGFILE ;\n \nSystem altered.\n \nSQL&gt; SELECT THREAD#, MAX(SEQUENCE#) FROM V$LOG GROUP BY THREAD# ;\n \n   THREAD# MAX(SEQUENCE#)\n---------- --------------\n         1            101\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 PROCESS,STATUS,SEQUENCE# FROM V$MANAGED_STANDBY;\n \nPROCESS   STATUS        SEQUENCE#\n--------- ------------ ----------\nARCH      CONNECTED             0\nDGRD      ALLOCATED             0\nDGRD      ALLOCATED             0\nARCH      CONNECTED             0\nARCH      CLOSING              99\nARCH      CLOSING             100\nLNS       CONNECTED             0\nDGRD      ALLOCATED             0\nRFS       IDLE                  0\nRFS       IDLE                101\n \n10 rows selected.\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 muitas situa\u00e7\u00f5es, precisamos validar algum deploy importante em nosso ambiente produtivo, para ver se sua implementa\u00e7\u00e3o ser\u00e1 bem sucedida e se n\u00e3o trar\u00e1 malef\u00edcios (at\u00e9 em termos de performance) para o banco como um todo. Nesses casos, podemos utilizar um recurso muito interessante: Snapshot Databases, que faz parte da licen\u00e7a do Enterprise Edition. Neste [&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-5167","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\/5167","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=5167"}],"version-history":[{"count":1,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5167\/revisions"}],"predecessor-version":[{"id":9113,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/posts\/5167\/revisions\/9113"}],"wp:attachment":[{"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=5167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=5167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swiv.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=5167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}