0% found this document useful (0 votes)
47 views16 pages

8.database Mirroring

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
47 views16 pages

8.database Mirroring

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 16
oO RPALcation Fs Rerdling Raust 4 the Sarwar - Sal © steft the mecliPeation tr the chomep oRU wecaded Evanscction cal yrme Seren abeays bouPRer pool « cohen he. change Fla Geoted the Gn the log Pile eueny time. Chom de, chenge ig ete wie tothe ames. ern sh ia Shove es Hore, oe - : od Ha | module sDatabase Mirroring | O° dro TE mae | CA 18 Aepe Th coil pe, @s esincitad ts akonys cog faite mise actnowledgmont-Tereheen dato Ig Were ty Seisererdi rt 13 ther Fy both the (erNeng) Database Mirroring: Introduction Mirroring Architecture ® Asuneknaus, edo RUD tha Availoloilthy Cartomabic Pelee & High PerPsirrenca yy Buncipd, moose] anos oe GHD Uph Paolection Cro Actor esvevesi] : Peunipal, mises Pour Rad G MUBBL. Itis another high availability feature available from SQL sev 203) Previous versions support the simple high availabilty feature called Transaction Log-Shipping. Log Shipping has its own limitation as it doesn’t support automatic failover as well as there might be data loss. All these limitation we can overcome with database mirroring. Ravinder (SQL DBA Training with 6+ real time experience)Page 1 dfhovte bf Database mirroring supports automatic failover and the transactions are applied to standby (Mirror) server immediately once they are committed at principle server. Like Log-Shipping no need of backup, copy and restore operations and jobs. Points to remember > In Principal server database is in ONLINE state > In mirror server database is in a restoring state, which means itis not available for incoming requests. > However , we can create a database snapshot of the mirror database, which provides a point-in- time ready-only view of the database. Advantages and Benefits: > Protection against database fallures. > Automatic failure detection and failover. Support of easy manual failover. Automatic client redirection. Multiple operating modes, No special hardware requirements Minimized chance of data loss Relatively ease of set up and configuration. vyvyvy 7 Mirroring Operating Mode , Synchronous oe ye ‘High availability (High safety with automatic failover) io v * Principal , Mirror and witness. “supports automatic failover. High protection * Principal, mirror * No automatic failover Asynchronous: y v *High Performance * Principal , Mirror * No automatic failover Ravinder (SQL DBA Training with 6+ real time experience)Page 2 FAQ;- How to create mirroring feature in SS 2005 RTM? Requirements 1. SQL Server 2005 with SP1 or SQL Server 2008 2. Database should be in FULL recovery model. 3. Service broker be enabled on the database. 4, Both the servers should have same version of SQL server. 5. Both the servers should have the same edition. 6. Witness server can have any edition. 7. Database name should be same on both the servers Configuring Mirroring ~Steps 1. Create mirror database a. Take full and T.Log back up from principal server and restore it in mirror server with NORECOVERY 2. Establish mirroring session using ALTER DATABASE command Steps: 1. Gotossms 2. Connect 2 or 3 instances For examples Ravinder-PC\sqi2008R2 - Principal Ravinder-PC \Practice - Mirror Ravinder-PC\Sample : Witness a Ravinder (SQL DBA Training with 6+ real time experience) Page 3 ee SLSR ana ia New Quey Oy BRS A G he File Edit View Debug Tools Window Community Help Object planet 5 Se 4 Connecty 33 3 as ig {B Ravinder-P Czample (SQL Server 10.50.1600 - Ravinder-PO\RaW 1 C5 Databases 1 (2) Security (8 E Server Objects 1 [5 Replication i i LQ Management : 1B SQL Server Agent (Agent XPs disabled) i 8 (i Ravinder P\practice (SQL Server 10.501600- Ravinder POR 3 Cy Databases oC Security © Server Objects & C5 Replication & [5 Management Gh SOL Sever Agent (Agents dables) | | al @ [23 Databases a C2 Security @ GG Server Objects 1 CS Replication 12 Cl Management (B SQL Sener Agent (Agent xPs deablec) 3.Note down the above instances service accounts a, Ravinder-PC\sql2008R2 - Ravinder-PC\Ravinder . Ravinder-PC \Practice - Ravinder-PC\Ravinder ¢. Ravinder-PC \Sample - Ravinder-PC\Ravinder 4. Verify both principal and mirror has same editions or not i.e, Enterprise or Standard, By running the following command in both the servers select serverproperty(‘edition 5, Go to principal server and create a sample database (in real time environment we have to use existi database) with the name SAMPLE, Ravinder (SQL DBA Training with 6+ real time experience)Page 4 6. Create one sample table in the database with some rows 7. Take FULL and Transaction Log backup of SAMPLE database in principal server, Use master €0 backup database SAMPLE to disk=" €:\backupfolder\full \SAMPLE_Full-bak’ go \backupfolder\log\sample_log.trn’ Backup log to SAMPLE to dis eo. 8, Go to mirror server and create a folder with name D:\Backupsfolder and grant read write permission to service account. Restore database by using the Recovery State WITH NORECOVERY Restore database SAMPLE from disk=" E:\backupfolder\ full \SAMPLE_Full.bak™ with move 'SAMPLE' to 'E:\Data\SMAPLE.mdf,, move 'SAMPLE_LOG' to'E:\Data\SMAPLE_log,.Idf", norecovery Restore log SAMPLE from disk=" E:\backupfolder\log\Sample_log.trn’ with norecovery 0 9. To configure the mirroring follow the below steps. 110. Goto Principal Server —» Right click on database SAMPLE —> Tasks—> Mirroring Ravinder (SQL DBA Training with 6+ real time experience)Page 5 © (2 Datebeses 1 [9 System Databases {3 Database Snapshots e [g Adal [Jada & [J kumar BQ prasad aU 1B Ca Security Nev Database... Ga Server Obj New Query a Revaton | _ScotDutabase as» © 5G Manegemel (B SaLSererd Tasks Bring Online Poiicies >| Shrink LE Facate Back Up.. Stor PowerShell Restore 7 Reports » Mivor. : Launch Database Mirroring Monitor. 111, Click on Configure Security —» Click Next [Ear gene Bsave © Chin rasetharsecty crud for ug ts dba, ae DD Ravinder (SQL DBA Training with 6+ real time experience)Page 6 1 Configure Database Micring Secity Wears » Configure Database Mirroring Security Wizard ‘Th wiz elp you cone the secuty set gsformrotng datbese SAMPLE” PP, Youean ee the ward corfu sooty stings onthe 2 tontg sever: the prc sererinsence the moor servrisiance the ness seventies lpn) [1 Oaret show the arin nage agen Next 12, Select Yes if you have witness instance otherwise select No. ‘TL Ceatigut OsGbace Mirroring Secungy Include Witness Server ‘Speci whether to nude a inees sarverin the eecurly corfigution. To operato database mirceng in syctveneu made with automatic afover, you must corfigure 2 hvthege server stance to anwar he tus of the Papel ne mtr suivernsances She Stl the fever. Do yeu want te configure secur to nchide 8 wines server instance? (Yee Ravinder (SQL. DBA Training with 6+ real time experience)Page 7 13. Next Next 14, Select principal instance Next 15. Click on Connect Select Mirror Server instance name (e.g. Ravinder-PC\Practice) Click on Next izard (sie st dus Configure Database Miercring Security Mirror Server instance ‘Speciy information about the seaver instance where the miror copy ofthe databace wil . be located, Mirror server instance: [| spear : i sean Microsoft! «| &~ SQL Server'2008 R2 Sf so ican ogre ‘Server name: ¥ si Atherton |Ravnde-PC Ravinder yO Cape) Cae (Tine) Cate) 16. Select Connect Next 17. Once again click on Connect button select Witness Server instance name (Ravinder-PC\Sample) [) Next 18, Enter service accounts. SUP TEr TTI T===a===F Er aC IC RnR ener ener eameeineeeeememeean! Ravinder (SQL DBA Training with 6+ real time experience)Page 6 BTL al BSSwEw, Servite Account 12 Syne trie Mak acarnfs TLR ok Same, cveateone Ale ramp Habito 3 Lovey q one Ie hee. 4. Configure Database Mirroring Security Wizard Service Accounts ‘Specly the service accounts ofthe server instances, Fer SQL. Server agcounts inthe same domain or rusted domains, spac the service accounts below. the accounts are nen-doman scecurts orthe accounts ave n uninieted domama, eave te textboxes enoty. Service accounts forthe folowing instances: Principal Ravinder BO\Bavinder ino: Fovinder ‘ter you specty the service accounts, logins willbe created for each eecount, Fnecessay, and willbe ‘rented CONNECT pemiasion onthe endpomnts Configuring Endpoints ick Sep tote the onan, > 3 Taal 0 Ere @ swecess 3 Soces 0 Wferng Data: [aden Siu Wage @ Configuing endpoint on pineal serverRav... Success @ Configuring endpoint on miner aervertPavind., Success @ Configuing endpoint on winess serverfiav... Success Ravinder (SQL DBA Training with 6¢ real time experience)Page 9 20. Close. 21, Select “Do Not Start Mirroring”. 22, Select Start Mirroring 5 Ovtabae roperies- SAMPLE Selecta nage 3 3 et + Gent Sst ~ Kier Bae Biemos sett etiam dears ogee Gare Tskng Bronesene Sevetreokcadttsn <= —— a 2 See Pes : Et aan Peat eri $B teecton ep Sor Soe Tea Ca re eremdar Poi te: ay tad TCP acts. Fr era: TCP cop acon SID2 pears rote ———-——~ = S Hh pfamanee ects) - Caen ange lie pan eer oe estos Hive nth aden vs rts) - Rina soe event ce. Cant tron bah ‘Sipmepaandmrarftchon sete hewn cose saonacaone tenet epimers | Sever ftom Faeroe Comics See eee eee Fame Fo Ronde Ss Hinddabn hart i (84 Mew cennacien pees Preiss Ready Ravinder (SQL DBA Training with 6+ real time experience)Page 10 23. Check the status OK 4 Database Prope: «SAMPLE Selectapoxe See + See Bee ie Zee Ean rath sears crest mtrai dalbese ; Zo Sito Tetra SE sometrs Snernatote sree Bicester ince Tor rise Ban 1 Temeacbon Lop Shopng Mee TePY/RawederPCSO2S ene: TePyiRaveden PSI ete: Une uty uated TEP aeteszes For ware: TCP fence abecon tae Opemting moe High pademance fryntveneue) Cora change tha nepal and than tantr thats the ine — Mon ant nde cena nt arc, Cot hr i Cet oe eee te crete ee ee Se sowie Seis etna Someston, Rounder 2Oavedar Progress Ready maT CT Point to Remember 1. One job is created on both the servers. Database Mirroring Monitor Job 2. Default Partner Timeout is 10sec. 3. How can you say that both the principal and mirror are 100% sync? a. We can view unsent log and un restored log values. If both are 0 then 100% sync. {In Mirroring Monitor) We can view Mirroring Failover LSN and Replication LSN with sys.database_mirroring, Both should be same. 4.Mirroring States 4. synchronizing 2. synchronized Ravinder (SQL DBA Training with 6+ real time experience)Page 11 3. Disconnected (If mirror or principal failed) 4, Suspended (if the principal is un available or unable to send transactions to mirror) 5, Pending Failover — if the unsent log is > 0 5. To change mirroring timeout ( Run is principal server) Alter database SAMPLE set PARTNER TIMEOUT 20 Monitoring Mirror PODLAIshm? pmendcmn ZLGBOURER ‘* We can monitor mirroring using the following options SBTNOALANT *Using MSDB tables and Views {ONE * Using Database Mirroring Monitor * Using Performance Monitor * Using Profiler 1. Using MSDB tables and Views * ToView complete details of mirroring (In Pri pal Server) Select * from sys.database_mirroring * ToView mirroring endpoint details { In Principal Server) Select * from sys.database_mirroring_endpoints *To View about Principal , mirror server details and mirroring state run the following query in witness server. Select * from sys.database_mirroring_witnesses 2.Using Database Mirroring Monitor ‘we can monitor the following features © Unsent Log (at principal) © Un restored Log (at micror) © Transaction Rate ‘© Commit overhead {transaction applies rate at mirror) EX: Go to Principal server and run the following query Ravinder (SQL DBA Training with 6+ real time experience)Page 12 © OBee SulferPClogspece) © lack yews, tog rrevee tomte clone earn, SK. dataloages @ Becher lag kumcoue 40 dises). with Staleaio Use SAMPLE Go Declare @n int=100 While @n<= 1000000 Begin Insert intoemp values (@n, ‘Ramesh’ , 60) Set @n=@ne1 End Right click on SAMPLE db Tasks. launch Database Mirroring Monitor Select "Database Mirroring Monitor” 4d. Click on Register Mirror databases . Click on Connect and select Mirror Server {. Select on database SAMPLE--> OK g. Observe the parameter by refreshing (f5) the monitor, Configuring Thresholds * Goto Mirroring Monitor’ Select “Warnings” tab “Set Thresholds. © Using performance Monitor a. We can monitor the following counters for Mirrored databases *We can use the performance object called “instance Name>:Database Mirroring” *Counters which we have to observe regularly “Bytes sends/sec “Log Harden time (Commit overhead) “Total sends/sec “Transaction delay (Principal) “Pages Sends/sec Steps 1. Start run sperfmon Ravinder (SQL DBA Training with 6+ real time experience)Page 13 | sireccma | anes jeg | | . occa eee Performing Fail Over 1. Fail Over process depends on Operating Modes 2. Ifthe operating mode is “High safety with automatic failover” then witness server makes mirror db online automatically within the configured timeout 3, Incase of other operating modes we have to perform fail over manually In High Performance se Qoretsd crash) 2. Run the following command in mirror server ALTER DATABASE SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS 2. Transfer the logins 3, Make the database available to the users and applications. In High Protection 2, Run the following commands in Mirror Server ALTER DATABASE SET PARTNER OFF;{To break mirroring) 2. Database comes into restoring state run the following command to take it online RESTORE DATABASEWITH RECOVERY Ravinder (SQL DBA Training with 6+ real time experience)Page 14 How to use Mirror database for reporting purpose in mirroring high availability: Ans: We can't run the queries on mirror database because the database always in recovery or restore mode. So, we need to create the snapshot of the mirror database which will allow the users to use the database for reporting purposes. Draw back snapshot database is, this can't updated as time to time. It is only static data. Query to create snapshot database of mirror database: ‘CREATE DATABASE Raju007 ON (NAME = raju, FILENAME ="C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\DATA\raju1123.mdf"} [AS SNAPSHOT OF raju Go Weveukg Brussg— 1 tchon tPe mince. datohae datePile ag Lop Ale derives oe. Filled xp thon chia SyncknBliscltan astbl not hapeon TY misraing AAI, Senso AU Crake Ho Joy Ale Hue Me oPate ieua In Principe) Saver as debris rob DP Rowan mle crcage ble so Princsal % rivers ditto Arwicall upPodes Bon Nghe. Dyyoa coll be Cote Tnahls cae esrcotlh Pablorr ast nico dean - vesdie Hames fife: Ravinder (SQL DBA Training with 6+ real time experience)Page 15 ) ooIng carte. Rbgaoup Frthe Pruircipe\ Abt All lac Mbpsing TP aedert have cBnsPrdig rnlbreig dbeds Pr Boh tha Sewer, C crek Re 0. abe “tn cme Bat] © Ppphying seowices packs oS ULL go Br Rasloven. Cpounhin] Monud Lalovos oe thigh pearance - IN Cop £ Manual Rates. . tem pBecrly ore choraig . Hap Pea feunewce. to High ckeky cotttout auchomte Paibien TEN Odfaloase in Synchwonug rnede , eB Evo tromsecHion 1s aucprtically opdare ants. rmnioo bPex But ee ee tra athe. pererromce 3 slows oe Stal a ddan. TE ales, doe bo coms to lie Fon his cage People eoilh Pace ReoPomrarce 19scn Weisediat eect Chie pry [Reewsey— Bacaye of Frying ts OPI Has comploke date eo com fea p Re [Pause ) button TE reve ouch He niet. Buck Kee? aur tramacting axa routed » © FE complate Log dave "fall Rome rete. q tke Leg baker % cata Corba. mivibirg

You might also like