{"id":1633,"date":"2013-01-14T21:52:39","date_gmt":"2013-01-14T23:52:39","guid":{"rendered":"http:\/\/fabriciolima.net\/blog\/?p=1633"},"modified":"2016-07-23T23:34:17","modified_gmt":"2016-07-24T02:34:17","slug":"database-mirroring-configurando-um-snapshot-no-servidor-mirror","status":"publish","type":"post","link":"https:\/\/fabriciolima.net\/blog\/2013\/01\/14\/database-mirroring-configurando-um-snapshot-no-servidor-mirror\/","title":{"rendered":"Database Mirroring &#8211; Configurando um Snapshot no servidor Mirror"},"content":{"rendered":"<p>Fala Pessoal,<\/p>\n<p>Todos se perguntam se \u00e9 poss\u00edvel fazer relat\u00f3rios com a base de dados que est\u00e1 sendo espelhada pelo Database Mirroring. Isso \u00e9 poss\u00edvel apenas criando um Snapshot dessa database, ou seja, voc\u00ea consegue ter uma foto da base para fazer consultas.<\/p>\n<p>Para criar uma database Read-Only no servidor de mirror temos que criar um snapshot da database que est\u00e1 sendo espelhada com o comando abaixo:<\/p>\n<p>create database Mirror3_Snapshot<br \/>\non<br \/>\n(Name = Mirror3,<br \/>\nFileName = &#8216;c:\\Mirror3_Snapshot.ss&#8217;)<br \/>\nAS SNAPSHOT OF Mirror3<\/p>\n<p>Onde,<\/p>\n<p>Mirror3_Snapshot =&gt; Nome da database snapshot<\/p>\n<p>\u201cName = Mirror3\u201d =&gt; Mirror3 \u00e9 o nome l\u00f3gico do arquivo mdf da database principal<\/p>\n<p>\u201cc:\\Mirror3_Snapshot.ss\u201d =&gt; Caminho e nome do Sparse File<\/p>\n<p>\u201cSNAPSHOT OF Mirror3\u201d =&gt; Mirror3_Snapshot ser\u00e1 uma c\u00f3pia da database Mirror3<\/p>\n<p>Ap\u00f3s a execu\u00e7\u00e3o desse comando, uma database para consultas j\u00e1 est\u00e1 disponibilizada no servidor mirror. Essa database fica vis\u00edvel na pasta Database Snapshots conforme a figura abaixo:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1913\" title=\"Figura 1\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13.png\" alt=\"\" width=\"326\" height=\"112\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13.png 326w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13-300x103.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13-100x34.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13-275x94.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-13-20x7.png 20w\" sizes=\"auto, (max-width: 326px) 100vw, 326px\" \/><\/a><\/p>\n<p>Como essa database \u00e9 readonly, n\u00e3o ser\u00e1 poss\u00edvel alterar dados na mesma.<br \/>\nEx: O comando abaixo:<\/p>\n<p>select *<br \/>\ninto _Usuarios<br \/>\nfrom sys.sysusers<\/p>\n<p>Gera o erro:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1914\" title=\"Figura 2\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22.png\" alt=\"\" width=\"572\" height=\"59\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22.png 572w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22-300x31.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22-410x42.png 410w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22-100x10.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22-275x28.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2012\/11\/Figura-22-20x2.png 20w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/a><\/p>\n<p>Entretanto, podemos criar tabelas tempor\u00e1rias para utilizar em nossas rotinas de relat\u00f3rios, pois elas ficam armazenadas no TempDB. O Comando abaixo \u00e9 executado com sucesso.<\/p>\n<p>select uid<br \/>\ninto #TesteSnapshot<br \/>\nfrom sys.sysusers<\/p>\n<p>Para manter um servidor D-1 sempre atualizado, podemos executar um job di\u00e1rio \u00e0s 00:00h com os comandos abaixo:<\/p>\n<p>use master<br \/>\nif OBJECT_ID(&#8216;tempdb..#Processos&#8217;) is not null<br \/>\ndrop table #Processos<\/p>\n<p>Declare @SpId as varchar(5)<br \/>\nselect Cast(spid as varchar(5))SpId<br \/>\ninto #Processos<br \/>\nfrom master.dbo.sysprocesses A<br \/>\njoin master.dbo.sysdatabases B on A.DbId = B.DbId<br \/>\nwhere B.Name =&#8217;Mirror3_Snapshot&#8217;<\/p>\n<p>while (select count(*) from #Processos) &gt;0<br \/>\nbegin<br \/>\nset @SpId = (select top 1 SpID from #Processos)<br \/>\nexec (&#8216;Kill &#8216; + \u00a0\u00a0 \u00a0@SpId)<br \/>\ndelete from #Processos where SpID = @SpId<br \/>\nend<\/p>\n<p>drop database Mirror3_Snapshot<\/p>\n<p>create database Mirror3_Snapshot<br \/>\non<br \/>\n(Name = Mirror3,<br \/>\nFileName = &#8216;c:\\Mirror3_Snapshot.ss&#8217;)<br \/>\nAS SNAPSHOT OF Mirror3<\/p>\n<p>Dessa forma voc\u00ea teria uma foto do seu ambiente com os dados do dia anterior que poderiam ser utilizados para a gera\u00e7\u00e3o de relat\u00f3rios.<\/p>\n<p>Fica a Dica.<\/p>\n<p>Artigos relacionados:<\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/15\/serie-de-posts-sobre-database-mirroring\/\" target=\"_blank\">S\u00e9rie de Posts sobre Database Mirroring<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/15\/database-mirroring-como-alterar-o-operation-mode\/\" target=\"_blank\">Database Mirroring \u2013 Como alterar o Operation Mode<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/23\/database-mirroring-testes-operation-mode-high-performance-parte-1\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Performance \u2013 Parte 1<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/28\/database-mirroring-operation-mode-high-performance-parte-2\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Performance \u2013 Parte 2<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/05\/31\/database-mirroring-operation-mode-high-performance-parte-3\/\" target=\"_blank\">Database Mirroring &#8211; Operation Mode High Performance &#8211; Parte 3<\/a><\/p>\n<p><a rel=\"bookmark\" href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/06\/27\/database-mirroring-operation-mode-high-safety-without-failover-parte-1\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety Without Failover \u2013  Parte 1<\/a><\/p>\n<p><a rel=\"bookmark\" href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/06\/29\/database-mirroring-operation-mode-high-safety-without-failover-parte-2\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety Without Failover \u2013  Parte 2<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/10\/31\/database-mirroring-operation-mode-high-safety-with-automatic-failover\/\" target=\"_blank\">Database Mirroring \u2013 Operation Mode High Safety with Automatic Failover<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2012\/12\/03\/database-mirroring-tempo-failover-hs-with-automatic-failover-com-timeout\/\" target=\"_blank\">Database Mirroring \u2013 Tempo Failover \u2013 HS With Automatic Failover com Timeout<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2013\/01\/01\/database-mirroring-tirando-o-servidor-de-witness-do-mirror-em-caso-de-falha\/\" target=\"_blank\">Database Mirroring \u2013 Tirando o servidor de Witness do Mirror em caso de falha<\/a><\/p>\n<p><a href=\"https:\/\/www.fabriciolima.net\/blog\/2013\/01\/11\/database-mirroring-failover-manual-de-varias-bases-ao-mesmo-tempo\/\" target=\"_blank\">Database Mirroring \u2013 Failover manual de v\u00e1rias bases ao mesmo tempo<\/a><\/p>\n<p><b>Gostou desse Post?<\/b><\/p>\n<p>Cadastre seu e-mail para receber novos Posts e curta minha <a href=\"https:\/\/www.facebook.com\/FabricioLimaSolucoesemBancodeDados\/\" target=\"_blank\">P\u00e1gina no Facebook<\/a> para receber Dicas de Leituras e Eventos sobre SQL Server.<\/p>\n<p>Abra\u00e7os,<\/p>\n<p>Fabr\u00edcio Lima<\/p>\n<p>MCITP \u2013 Database Administrator<\/p>\n<p>Consultor e Instrutor SQL Server<\/p>\n<p>Trabalha com SQL Server desde 2006<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fala Pessoal, Todos se perguntam se \u00e9 poss\u00edvel fazer relat\u00f3rios com a base de dados que est\u00e1 sendo espelhada pelo Database Mirroring. Isso \u00e9 poss\u00edvel apenas criando um Snapshot dessa database, ou seja, voc\u00ea consegue ter uma foto da base para fazer consultas. Para criar uma database Read-Only no servidor de mirror temos que criar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3,33,280],"tags":[604,606,391,23,607,372,613,611,612,610,608,616,49,33,50,34,605,609,614,615],"class_list":["post-1633","post","type-post","status-publish","format-standard","hentry","category-administracao-de-bd","category-sql-server","category-virtual-pass-br","tag-alta-disponibilidade","tag-database-mirror","tag-database-mirroring","tag-dba","tag-espelhamento-de-banco-de-dados","tag-high-availability","tag-high-performance","tag-high-safety-with-automatic-failover","tag-high-safety-without-automatic-failover","tag-operation-mode","tag-perda-de-dados","tag-safety","tag-sql","tag-sql-server","tag-sql-server-2005","tag-sql-server-2008","tag-sql-server-mirror","tag-sql-server-online","tag-sys-database_mirroring","tag-witness"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/1633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/comments?post=1633"}],"version-history":[{"count":0,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/1633\/revisions"}],"wp:attachment":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/media?parent=1633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/categories?post=1633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/tags?post=1633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}