SlideShare a Scribd company logo
1 of 30
Database Administration Community (https://mostafaelmasry.wordpress.com)
SQL Server Technical Article
High Availability Solution Database Mirroring in SQL Server 2008 R2
Writer: Mustafa EL-Masry
Technical Reviewer: SQLSERVER Performance tuning (http://sqlserver-performance-tuning.net/)
Published: Jan 2015
Applies to: SQL Server 2008 R2, 2012
Slide Share: http://www.slideshare.net/MostafaElmasry3
About The Writer
I am Mustafa El-MasrySeniorDatabase administratorandDB Analyst I
am ExpertDatabase performance tuning, Ihave deeppractical
knowledge aboutT-SQLperformance,HW Performance issues,Data
Warehousinganddatamart solutions,SQLServerReplication,Clustering
solutions(Active Activeandactive passive)andDatabase Designsfor
differentkindsof systems,HAG,divingdeeplymore :
I am Founderof Community:SQL
DATABASEADMINISTRATION:http://mostafaelmasry.wordpress.com/
Linkedin: https://www.linkedin.com/in/mostafaelmasry
My CommunityAnnual report
: https://mostafaelmasry.wordpress.com/2014/annual-report/
I am Technical Writerand Reviewer:http://www.slideshare.net/MostafaElmasry3/
I am Audience MarketingManager and Executive Board member:SQLSERVER PERFORMANCE
TUNING http://sqlserver-performance-tuning.net/
One HundredPOST :http://sqlserver-performance-tuning.net/?p=5244
FluentParticipator at MicrosoftForums of SQL Serverat http://Social.technet.microsoft.com
More than +175 Post in SQL Server Technology: http://sqlserver-performance-tuning.net/?p=4526
MicrosoftProfile:https://www.mcpvirtualbusinesscard.com/VBCServer/EngMostafaElamsry/profile
Database Administration Community (https://mostafaelmasry.wordpress.com)
Agendaand overview
1- IntroductionaboutDatabase MirroringConcept
2- Reference (8Blogs)
3- Note
4- Database mirroringoperationmode
5- Database MirroringRequirement
6- Advantage of Database Mirroring
7- Disadvantage of Database Mirroring
8- Database MirroringEnhancementinSQL Server2008
9- Database MirroringInstallationStepbyStep
10- HighAvailabilityMode [AutomaticFailover]
11- HighAvailabilityMode [Manual Failover]
12- HighSafetyMode Withoutwitnessserver[Manual Failover]
13- Standerlistenerportindatabase mirroring
14- CheckSQL servermirroringavailability
15- Addor replace witnessservertoan existingmirroringdatabase
16- How to monitorDatabase Mirroring
17- Mirroringin workshopnotinDC (DomainController)
Database Administration Community (https://mostafaelmasry.wordpress.com)
Introduction and overview
Database mirroringisa primarilysoftware solution forincreasingdatabase availability.Mirroringis
implementedona per-database basisandworksonlywithdatabasesthatuse the full recoverymodel.
The simple andbulk-loggedrecoverymodelsdonotsupportdatabase mirroring.Therefore,all bulk
operationsare alwaysfullylogged.Database mirroringworkswithanysupporteddatabase compatibility
level. Database mirroringisusedbyMicrosoft SQL Server,arelational database managementsystem
(RDBMS) designedforthe enterpriseenvironment.Twocopiesof asingle database reside ondifferent
computerscalled serverinstances,usuallyinphysical locationsseparatedbysome distance.The
principal (orprimary) serverinstance providesthe database toclients.The mirror(orsecondary) server
instance actsas a standbythat can take overin case of a problemwiththe principal serverinstance.
Database Administration Community (https://mostafaelmasry.wordpress.com)
Reference
Note
 In database mirroring section you have 3 servers (principle, mirroring, and witness)
 The database will be in the principle server and the application will be connect to the
principle server then you will take backup (Full + log) from the database in the principle
server the make restore to this backup with no recovery option in the mirroring server so
the record will copy from the principle server to the mirror server.
 Witness server will be monitoring to the principle and the mirroring server.
 You can setupthe principle serverindomainandthe mirroringserverinanotherdomain
What happensif the principle serverdown in highavailabilitymode?
If the principle serverdownthe mirroringserverwill be the new principle serverandthe applicationwill
be connectautomaticallytothe newprinciple server(mirroringserver)
What happenedwhenthe applicationconnect to the database in the principle server?
Whenthe Applicationconnecttothe principle serverandusersmake anytransactiononthisdatabase
the record will write inlogpuffermemoryinprinciple serverthenwrite it inlogfile indatabase thenthe
logpuffersendthe recordto the log puffermemorytothe mirroringserverthenthe logpufferwrite this
record in log file in database. Then the mirror server send to the principle server massage to know the
principle the transaction is succeed then the principle tell the application the transaction is succeed.
Mirroring in SQL Server (8/8)
Mirroring in SQL Server (7/8)
Mirroring in SQL Server (6/8)
Mirroring in SQL Server (5/8)
Mirroring in SQL Server (4/8)
Mirroring in SQL Server (3/8)
Mirroring in SQL Server (2/8)
Mirroring in SQL Server (1/8)
Database Administration Community (https://mostafaelmasry.wordpress.com)
Database mirroring operation mode
You can setupthe mirroringserverin3 modes
1. High availability.
In highavailabilityyouneed3servers
(principle server,mirroringserver,witness
server) sointhisoperationmode the
applicationconnectonthe principle server
thenthe transactionwrite inlogfile then
the principle serversendthe recordtothe
mirrorserverinlog file the mirrorsendto
the principle (the recordiscommit) then
the principle sendtothe applicationthe transactioniscommitted
2. High safety.
In highsafetymode we don'tneedtothe witnessserverwe willneedinthissectiontothe
principle serverandthe mirrorserveronlysothere'sno automaticfailoverinhighsafetymode.
Andthe operationwill be same inthe highavailabilitymode[applicationconnectonthe
principle serverthenthe transactionwrite inlogfile thenthe principle serversendthe recordto
the mirror serverinlog file the mirrorsendtothe principle (therecordiscommit) thenthe
principle sendtothe applicationthe transactioniscommitted]
Remarks: the difference betweenhighavailabilitymode andhighsafetymode isAutomatic
failoverinhighavailability will foundAutomaticfailoverbutinhighsafetywill notfound
Automaticfailover.Soif the principle serverdownyouhave problembecause youwillmake
manuallystart
The mirroringservertobe principle server.Notlike inhighavailabilitymode thisoperation
make automaticallybecause thisoperationmodehave automaticfailover.
3. High performance.
In highperformance mode youneed2server(principle server,mirrorserver) like highsafety
mode . So the differencebetweenthe highperformancemode andhighsafetymode isinhigh
performance the applicationsendthe transactiontothe principle serverinlogfile thenthe
principle sendthe recordtothe mirrorserverand sendtothe applicationthe transactionis
committedsothe principle server don'twaitthe mirrorserverlike (highsafetymodeandhigh
availabilitymode)
Database Administration Community (https://mostafaelmasry.wordpress.com)
Operation mode servers Automatic failover Principle wait the
mirror
High availability 3 servers Yes Yes
High safety 2 servers No Yes
High performance 2 servers No No
In the finale Iexplainwhatismirroring?,whatisthe operationmode inmirroring?,whatisthe
difference betweenoperationmode inmirroring?,rememberItell youhighsafetyandhigh
performance notneedwitnessserverbutyoucan create witness serverinthisoperationmode butit
will make problemswhityousodon'tmake witnessserverinhighsafetymode andhighperformance
mode
Database MirroringRequirement
 The database and file locationshouldbe same.
 Collectionandmastercode page shouldbe same inthe principle andmirrorserver.
 Database name shouldbe same inthe principle andmirrorserver.
 You cannot mirrormore the 10 databasesin32 bitserversyoucan in64 bitserverbutnot
recommended.
 You cannot use attach/de attach you can use backup andrestore.
 Portsin mirroringshouldbe openinginfirewall orclose the firewall.
 ServicesaccountInSQL and SQL agentshouldbe same in all servers.
 The mirroringnot supportthe cross database transaction& distributedtransactionlog
 SQL servernumbershouldbe same butyoucan setupprinciple serveronSQLServer2008
service pack1 andthe mirroron SQL Serverservice pack2.
Database Administration Community (https://mostafaelmasry.wordpress.com)
Advantage of Database Mirroring
1- Doesnot require special hardware (suchassharedstorage,heart-beatconnection) andcluster
ware,thuspotentiallyhaslowerinfrastructure cost
2- Database mirroringsupportsfull-textcatalogs
3- Hardware and software upgrade that'sveryeasy.
Remark: If youwant upgrade the mirrorserverfromSQL server2008 R2 todenial youmust
pass the mirroringinthissectionthenafterupgrade startthe mirroringagain
4- Increasesthe dataprotection(disasterrecovery).
5- Increasesthe database availabilityif youuse the Syncmode.
6- Cost of database mirroringislessthanclustering.
7- It's robustand efficientthanlogshippingandreplication.
8- Failoverisfastcompare to cluster
9- Mirror servercan be usedto host databasesforotherapplicationsnotlike clustering.
Disadvantage of Database Mirroring
1- Mirroringdoesn'tsupportfile stream.
2- Mirror serverisnot available fordatabase readonly.
3- Mirror serverworkingindatabase level notinserverlevelnotlike clustering(inclustering
failover youmake thisinserverlevelonall database inthisserverinloginsinjobslike this)
Database Mirroring Enhancement in SQL Server 2008
1) Database mirroringautomatic page repair.
 If a page on the principle ormirrorserveriscorrupt,it isautomaticallyreplacedwith
the correspondingcopyonitspartner
 Some page typescannotbe automaticallyrepaired:
 File headerpages
 Database boot page
 Allocationpages
2) CompressedData flow
 Data Flowbetweenthe principle andmirrorserverisnow compressedtoimprove
performance.
3) Manual Failover
 Manual failovernolongerrequire adatabase restart
4) Log performance
 log-sendbuffers
 Page read-ahead
 Write-aheadonthe incominglogstreamonthe mirrorserver
Reference:http://www.sqlserver-training.com/database-mirroring-enhancements-in-sql-server-2008-
from-2005/-
Database Administration Community (https://mostafaelmasry.wordpress.com)
Database Mirroring Installation Step by Step
Let's start to setupmirroringserverinSQLserver2008 R2 in the firstI will setupSQLServer2008R2 with
three instance
1. Principle instance(SQLSERVER2008R2A)
2. Mirroringinstance (SQLSERVER2008R2B)
3. WitnessInstance (SQLSERVER2008R2C)
 In myexample I will make mirroringtype highavailability(Synchronize mode)
 In principle serverIwill create database Mirroring_DB
 Take full backupMirroring_DB.bak
 thentake log TransactionbackupMirroring_DB.trn
 Make restore tothisbackup full mirroringserver withNorecoveryoption
 Thenright clickonMirroring_DB >>Tasks>>Restore>>TransactionLog
 ThenSelectyourtransactionlogbackup(Mirroring_DB.trn)
 Don’tforgetrestore withnorecoveryoption
Database Administration Community (https://mostafaelmasry.wordpress.com)
High Availability Mode [Automatic Failover]
Principle Server
 Rightclick on database Mirroring_Db >> tasks >> Mirror >> Configure Security
 You will ask if you wantto setup witness server or not? selectyes.
 Then you will ask to selectyour principle server [connect to Elmasry-PCPrinciple]and make the port is 5021 and
the endpointname is Principle then Click next
 You will ask again to selectyour Mirroring server [connectto Elmasry-PCMirroring]and make the port is 5022
and the endpointname is mirroring then click next.
 You will ask again to selectyour witness server [connectto Elmasry-PC]and make the port is 5023 and the
endpointname is Witness then click next .
 In this step he will ask you to put your user name in your windows and this user mustbe add in the SQL Server
so I write my username is [mypc namewindows username][Elmasry-PCElmasry].then click finish
 SQL server after you click finish itwill make configuration to the Principle Server , Mirroring Server , Witness
Server
 After this configuration is finish SQL server will give you massage if you want to Start mirroring or not selectstart
and Waite few mints then mirroring will startand you see the status is [Synchronized: the databases are fully
synchronized]
 Nowgo to make refreshtothe servers[principle - mirroring]
Database Administration Community (https://mostafaelmasry.wordpress.com)
Principle Server[Elmasry-PCPrinciple]
1- Create Table Name Employee
CREATE TABLE Employee
(Emp_Id INT NOT NULL PRIMARY KEY IDENTITY,
Emp_Name NVARCHAR(50) NOT NULL,
Tel NVARCHAR(12) NULL)
2- Insert data in this table
INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N'Mostafa', -- Emp_Name - nvarchar(50)
N'0172788327' -- Tel - nvarchar(12)
) , ('Mohamed' , '015876565645')
3- Nowif you selectdatafromEmployee Table youwill see2rows
4- Rightclickon the principle serverandmake stoptothe server
Mirroring Server[Elmasry-PCMirroring]
1- Refreshthe server(youwillsee the database change frommirroringtoprincipledatabase andif
youopenthe database you will see the Employee table andthe 2 rows
2- Nowtry to insertinthistable another2 rows
Database Administration Community (https://mostafaelmasry.wordpress.com)
INSERT INTO dbo.Employee
( Emp_Name, Tel )
VALUES ( N'Omar', -- Emp_Name - nvarchar(50)
N'0172788327' -- Tel - nvarchar(12)
) , ('Kemo' , '015876565645')
3- Stopthe serverandstart the principle server[Elmasry-PCPrinciple] youwill seethe database is
mirroringmake stopto the Mirroringserver[Elmasry-PCMirroring] youwill see the difference
the mirroringdatabase inthe principle serverwill change toPrinciple severandif youopenthe
Employee table youwillsee 4rowsnot 2 because the 2 rowsyou insertintodatabase in
mirroringservertransferautomaticallytoanotherserver
Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisverygoodthat’sis
manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning
change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this
operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically
because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same
operationbyyourhand :
1- Go to principle serverthenrightclickandselecttasks>>> Mirror
2- ThenClickon Failoveryouwill seethe massage Clickyes
3- Thenmake refreshtothe serveryouwill see the change
Database Administration Community (https://mostafaelmasry.wordpress.com)
High Availability Mode [Manual Failover]
Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisvery goodthat’sis
manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning
change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this
operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically
because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same operation
by yourhand :
 Go to principle serverthenrightclickandselecttasks>>>>> Mirror
 ThenClickon Failoveryouwill seethe massage Clickyes
 Thenmake refreshtothe serveryouwill see the change
High Safety Mode Without witness server [Manual Failover]
In Highsafetymode if the principle serverdownthe mirroringwill be disconnectbutif youwantto
make the mirroringDB is principle DBinhighAvailabilitySQLServermake thisoperationAutomatically
because inthismode youhave AutomaticFailoverbutdon’tworryyoucan make thisbycode [Ilisten
someone tell me Whywe can'tmake the mirroringisprinciple byManual failoverItell himbecause the
mirroringmode ishighsafetyandthe principle serverisdownsothe mirroringserverisdisconnectedso
if you make rightclickon the mirroringDB thenSelecttasksthenmirroryouwill see the buttonof
FailoverisDisable]sowe have one choice orone way to make the MirroringDB isprinciple DBto allow
the applicationtoconnectThisWay is ByCode let'sstart to explainthe Mirroring[HighSafetyMode]
Database Administration Community (https://mostafaelmasry.wordpress.com)
Principle Server[Elmasry-PCPrinciple]
1- Rightclickon mirroringdatabase >>>> tasks>>>> Mirror
2- Delete the servernetworkaddresstothe witnessserver.automaticyouwillsee the SQLserver
change your mode fromhighavailabilitymode tohighsafetymode >>>>> clickok .
3- Rightclickon the principle server>>>> thenselectstop.
4- The serverwill be down
Mirroring Server[Elmasry-PCMirroring]
1- Refreshthe MirroringServer
2- You will see the database [Mirroring_DB] isDisconnected/inrecovery.
3- NowI will Execute SQLStatementonmasterdatabase inmirroringseverthisstatementwill
change the mirroring_DBfrom mirrorto principle
USE master
GO
ALTER DATABASE Mirroring_DB SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
4- If you make start to the Principle server[Elmasry-PCPrinciple] youmustgoto the Mirroring
Severandright clickonMirroring_Db >>>Tasks >>>>Mirror >>>> Make resume toreturn the
mirrorto work.
5- HighPerformance Mode like HighSafetymode butif youwantto know the difference between
highsafetymode andhighperformance mode see partno1
Database Administration Community (https://mostafaelmasry.wordpress.com)
Stander listener port in database mirroring
If we will buildthe entire instance (Principle,mirroring,Witness) inthe same serveratthistime you
shoulduse difference portsExample:
 Principle Serveruse the Standerportnumber5021
 MirroringServeruse the Standerport number5022
 WitnessServeruse the Standerportnumber5023
But if youwill builditindifference serversyoucanuse one port like: 5021 butdon’tforgetto Disable
Firewall ormustbe openthese portsonthe Firewall.
Check SQL server mirroring availability
We can checkSQL Servermirroringisrunningor bydifference steps:
1- port number listener:openCMD andwrite thisCommand”netstat -an” youwill see the
3 port forthe 3 ServersPrinciple–mirroring– WitnessalsoI see the 3 port because I
setupthe 3 SQL ServerInstance inthe same WindowsServer
Database Administration Community (https://mostafaelmasry.wordpress.com)
2- EventViewerforWindowsServer
3- SQL ServerDatabase Log
4- CheckEndpoint Status
Database Administration Community (https://mostafaelmasry.wordpress.com)
Add or replace witness server to an existing mirroring database
AfterI finishmyworkinDatabase MirroringwithoperationMode (highSafety).i exploreritwill notbe
Automaticfailoverbecause thisoptionif youneedityoumustconfigure yourmirroringwithoperation
mode (HighAvailabilitySynchronous) andthisOperationMode need3Servers(Principle ,Mirroring,
Witness) Soi will Shownow howtoadd or Replace mirroringDatabase WitnessServer
1- Nowthismy mirroringoperationmode it’shighsafetywithoutautomaticandthe witness
Servernotconfigured.
2- Clickon Configure Securityafterthismirroringwill Askyouif youneedtoConfigure Witness
Serveror notSelectyes
Database Administration Community (https://mostafaelmasry.wordpress.com)
3- CheckWitnessServer
4- Mirroringwill returnthe principle serverconfiguration
5- SelectWitnessServer
Database Administration Community (https://mostafaelmasry.wordpress.com)
6- Configure WitnessServerandthe port listener
7- Put ServicesAccount inmyexperience if youworkinginWorkgroupandyourall instance inthe
same windowslike thisexample create new userAdministratoronyourpc and addhimin SQL
Serverloginthe use it else if youuse Workgroupbutthe SQL Serversnotall inthe Same pc you
will use 3 Windowsor2 create CertificationinyourSQLServerandI will show itinthe nextpost
whoto create Mirroring WithLoginCertification.
Database Administration Community (https://mostafaelmasry.wordpress.com)
8- AfterthisStepClickfinishNoyourdatabase witnessisConfigured
Nowyour ConfigurationisComplete andif youcompare betweenimagesno8 andimage no 1 you will
see the difference youwill seenowwe have MirroringwithoperationmodehighsafetyWithAutomatic
failover
NOTE:
In Stepno6 you will See Iwrite the port no is5023 but wheni finishmyStepsandarrive to stepno8
thenclickon ok I reactive thisError:
TITLE: MicrosoftSQL ServerManagementStudio ——————————
AlterfailedforDatabase ‘ACC2012′. (Microsoft.SqlServer.Smo)
For help,click:onthislink
Database Administration Community (https://mostafaelmasry.wordpress.com)
——————————ADDITIONALINFORMATION:
An exceptionoccurredwhileexecutingaTransact-SQLstatementorbatch.
(Microsoft.SqlServer.ConnectionInfo)
——————————
The ALTER DATABASEcommandcouldnotbe sentto the remote serverinstance ‘TCP://IT-PC:5023′.The
database mirroringconfigurationwasnotchanged.Verifythatthe serverisconnected,andtryagain.
(MicrosoftSQL Server,Error:1456)
For help,click:onthislink
——————————BUTTONS:
OK ——————————
I don’tknowwhatis error I searchmore and more on the internetbut Idon’t foundgoodSolutionbut
whenI checkedthe SQLServerlog I see somethingsay{ SQL Servercannotlistentothe port No5023 }
So I Reconfiguredthe mirroringagainandChange the portfor the WitnessServerform5023 to 5024 it’s
Workingnowverygood
Database Administration Community (https://mostafaelmasry.wordpress.com)
How to monitor Database Mirroring:
I will monitordatabase mirroringfromManagementStudioandbyT-SQL
1- I will StopmirroringServertoinputtransactionintoPrinciple ServerandSee the logwhat
happenedinItGo to your database MirroringinPrinciple Server>> Write Click>>> tasks
>>>Lunch Database mirroringmonitor
2- Create Table onPrinciple Server andinsert10000 RecordintoNew table
CREATE TABLE TEST( A INT, B INT)
DECLARE @I INT=0
WHILE @I < 100000
BEGIN
INSERT INTO TEST VALUES(@I,@I)
SET @I=@I+1
END
SELECT COUNT(*) FROM TEST
Database Administration Community (https://mostafaelmasry.wordpress.com)
3- Nowrun the Scriptand insertthe Data thenlet’sgoto Checkthe monitortoSee whathappened
Database Administration Community (https://mostafaelmasry.wordpress.com)
4- ThenStart the mirroringServerandCheckthe Monitor again
Database Administration Community (https://mostafaelmasry.wordpress.com)
Check the database mirroring information:
SELECT M.database_id , D.Name , M.mirroring_state_desc ,
M.mirroring_role_desc,M.mirroring_partner_name , M.mirroring_partner_instance,
M.mirroring_witness_name , M.mirroring_witness_state_desc
FROM sys.database_mirroring as M inner join Sys.databases as D
on M.database_id = D.database_id
Where D.database_id > 4
Database Administration Community (https://mostafaelmasry.wordpress.com)
Mirroring in workshop not in DC (Domain Controller)
Nowif I have 3 Serverswith three SQLserverInstance butthisserversnottrusted= Notin domainthis
serversinworkgroupbut nowI won’tto create mirroringbut the laststepin MirroringConfiguration
needfromthe ServicesAccountWhatI will write andwithnotrusted.So what we can do to make these
serversistrusted.
Solution:
We will make linkbetweenthisSQLServerinstance thislinknotthe linkedserverfeature butthat’s
meaningwe will make masterkeyandCertificate onall ServersthenCreate usersinthe 3Serversthen
give grant ConnectiontothisUsersonthis MirroringEndpointExample
Servername Certification user
ServerA (Principle) CERT_A User_A
ServerB (Mirror) CERT_B User_B
ServerC (Witness) CERT_C User_C
 Now I create differenceCertificate and useronthe serversthenIwill
 Create Certificate ServerBand C onserverA
 Create Certificate ServerA andC on ServerB
 Create Certificate ServerA andB on ServerC
AlsoI make these Steps onuserthengive the 3 userin the ServerA and B and C grant Connectionon
MirroringEndpointbythisWay I make Bridge betweenthe 3Servers
1- Step 1 on Principle Server:
USE MASTER
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Admin123'
GO
CREATE CERTIFICATE Principle_cert
WITH SUBJECT = 'Principle certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE = STARTED
Database Administration Community (https://mostafaelmasry.wordpress.com)
AS TCP (LISTENER_PORT = 5025 , LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION = CERTIFICATE Principle_cert , ENCRYPTION=REQUIREDALGORITHM RC4 ,
ROLE=ALL)
GO
BACKUP CERTIFICATE Principle_cert
TO FILE ='C:certificatePrinciple_cert.cer'
GO
2- Step no 2 On Mirror Server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Admin123'
GO
CREATE CERTIFICATE Mirror_cert WITH SUBJECT = 'Mirror certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT= 5026,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION=CERTIFICATE Mirror_cert , ENCRYPTION = REQUIREDALGORITHM RC4 , ROLE=ALL)
GO
BACKUP CERTIFICATE Mirror_cert
TO FILE='D:certificateMirror_cert.cer';
GO
3- Step No3 on Principle Server:
Copythe Certificate”Mirror_cert”FromMirror Servertothe Principle Serverbecause IwillCreate the
Certificate MirroringServeronPrinciple Serverwiththe Username Mirror_user
USE MASTER
GO
Database Administration Community (https://mostafaelmasry.wordpress.com)
CREATE LOGIN Mirror_login WITH PASSWORD='Admin123'
GO
CREATE USER Mirror_user FOR LOGIN Mirror_login
GO
CREATE CERTIFICATE Mirror_cert
AUTHORIZATION Mirror_cert
FROM FILE='C:certificateMirror_cert .cer' -----the Path of your Certificate After you
Copy it
GO
GRANT CONNECTON ENDPOINT:End mirroringTO[Mirror_login] -----Giveprivilege tothe User
Mirror_loginto connectto the MirroringEndpoint”End_Mirroring“
GO
4- Step No4 on Mirror Server:
Copythe Certificate”Principle_cert ”From Principle Servertothe Mirror Serverbecause Iwill Create
the Certificate PrincipleServeronMirroringServerWiththe Username Principle user
USE MASTER
GO
CREATE LOGIN Principle_login WITH PASSWORD='Admin123'
GO
CREATE USER Principle_user FOR LOGIN Principle_login
GO
CREATE CERTIFICATE Principle_cert
AUTHORIZATION Principle_cert
FROM FILE='C:certificateMirror_cert.cer' ---the Path of your Certificate After you Copy
it
GO
GRANT CONNECTON ENDPOINT::EndMirroring TO [Principle_login] ——-Giveprivilege tothe User
Principle_logintoConnecttothe Mirroring Endpoint”End_Mirroring “
Database Administration Community (https://mostafaelmasry.wordpress.com)
5- Step No5 on WitnessServer:Create master Key and Certificate Witness_Cert
USE MASTER
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD='Admin123'
GO
CREATE CERTIFICATE Witness_cert
WITH SUBJECT='Witness certificate'
GO
CREATE ENDPOINT End_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT= 5027,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING
(AUTHENTICATION=CERTIFICATE Witness_cert,
ENCRYPTION = REQUIRED ALGORITHM RC4 , ROLE = Witness)
GO
BACKUP ERTIFICATE witness_cert
TO FILE='C:certificateWitness_cert.cer'
GO
6- Step No6 on Principle Server:
Copythe Certificate “Witness_cert ”From WitnessServertothe Principle Serverbecause Iwill Create
the Certificate WitnessServeronPrinciple ServerWiththe Username Witness_user
USE MASTER
GO
CREATE LOGIN Witness_login WITH PASSWORD='Admin123'
GO
CREATE USER Witness_user FOR LOGIN Witness_login
Database Administration Community (https://mostafaelmasry.wordpress.com)
GO
CREATE CERTIFICATE Witness_cert
AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login]
GO
7- Step No7 on Mirror Server:
Copythe Certificate”Witness_cert”FromWitnessServertothe Mirror Serverbecause Iwill Create the
Certificate WitnessServeronMirror Serverwiththe Username Witness_user
USE MASTER
GO
CREATE LOGIN Witness_login WITH PASSWORD='Admin123'
GO
CREATE USER Witness_user FOR LOGIN Witness_login
GO
CREATE CERTIFICATE Witness_cert
AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login]
GO
8- Step No8 on WitnessServer:
Copythe Certificate”Principle_cert ”From Principle Serverand ” Mirror_cert ” From the Mirror Server
” Principle_cert“
USE MASTER
GO
CREATE LOGIN Principle_login WITH PASSWORD='Admin123'
GO
CREATE USER Principle_user FOR LOGIN Principle_login
Database Administration Community (https://mostafaelmasry.wordpress.com)
GO
CREATE CERTIFICATE Principle_cert
AUTHORIZATION Principle_user
FROM FILE='D:certificatePrinciple_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Principle_login]
GO
” Mirror_cert “
CREATE LOGIN Mirror_login WITH PASSWORD=‘Admin123′
GO
CREATE USER Mirror_user FOR LOGIN Mirror_login
GO
CREATE CERTIFICATE Mirror_cert
AUTHORIZATION Mirror_user
FROM FILE='C:certificateMirror_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Mirror_login]
GO
9- take Full backup+ Log backupfrom yourDatabase Mirroringon Principle ServerthenGoto
MirroringServerand restore thisBackupWithNORECOVERYOption
10- GO TO the principle Serverinmake yourEasymirroringconfigurationbutinthe lastStepdon’t
write anyService AccountletitEmptythenAfterthisStepMirroringwill be Complete
Successfully
Thanks for all followers
Eng. Mustafa EL-Masry

More Related Content

What's hot

Making Money with RSS
Making Money with RSSMaking Money with RSS
Making Money with RSSgoodfriday
 
MySQL Scalability Mistakes - OTN
MySQL Scalability Mistakes - OTNMySQL Scalability Mistakes - OTN
MySQL Scalability Mistakes - OTNRonald Bradford
 
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groups
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability GroupsSQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groups
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groupsturgaysahtiyan
 
SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)Hamid J. Fard
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAUlf Wendel
 
Microsoft Azure, My First IaaS
Microsoft Azure, My First IaaSMicrosoft Azure, My First IaaS
Microsoft Azure, My First IaaSJohn Martin
 
SQL Server 2012 High Availability with AlwaysOn Availability Groups
SQL Server 2012 High Availability with AlwaysOn Availability GroupsSQL Server 2012 High Availability with AlwaysOn Availability Groups
SQL Server 2012 High Availability with AlwaysOn Availability GroupsEdwin M Sarmiento
 
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...SpanishPASSVC
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Maarten Balliauw
 
How to Make SQL Server Go Faster
How to Make SQL Server Go FasterHow to Make SQL Server Go Faster
How to Make SQL Server Go FasterBrent Ozar
 
FOSDEM 2015 - NoSQL and SQL the best of both worlds
FOSDEM 2015 - NoSQL and SQL the best of both worldsFOSDEM 2015 - NoSQL and SQL the best of both worlds
FOSDEM 2015 - NoSQL and SQL the best of both worldsAndrew Morgan
 
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...turgaysahtiyan
 
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionSQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionMark Broadbent
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringIDERA Software
 
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB
 
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Dave Stokes
 
Fundamentals of SQL Server 2012 Availability groups
Fundamentals of SQL Server 2012 Availability groupsFundamentals of SQL Server 2012 Availability groups
Fundamentals of SQL Server 2012 Availability groupsEdwin M Sarmiento
 
Sql server’s high availability technologies
Sql server’s high availability technologiesSql server’s high availability technologies
Sql server’s high availability technologiesvenkatchs
 

What's hot (19)

Making Money with RSS
Making Money with RSSMaking Money with RSS
Making Money with RSS
 
MySQL Scalability Mistakes - OTN
MySQL Scalability Mistakes - OTNMySQL Scalability Mistakes - OTN
MySQL Scalability Mistakes - OTN
 
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groups
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability GroupsSQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groups
SQLSaturday Bulgaria : HA & DR with SQL Server AlwaysOn Availability Groups
 
SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)
 
PoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HAPoC: Using a Group Communication System to improve MySQL Replication HA
PoC: Using a Group Communication System to improve MySQL Replication HA
 
Microsoft Azure, My First IaaS
Microsoft Azure, My First IaaSMicrosoft Azure, My First IaaS
Microsoft Azure, My First IaaS
 
SQL Server 2012 High Availability with AlwaysOn Availability Groups
SQL Server 2012 High Availability with AlwaysOn Availability GroupsSQL Server 2012 High Availability with AlwaysOn Availability Groups
SQL Server 2012 High Availability with AlwaysOn Availability Groups
 
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...
Configurando Aplicaciones para Réplicas de Lectura de SQL-Server AlwaysOn - C...
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
 
How to Make SQL Server Go Faster
How to Make SQL Server Go FasterHow to Make SQL Server Go Faster
How to Make SQL Server Go Faster
 
FOSDEM 2015 - NoSQL and SQL the best of both worlds
FOSDEM 2015 - NoSQL and SQL the best of both worldsFOSDEM 2015 - NoSQL and SQL the best of both worlds
FOSDEM 2015 - NoSQL and SQL the best of both worlds
 
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
 
Azure Powershell Tips
Azure Powershell TipsAzure Powershell Tips
Azure Powershell Tips
 
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionSQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database Mirroring
 
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
 
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
 
Fundamentals of SQL Server 2012 Availability groups
Fundamentals of SQL Server 2012 Availability groupsFundamentals of SQL Server 2012 Availability groups
Fundamentals of SQL Server 2012 Availability groups
 
Sql server’s high availability technologies
Sql server’s high availability technologiesSql server’s high availability technologies
Sql server’s high availability technologies
 

Similar to High availability solution database mirroring

Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroringwebhostingguy
 
Mirroring in SQL Server 2012 R2
Mirroring in SQL Server 2012 R2Mirroring in SQL Server 2012 R2
Mirroring in SQL Server 2012 R2Mahesh Dahal
 
MySQL HA Presentation
MySQL HA PresentationMySQL HA Presentation
MySQL HA Presentationpapablues
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql ServerRishikesh Tiwari
 
MySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue SolutionsMySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue SolutionsRapidValue
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 Enliufabin 66688
 
MySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoMySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoKeith Hollman
 
Sql interview question part 10
Sql interview question part 10Sql interview question part 10
Sql interview question part 10kaashiv1
 
Financial, Retail And Shopping Domains
Financial, Retail And Shopping DomainsFinancial, Retail And Shopping Domains
Financial, Retail And Shopping DomainsSonia Sanchez
 
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...Principled Technologies
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primaryKaizenlogcom
 
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsOUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsAndrew Morgan
 
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Continuent
 
Continuent Tungsten - Scalable Saa S Data Management
Continuent Tungsten - Scalable Saa S Data ManagementContinuent Tungsten - Scalable Saa S Data Management
Continuent Tungsten - Scalable Saa S Data Managementguest2e11e8
 
Java Abs Dynamic Server Replication
Java Abs   Dynamic Server ReplicationJava Abs   Dynamic Server Replication
Java Abs Dynamic Server Replicationncct
 
Building the perfect share point farm
Building the perfect share point farmBuilding the perfect share point farm
Building the perfect share point farmDavid Broussard
 
Netherlands Tech Tour 02 - MySQL Fabric
Netherlands Tech Tour 02 -   MySQL FabricNetherlands Tech Tour 02 -   MySQL Fabric
Netherlands Tech Tour 02 - MySQL FabricMark Swarbrick
 

Similar to High availability solution database mirroring (20)

Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
 
Mirroring in SQL Server 2012 R2
Mirroring in SQL Server 2012 R2Mirroring in SQL Server 2012 R2
Mirroring in SQL Server 2012 R2
 
MySQL HA Presentation
MySQL HA PresentationMySQL HA Presentation
MySQL HA Presentation
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql Server
 
MySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue SolutionsMySQL Database Replication - A Guide by RapidValue Solutions
MySQL Database Replication - A Guide by RapidValue Solutions
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
 
MySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoMySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & Demo
 
Sql interview question part 10
Sql interview question part 10Sql interview question part 10
Sql interview question part 10
 
Ebook10
Ebook10Ebook10
Ebook10
 
MySQL Tech Tour Nov, 2013
MySQL Tech Tour Nov, 2013MySQL Tech Tour Nov, 2013
MySQL Tech Tour Nov, 2013
 
Financial, Retail And Shopping Domains
Financial, Retail And Shopping DomainsFinancial, Retail And Shopping Domains
Financial, Retail And Shopping Domains
 
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...
Process 84% more MySQL database activity with the latest-gen Dell PowerEdge R...
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primary
 
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worldsOUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
OUG Scotland 2014 - NoSQL and MySQL - The best of both worlds
 
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
 
Continuent Tungsten - Scalable Saa S Data Management
Continuent Tungsten - Scalable Saa S Data ManagementContinuent Tungsten - Scalable Saa S Data Management
Continuent Tungsten - Scalable Saa S Data Management
 
Java Abs Dynamic Server Replication
Java Abs   Dynamic Server ReplicationJava Abs   Dynamic Server Replication
Java Abs Dynamic Server Replication
 
Ssn#14 reporting services part ii
Ssn#14  reporting services part iiSsn#14  reporting services part ii
Ssn#14 reporting services part ii
 
Building the perfect share point farm
Building the perfect share point farmBuilding the perfect share point farm
Building the perfect share point farm
 
Netherlands Tech Tour 02 - MySQL Fabric
Netherlands Tech Tour 02 -   MySQL FabricNetherlands Tech Tour 02 -   MySQL Fabric
Netherlands Tech Tour 02 - MySQL Fabric
 

Recently uploaded

Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 

Recently uploaded (20)

Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 

High availability solution database mirroring

  • 1. Database Administration Community (https://mostafaelmasry.wordpress.com) SQL Server Technical Article High Availability Solution Database Mirroring in SQL Server 2008 R2 Writer: Mustafa EL-Masry Technical Reviewer: SQLSERVER Performance tuning (http://sqlserver-performance-tuning.net/) Published: Jan 2015 Applies to: SQL Server 2008 R2, 2012 Slide Share: http://www.slideshare.net/MostafaElmasry3 About The Writer I am Mustafa El-MasrySeniorDatabase administratorandDB Analyst I am ExpertDatabase performance tuning, Ihave deeppractical knowledge aboutT-SQLperformance,HW Performance issues,Data Warehousinganddatamart solutions,SQLServerReplication,Clustering solutions(Active Activeandactive passive)andDatabase Designsfor differentkindsof systems,HAG,divingdeeplymore : I am Founderof Community:SQL DATABASEADMINISTRATION:http://mostafaelmasry.wordpress.com/ Linkedin: https://www.linkedin.com/in/mostafaelmasry My CommunityAnnual report : https://mostafaelmasry.wordpress.com/2014/annual-report/ I am Technical Writerand Reviewer:http://www.slideshare.net/MostafaElmasry3/ I am Audience MarketingManager and Executive Board member:SQLSERVER PERFORMANCE TUNING http://sqlserver-performance-tuning.net/ One HundredPOST :http://sqlserver-performance-tuning.net/?p=5244 FluentParticipator at MicrosoftForums of SQL Serverat http://Social.technet.microsoft.com More than +175 Post in SQL Server Technology: http://sqlserver-performance-tuning.net/?p=4526 MicrosoftProfile:https://www.mcpvirtualbusinesscard.com/VBCServer/EngMostafaElamsry/profile
  • 2. Database Administration Community (https://mostafaelmasry.wordpress.com) Agendaand overview 1- IntroductionaboutDatabase MirroringConcept 2- Reference (8Blogs) 3- Note 4- Database mirroringoperationmode 5- Database MirroringRequirement 6- Advantage of Database Mirroring 7- Disadvantage of Database Mirroring 8- Database MirroringEnhancementinSQL Server2008 9- Database MirroringInstallationStepbyStep 10- HighAvailabilityMode [AutomaticFailover] 11- HighAvailabilityMode [Manual Failover] 12- HighSafetyMode Withoutwitnessserver[Manual Failover] 13- Standerlistenerportindatabase mirroring 14- CheckSQL servermirroringavailability 15- Addor replace witnessservertoan existingmirroringdatabase 16- How to monitorDatabase Mirroring 17- Mirroringin workshopnotinDC (DomainController)
  • 3. Database Administration Community (https://mostafaelmasry.wordpress.com) Introduction and overview Database mirroringisa primarilysoftware solution forincreasingdatabase availability.Mirroringis implementedona per-database basisandworksonlywithdatabasesthatuse the full recoverymodel. The simple andbulk-loggedrecoverymodelsdonotsupportdatabase mirroring.Therefore,all bulk operationsare alwaysfullylogged.Database mirroringworkswithanysupporteddatabase compatibility level. Database mirroringisusedbyMicrosoft SQL Server,arelational database managementsystem (RDBMS) designedforthe enterpriseenvironment.Twocopiesof asingle database reside ondifferent computerscalled serverinstances,usuallyinphysical locationsseparatedbysome distance.The principal (orprimary) serverinstance providesthe database toclients.The mirror(orsecondary) server instance actsas a standbythat can take overin case of a problemwiththe principal serverinstance.
  • 4. Database Administration Community (https://mostafaelmasry.wordpress.com) Reference Note  In database mirroring section you have 3 servers (principle, mirroring, and witness)  The database will be in the principle server and the application will be connect to the principle server then you will take backup (Full + log) from the database in the principle server the make restore to this backup with no recovery option in the mirroring server so the record will copy from the principle server to the mirror server.  Witness server will be monitoring to the principle and the mirroring server.  You can setupthe principle serverindomainandthe mirroringserverinanotherdomain What happensif the principle serverdown in highavailabilitymode? If the principle serverdownthe mirroringserverwill be the new principle serverandthe applicationwill be connectautomaticallytothe newprinciple server(mirroringserver) What happenedwhenthe applicationconnect to the database in the principle server? Whenthe Applicationconnecttothe principle serverandusersmake anytransactiononthisdatabase the record will write inlogpuffermemoryinprinciple serverthenwrite it inlogfile indatabase thenthe logpuffersendthe recordto the log puffermemorytothe mirroringserverthenthe logpufferwrite this record in log file in database. Then the mirror server send to the principle server massage to know the principle the transaction is succeed then the principle tell the application the transaction is succeed. Mirroring in SQL Server (8/8) Mirroring in SQL Server (7/8) Mirroring in SQL Server (6/8) Mirroring in SQL Server (5/8) Mirroring in SQL Server (4/8) Mirroring in SQL Server (3/8) Mirroring in SQL Server (2/8) Mirroring in SQL Server (1/8)
  • 5. Database Administration Community (https://mostafaelmasry.wordpress.com) Database mirroring operation mode You can setupthe mirroringserverin3 modes 1. High availability. In highavailabilityyouneed3servers (principle server,mirroringserver,witness server) sointhisoperationmode the applicationconnectonthe principle server thenthe transactionwrite inlogfile then the principle serversendthe recordtothe mirrorserverinlog file the mirrorsendto the principle (the recordiscommit) then the principle sendtothe applicationthe transactioniscommitted 2. High safety. In highsafetymode we don'tneedtothe witnessserverwe willneedinthissectiontothe principle serverandthe mirrorserveronlysothere'sno automaticfailoverinhighsafetymode. Andthe operationwill be same inthe highavailabilitymode[applicationconnectonthe principle serverthenthe transactionwrite inlogfile thenthe principle serversendthe recordto the mirror serverinlog file the mirrorsendtothe principle (therecordiscommit) thenthe principle sendtothe applicationthe transactioniscommitted] Remarks: the difference betweenhighavailabilitymode andhighsafetymode isAutomatic failoverinhighavailability will foundAutomaticfailoverbutinhighsafetywill notfound Automaticfailover.Soif the principle serverdownyouhave problembecause youwillmake manuallystart The mirroringservertobe principle server.Notlike inhighavailabilitymode thisoperation make automaticallybecause thisoperationmodehave automaticfailover. 3. High performance. In highperformance mode youneed2server(principle server,mirrorserver) like highsafety mode . So the differencebetweenthe highperformancemode andhighsafetymode isinhigh performance the applicationsendthe transactiontothe principle serverinlogfile thenthe principle sendthe recordtothe mirrorserverand sendtothe applicationthe transactionis committedsothe principle server don'twaitthe mirrorserverlike (highsafetymodeandhigh availabilitymode)
  • 6. Database Administration Community (https://mostafaelmasry.wordpress.com) Operation mode servers Automatic failover Principle wait the mirror High availability 3 servers Yes Yes High safety 2 servers No Yes High performance 2 servers No No In the finale Iexplainwhatismirroring?,whatisthe operationmode inmirroring?,whatisthe difference betweenoperationmode inmirroring?,rememberItell youhighsafetyandhigh performance notneedwitnessserverbutyoucan create witness serverinthisoperationmode butit will make problemswhityousodon'tmake witnessserverinhighsafetymode andhighperformance mode Database MirroringRequirement  The database and file locationshouldbe same.  Collectionandmastercode page shouldbe same inthe principle andmirrorserver.  Database name shouldbe same inthe principle andmirrorserver.  You cannot mirrormore the 10 databasesin32 bitserversyoucan in64 bitserverbutnot recommended.  You cannot use attach/de attach you can use backup andrestore.  Portsin mirroringshouldbe openinginfirewall orclose the firewall.  ServicesaccountInSQL and SQL agentshouldbe same in all servers.  The mirroringnot supportthe cross database transaction& distributedtransactionlog  SQL servernumbershouldbe same butyoucan setupprinciple serveronSQLServer2008 service pack1 andthe mirroron SQL Serverservice pack2.
  • 7. Database Administration Community (https://mostafaelmasry.wordpress.com) Advantage of Database Mirroring 1- Doesnot require special hardware (suchassharedstorage,heart-beatconnection) andcluster ware,thuspotentiallyhaslowerinfrastructure cost 2- Database mirroringsupportsfull-textcatalogs 3- Hardware and software upgrade that'sveryeasy. Remark: If youwant upgrade the mirrorserverfromSQL server2008 R2 todenial youmust pass the mirroringinthissectionthenafterupgrade startthe mirroringagain 4- Increasesthe dataprotection(disasterrecovery). 5- Increasesthe database availabilityif youuse the Syncmode. 6- Cost of database mirroringislessthanclustering. 7- It's robustand efficientthanlogshippingandreplication. 8- Failoverisfastcompare to cluster 9- Mirror servercan be usedto host databasesforotherapplicationsnotlike clustering. Disadvantage of Database Mirroring 1- Mirroringdoesn'tsupportfile stream. 2- Mirror serverisnot available fordatabase readonly. 3- Mirror serverworkingindatabase level notinserverlevelnotlike clustering(inclustering failover youmake thisinserverlevelonall database inthisserverinloginsinjobslike this) Database Mirroring Enhancement in SQL Server 2008 1) Database mirroringautomatic page repair.  If a page on the principle ormirrorserveriscorrupt,it isautomaticallyreplacedwith the correspondingcopyonitspartner  Some page typescannotbe automaticallyrepaired:  File headerpages  Database boot page  Allocationpages 2) CompressedData flow  Data Flowbetweenthe principle andmirrorserverisnow compressedtoimprove performance. 3) Manual Failover  Manual failovernolongerrequire adatabase restart 4) Log performance  log-sendbuffers  Page read-ahead  Write-aheadonthe incominglogstreamonthe mirrorserver Reference:http://www.sqlserver-training.com/database-mirroring-enhancements-in-sql-server-2008- from-2005/-
  • 8. Database Administration Community (https://mostafaelmasry.wordpress.com) Database Mirroring Installation Step by Step Let's start to setupmirroringserverinSQLserver2008 R2 in the firstI will setupSQLServer2008R2 with three instance 1. Principle instance(SQLSERVER2008R2A) 2. Mirroringinstance (SQLSERVER2008R2B) 3. WitnessInstance (SQLSERVER2008R2C)  In myexample I will make mirroringtype highavailability(Synchronize mode)  In principle serverIwill create database Mirroring_DB  Take full backupMirroring_DB.bak  thentake log TransactionbackupMirroring_DB.trn  Make restore tothisbackup full mirroringserver withNorecoveryoption  Thenright clickonMirroring_DB >>Tasks>>Restore>>TransactionLog  ThenSelectyourtransactionlogbackup(Mirroring_DB.trn)  Don’tforgetrestore withnorecoveryoption
  • 9. Database Administration Community (https://mostafaelmasry.wordpress.com) High Availability Mode [Automatic Failover] Principle Server  Rightclick on database Mirroring_Db >> tasks >> Mirror >> Configure Security  You will ask if you wantto setup witness server or not? selectyes.  Then you will ask to selectyour principle server [connect to Elmasry-PCPrinciple]and make the port is 5021 and the endpointname is Principle then Click next  You will ask again to selectyour Mirroring server [connectto Elmasry-PCMirroring]and make the port is 5022 and the endpointname is mirroring then click next.  You will ask again to selectyour witness server [connectto Elmasry-PC]and make the port is 5023 and the endpointname is Witness then click next .  In this step he will ask you to put your user name in your windows and this user mustbe add in the SQL Server so I write my username is [mypc namewindows username][Elmasry-PCElmasry].then click finish  SQL server after you click finish itwill make configuration to the Principle Server , Mirroring Server , Witness Server  After this configuration is finish SQL server will give you massage if you want to Start mirroring or not selectstart and Waite few mints then mirroring will startand you see the status is [Synchronized: the databases are fully synchronized]  Nowgo to make refreshtothe servers[principle - mirroring]
  • 10. Database Administration Community (https://mostafaelmasry.wordpress.com) Principle Server[Elmasry-PCPrinciple] 1- Create Table Name Employee CREATE TABLE Employee (Emp_Id INT NOT NULL PRIMARY KEY IDENTITY, Emp_Name NVARCHAR(50) NOT NULL, Tel NVARCHAR(12) NULL) 2- Insert data in this table INSERT INTO dbo.Employee ( Emp_Name, Tel ) VALUES ( N'Mostafa', -- Emp_Name - nvarchar(50) N'0172788327' -- Tel - nvarchar(12) ) , ('Mohamed' , '015876565645') 3- Nowif you selectdatafromEmployee Table youwill see2rows 4- Rightclickon the principle serverandmake stoptothe server Mirroring Server[Elmasry-PCMirroring] 1- Refreshthe server(youwillsee the database change frommirroringtoprincipledatabase andif youopenthe database you will see the Employee table andthe 2 rows 2- Nowtry to insertinthistable another2 rows
  • 11. Database Administration Community (https://mostafaelmasry.wordpress.com) INSERT INTO dbo.Employee ( Emp_Name, Tel ) VALUES ( N'Omar', -- Emp_Name - nvarchar(50) N'0172788327' -- Tel - nvarchar(12) ) , ('Kemo' , '015876565645') 3- Stopthe serverandstart the principle server[Elmasry-PCPrinciple] youwill seethe database is mirroringmake stopto the Mirroringserver[Elmasry-PCMirroring] youwill see the difference the mirroringdatabase inthe principle serverwill change toPrinciple severandif youopenthe Employee table youwillsee 4rowsnot 2 because the 2 rowsyou insertintodatabase in mirroringservertransferautomaticallytoanotherserver Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisverygoodthat’sis manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same operationbyyourhand : 1- Go to principle serverthenrightclickandselecttasks>>> Mirror 2- ThenClickon Failoveryouwill seethe massage Clickyes 3- Thenmake refreshtothe serveryouwill see the change
  • 12. Database Administration Community (https://mostafaelmasry.wordpress.com) High Availability Mode [Manual Failover] Before Istart to explainMirroringHighSafetymode Iwill explainsomethingisvery goodthat’sis manual FailoverYesyoucan make manual failoverinthe previousExampleImake Failover(meaning change the serverprinciple will be the mirroringandthe mirroringwillbe the principle) Imake this operationbutAutomaticallywhenImake stoptothe serverandthisoperationmake Automatically because Imake mirroring[HighAvailability] butinthe manual failoveryoucanmake the same operation by yourhand :  Go to principle serverthenrightclickandselecttasks>>>>> Mirror  ThenClickon Failoveryouwill seethe massage Clickyes  Thenmake refreshtothe serveryouwill see the change High Safety Mode Without witness server [Manual Failover] In Highsafetymode if the principle serverdownthe mirroringwill be disconnectbutif youwantto make the mirroringDB is principle DBinhighAvailabilitySQLServermake thisoperationAutomatically because inthismode youhave AutomaticFailoverbutdon’tworryyoucan make thisbycode [Ilisten someone tell me Whywe can'tmake the mirroringisprinciple byManual failoverItell himbecause the mirroringmode ishighsafetyandthe principle serverisdownsothe mirroringserverisdisconnectedso if you make rightclickon the mirroringDB thenSelecttasksthenmirroryouwill see the buttonof FailoverisDisable]sowe have one choice orone way to make the MirroringDB isprinciple DBto allow the applicationtoconnectThisWay is ByCode let'sstart to explainthe Mirroring[HighSafetyMode]
  • 13. Database Administration Community (https://mostafaelmasry.wordpress.com) Principle Server[Elmasry-PCPrinciple] 1- Rightclickon mirroringdatabase >>>> tasks>>>> Mirror 2- Delete the servernetworkaddresstothe witnessserver.automaticyouwillsee the SQLserver change your mode fromhighavailabilitymode tohighsafetymode >>>>> clickok . 3- Rightclickon the principle server>>>> thenselectstop. 4- The serverwill be down Mirroring Server[Elmasry-PCMirroring] 1- Refreshthe MirroringServer 2- You will see the database [Mirroring_DB] isDisconnected/inrecovery. 3- NowI will Execute SQLStatementonmasterdatabase inmirroringseverthisstatementwill change the mirroring_DBfrom mirrorto principle USE master GO ALTER DATABASE Mirroring_DB SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS 4- If you make start to the Principle server[Elmasry-PCPrinciple] youmustgoto the Mirroring Severandright clickonMirroring_Db >>>Tasks >>>>Mirror >>>> Make resume toreturn the mirrorto work. 5- HighPerformance Mode like HighSafetymode butif youwantto know the difference between highsafetymode andhighperformance mode see partno1
  • 14. Database Administration Community (https://mostafaelmasry.wordpress.com) Stander listener port in database mirroring If we will buildthe entire instance (Principle,mirroring,Witness) inthe same serveratthistime you shoulduse difference portsExample:  Principle Serveruse the Standerportnumber5021  MirroringServeruse the Standerport number5022  WitnessServeruse the Standerportnumber5023 But if youwill builditindifference serversyoucanuse one port like: 5021 butdon’tforgetto Disable Firewall ormustbe openthese portsonthe Firewall. Check SQL server mirroring availability We can checkSQL Servermirroringisrunningor bydifference steps: 1- port number listener:openCMD andwrite thisCommand”netstat -an” youwill see the 3 port forthe 3 ServersPrinciple–mirroring– WitnessalsoI see the 3 port because I setupthe 3 SQL ServerInstance inthe same WindowsServer
  • 15. Database Administration Community (https://mostafaelmasry.wordpress.com) 2- EventViewerforWindowsServer 3- SQL ServerDatabase Log 4- CheckEndpoint Status
  • 16. Database Administration Community (https://mostafaelmasry.wordpress.com) Add or replace witness server to an existing mirroring database AfterI finishmyworkinDatabase MirroringwithoperationMode (highSafety).i exploreritwill notbe Automaticfailoverbecause thisoptionif youneedityoumustconfigure yourmirroringwithoperation mode (HighAvailabilitySynchronous) andthisOperationMode need3Servers(Principle ,Mirroring, Witness) Soi will Shownow howtoadd or Replace mirroringDatabase WitnessServer 1- Nowthismy mirroringoperationmode it’shighsafetywithoutautomaticandthe witness Servernotconfigured. 2- Clickon Configure Securityafterthismirroringwill Askyouif youneedtoConfigure Witness Serveror notSelectyes
  • 17. Database Administration Community (https://mostafaelmasry.wordpress.com) 3- CheckWitnessServer 4- Mirroringwill returnthe principle serverconfiguration 5- SelectWitnessServer
  • 18. Database Administration Community (https://mostafaelmasry.wordpress.com) 6- Configure WitnessServerandthe port listener 7- Put ServicesAccount inmyexperience if youworkinginWorkgroupandyourall instance inthe same windowslike thisexample create new userAdministratoronyourpc and addhimin SQL Serverloginthe use it else if youuse Workgroupbutthe SQL Serversnotall inthe Same pc you will use 3 Windowsor2 create CertificationinyourSQLServerandI will show itinthe nextpost whoto create Mirroring WithLoginCertification.
  • 19. Database Administration Community (https://mostafaelmasry.wordpress.com) 8- AfterthisStepClickfinishNoyourdatabase witnessisConfigured Nowyour ConfigurationisComplete andif youcompare betweenimagesno8 andimage no 1 you will see the difference youwill seenowwe have MirroringwithoperationmodehighsafetyWithAutomatic failover NOTE: In Stepno6 you will See Iwrite the port no is5023 but wheni finishmyStepsandarrive to stepno8 thenclickon ok I reactive thisError: TITLE: MicrosoftSQL ServerManagementStudio —————————— AlterfailedforDatabase ‘ACC2012′. (Microsoft.SqlServer.Smo) For help,click:onthislink
  • 20. Database Administration Community (https://mostafaelmasry.wordpress.com) ——————————ADDITIONALINFORMATION: An exceptionoccurredwhileexecutingaTransact-SQLstatementorbatch. (Microsoft.SqlServer.ConnectionInfo) —————————— The ALTER DATABASEcommandcouldnotbe sentto the remote serverinstance ‘TCP://IT-PC:5023′.The database mirroringconfigurationwasnotchanged.Verifythatthe serverisconnected,andtryagain. (MicrosoftSQL Server,Error:1456) For help,click:onthislink ——————————BUTTONS: OK —————————— I don’tknowwhatis error I searchmore and more on the internetbut Idon’t foundgoodSolutionbut whenI checkedthe SQLServerlog I see somethingsay{ SQL Servercannotlistentothe port No5023 } So I Reconfiguredthe mirroringagainandChange the portfor the WitnessServerform5023 to 5024 it’s Workingnowverygood
  • 21. Database Administration Community (https://mostafaelmasry.wordpress.com) How to monitor Database Mirroring: I will monitordatabase mirroringfromManagementStudioandbyT-SQL 1- I will StopmirroringServertoinputtransactionintoPrinciple ServerandSee the logwhat happenedinItGo to your database MirroringinPrinciple Server>> Write Click>>> tasks >>>Lunch Database mirroringmonitor 2- Create Table onPrinciple Server andinsert10000 RecordintoNew table CREATE TABLE TEST( A INT, B INT) DECLARE @I INT=0 WHILE @I < 100000 BEGIN INSERT INTO TEST VALUES(@I,@I) SET @I=@I+1 END SELECT COUNT(*) FROM TEST
  • 22. Database Administration Community (https://mostafaelmasry.wordpress.com) 3- Nowrun the Scriptand insertthe Data thenlet’sgoto Checkthe monitortoSee whathappened
  • 23. Database Administration Community (https://mostafaelmasry.wordpress.com) 4- ThenStart the mirroringServerandCheckthe Monitor again
  • 24. Database Administration Community (https://mostafaelmasry.wordpress.com) Check the database mirroring information: SELECT M.database_id , D.Name , M.mirroring_state_desc , M.mirroring_role_desc,M.mirroring_partner_name , M.mirroring_partner_instance, M.mirroring_witness_name , M.mirroring_witness_state_desc FROM sys.database_mirroring as M inner join Sys.databases as D on M.database_id = D.database_id Where D.database_id > 4
  • 25. Database Administration Community (https://mostafaelmasry.wordpress.com) Mirroring in workshop not in DC (Domain Controller) Nowif I have 3 Serverswith three SQLserverInstance butthisserversnottrusted= Notin domainthis serversinworkgroupbut nowI won’tto create mirroringbut the laststepin MirroringConfiguration needfromthe ServicesAccountWhatI will write andwithnotrusted.So what we can do to make these serversistrusted. Solution: We will make linkbetweenthisSQLServerinstance thislinknotthe linkedserverfeature butthat’s meaningwe will make masterkeyandCertificate onall ServersthenCreate usersinthe 3Serversthen give grant ConnectiontothisUsersonthis MirroringEndpointExample Servername Certification user ServerA (Principle) CERT_A User_A ServerB (Mirror) CERT_B User_B ServerC (Witness) CERT_C User_C  Now I create differenceCertificate and useronthe serversthenIwill  Create Certificate ServerBand C onserverA  Create Certificate ServerA andC on ServerB  Create Certificate ServerA andB on ServerC AlsoI make these Steps onuserthengive the 3 userin the ServerA and B and C grant Connectionon MirroringEndpointbythisWay I make Bridge betweenthe 3Servers 1- Step 1 on Principle Server: USE MASTER GO CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Admin123' GO CREATE CERTIFICATE Principle_cert WITH SUBJECT = 'Principle certificate' GO CREATE ENDPOINT End_Mirroring STATE = STARTED
  • 26. Database Administration Community (https://mostafaelmasry.wordpress.com) AS TCP (LISTENER_PORT = 5025 , LISTENER_IP=ALL) FOR DATABASE_MIRRORING (AUTHENTICATION = CERTIFICATE Principle_cert , ENCRYPTION=REQUIREDALGORITHM RC4 , ROLE=ALL) GO BACKUP CERTIFICATE Principle_cert TO FILE ='C:certificatePrinciple_cert.cer' GO 2- Step no 2 On Mirror Server: USE master GO CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Admin123' GO CREATE CERTIFICATE Mirror_cert WITH SUBJECT = 'Mirror certificate' GO CREATE ENDPOINT End_Mirroring STATE=STARTED AS TCP (LISTENER_PORT= 5026,LISTENER_IP=ALL) FOR DATABASE_MIRRORING (AUTHENTICATION=CERTIFICATE Mirror_cert , ENCRYPTION = REQUIREDALGORITHM RC4 , ROLE=ALL) GO BACKUP CERTIFICATE Mirror_cert TO FILE='D:certificateMirror_cert.cer'; GO 3- Step No3 on Principle Server: Copythe Certificate”Mirror_cert”FromMirror Servertothe Principle Serverbecause IwillCreate the Certificate MirroringServeronPrinciple Serverwiththe Username Mirror_user USE MASTER GO
  • 27. Database Administration Community (https://mostafaelmasry.wordpress.com) CREATE LOGIN Mirror_login WITH PASSWORD='Admin123' GO CREATE USER Mirror_user FOR LOGIN Mirror_login GO CREATE CERTIFICATE Mirror_cert AUTHORIZATION Mirror_cert FROM FILE='C:certificateMirror_cert .cer' -----the Path of your Certificate After you Copy it GO GRANT CONNECTON ENDPOINT:End mirroringTO[Mirror_login] -----Giveprivilege tothe User Mirror_loginto connectto the MirroringEndpoint”End_Mirroring“ GO 4- Step No4 on Mirror Server: Copythe Certificate”Principle_cert ”From Principle Servertothe Mirror Serverbecause Iwill Create the Certificate PrincipleServeronMirroringServerWiththe Username Principle user USE MASTER GO CREATE LOGIN Principle_login WITH PASSWORD='Admin123' GO CREATE USER Principle_user FOR LOGIN Principle_login GO CREATE CERTIFICATE Principle_cert AUTHORIZATION Principle_cert FROM FILE='C:certificateMirror_cert.cer' ---the Path of your Certificate After you Copy it GO GRANT CONNECTON ENDPOINT::EndMirroring TO [Principle_login] ——-Giveprivilege tothe User Principle_logintoConnecttothe Mirroring Endpoint”End_Mirroring “
  • 28. Database Administration Community (https://mostafaelmasry.wordpress.com) 5- Step No5 on WitnessServer:Create master Key and Certificate Witness_Cert USE MASTER GO CREATE MASTER KEY ENCRYPTION BY PASSWORD='Admin123' GO CREATE CERTIFICATE Witness_cert WITH SUBJECT='Witness certificate' GO CREATE ENDPOINT End_Mirroring STATE=STARTED AS TCP (LISTENER_PORT= 5027,LISTENER_IP=ALL) FOR DATABASE_MIRRORING (AUTHENTICATION=CERTIFICATE Witness_cert, ENCRYPTION = REQUIRED ALGORITHM RC4 , ROLE = Witness) GO BACKUP ERTIFICATE witness_cert TO FILE='C:certificateWitness_cert.cer' GO 6- Step No6 on Principle Server: Copythe Certificate “Witness_cert ”From WitnessServertothe Principle Serverbecause Iwill Create the Certificate WitnessServeronPrinciple ServerWiththe Username Witness_user USE MASTER GO CREATE LOGIN Witness_login WITH PASSWORD='Admin123' GO CREATE USER Witness_user FOR LOGIN Witness_login
  • 29. Database Administration Community (https://mostafaelmasry.wordpress.com) GO CREATE CERTIFICATE Witness_cert AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer' GO GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login] GO 7- Step No7 on Mirror Server: Copythe Certificate”Witness_cert”FromWitnessServertothe Mirror Serverbecause Iwill Create the Certificate WitnessServeronMirror Serverwiththe Username Witness_user USE MASTER GO CREATE LOGIN Witness_login WITH PASSWORD='Admin123' GO CREATE USER Witness_user FOR LOGIN Witness_login GO CREATE CERTIFICATE Witness_cert AUTHORIZATION Witness_user FROM FILE='C:certificateWitness_cert.cer' GO GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Witness_login] GO 8- Step No8 on WitnessServer: Copythe Certificate”Principle_cert ”From Principle Serverand ” Mirror_cert ” From the Mirror Server ” Principle_cert“ USE MASTER GO CREATE LOGIN Principle_login WITH PASSWORD='Admin123' GO CREATE USER Principle_user FOR LOGIN Principle_login
  • 30. Database Administration Community (https://mostafaelmasry.wordpress.com) GO CREATE CERTIFICATE Principle_cert AUTHORIZATION Principle_user FROM FILE='D:certificatePrinciple_cert.cer' GO GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Principle_login] GO ” Mirror_cert “ CREATE LOGIN Mirror_login WITH PASSWORD=‘Admin123′ GO CREATE USER Mirror_user FOR LOGIN Mirror_login GO CREATE CERTIFICATE Mirror_cert AUTHORIZATION Mirror_user FROM FILE='C:certificateMirror_cert.cer' GO GRANT CONNECT ON ENDPOINT::End_Mirroring TO [Mirror_login] GO 9- take Full backup+ Log backupfrom yourDatabase Mirroringon Principle ServerthenGoto MirroringServerand restore thisBackupWithNORECOVERYOption 10- GO TO the principle Serverinmake yourEasymirroringconfigurationbutinthe lastStepdon’t write anyService AccountletitEmptythenAfterthisStepMirroringwill be Complete Successfully Thanks for all followers Eng. Mustafa EL-Masry