SQL Server Database Mirroring

74
Proprietary of Rafael - Advanced Defense Systems.Ltd. ךךךךך ךךךךךךך1 Database Mirror for the exceptional DBA ךךך ךךךך ךךך"ך – ךךךךךך ךךךךך ךךךךךךך ךך"ך[email protected] 4.4.2011

Transcript of SQL Server Database Mirroring

Page 1: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd. 1סימוכיןתאריך

Database Mirror for the exceptional DBA דוד יצחק

רפא"ל – מערכות לחימה מתקדמות בע"מ[email protected]

4.4.2011

Page 2: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Rafael Advanced Defense Systems

• Designs, develops, manufactures and supplies a wide range of high tech defense systems for air, land, sea and space applications.

• Sales in 2010 exceeding $1851M

• About 7000 Employees

Page 3: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Speaker Qualifications• SQL Server , Oracle , Sybase ,Sybase

Anywhere - application & infrastructure DBA .

• 14 years of SQL experience, starting with version 6.5

• Education : –BSC (Information System Engineer) –MBA–Currently ME (System Engineering)

Page 4: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Agenda

• Database Mirroring Architecture Short Overview• Automating Setup using T SQL & SQLCMD or Power shell• Monitoring and Alerting• What Next I Expect in Denali• Planning (T&E) and Best Practices.• Resources• Next Session (?) :

– Reporting Considerations– Merge Replication and Database Mirror as a combined solution– Database Mirroring and failover Cluster combination– .Net coding with Database Mirror

Page 5: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Key Terms-1• Principal:

– Source of the mirroring. – Can mirror one or more databases on a single SQL Server instance to

another SQL Server instance.– You mirror a database, not a subset of the database

• Mirror: – The recipient of the mirroring from the principal DB server. – Kept in hot standby mode cannot be used directly in any way. – In continuous “restore” mode.– Physical transaction records are continuously applied to this mirror database.– Not available for direct DB usage - exception is creating DB snapshots

Page 6: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Key Terms- 2• Witness

– Optional Server that monitor the principal and mirror servers to provide a quorum

• Partner – Opposite server when referring to the principal and mirror

servers

• Endpoint – Bound to a network protocol– Allows SQL servers to communicate across the

network.

Page 7: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Key Terms - 3• Session

– Active relationship between the servers involved in DB mirroring – Allows them to maintain server state information about one another

• Roles – Possible roles:

1. Witness role—Can be any edition of a SQL Server (even SQL Server Express).

2. Principal role

3. Mirror role– After a failure, the mirror server takes over the principal

role, and the roles reverse.

•  

Page 8: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Key Terms - 4• Role Switching

– Active relationship between the servers involved in DB mirroring

– Allows them to maintain server state information about one another

– The act of transferring the principal role to the mirror server.• When a failure occurs :

– Principal role is switched to the mirror server– DB is brought online as the principal DB

Page 9: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Copy-on-Write Technology

Principle DB

2.transaction is written to principal server’s transaction log

Principle Server Mirror ServerMirror DB

1 .Client

transaction

2. Log record Copied to mirror server over Network I

*Mirror DB is exactly the same as the Principal DB

4 .acknowledgment to principal server of its write success

3.physical log record is written to the mirror DB

Page 10: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

DB Mirror High Performance

3. Write the data to transaction log and commit the data

Mirror

1. Write the data to transaction log and commit the data

Principle2. Send the transaction to mirror

4. Send Acknowledgement to principle

Page 11: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

DB Mirror High Safety with Witness

3. Write the data to transaction log and commit the data

Mirror

1. Write the data to transaction log

Principle2. Send the transaction to mirror

4. Send Acknowledgement to principle

5. Commit the data

Page 12: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Database Mirroring Operating Modes: Sync/ Async

• Synchronous operations– Committed transaction is committed on both partners of

the database mirroring pair. – Ensure Zero Data loss.– Add some latency cost - it is across two servers.– Possible performance issues on slower networks. – Recovery is Faster – no uncommitted trans to be

applied/undone – Failover can be automatic. – High-safety modes use synchronous operations.– Enterprise/Standard Edition.

Page 13: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Database Mirroring Operating Modes: Sync/ Async

• Asynchronous operations– Transactions commit without waiting for the mirror

server to write the log to disk. – Can increase performance but chance of some data

loss.– Enterprise Edition Only . – Manual failover only. – High-performance mode uses asynchronous

operations.

Page 14: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Flow to determine the operating Mode for DB

Page 15: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Operating Modes

Mode Risk of data loss Transport Description

High Availability

Mode

Zero Data LossDouble Failure

ProtectionSYNC

High safety with automatic failover &witness

High Protection

Mode

Zero Data LossSingle Failure

ProtectionSYNC

High safety without automatic failover ,without witness

High performance

Potential forMinimal Data Loss

ASYNCPrinciple never waits for mirror

acknowledgement

Page 16: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Database Mirroring Operating Modes in SSMS

Page 17: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Database Mirroring Operating Modes: Sync/ Async

• Asyns / Sync depends on the transaction safety setting. – Control this setting through SAFETY option when

configuring with T-SQL.– The default for SAFETY is FULL (synchronous

operations).– Set it to OFF for asynchronous operations. – With mirroring wizard, this option is set for you

automatically.

ALTER DATABASE $(MirrorDatabaseName) SET SAFETY OFF /ON

Page 18: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Failover variations 1 Automatic failover: high-availability mode

– Enabled with a three-server configuration: principal, mirror, witness server.

– Mirror DB must already be synchronized (Sync with the transactions as they are being written to the principal).

– Role switching is done automatically.

Page 19: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Failover variations 2 Manual failover: high-protection mode

• No witness server & you are using synchronous operations.

• The principal and mirror are connected to each other• Mirror DB is synchronized. • Role switching is done manually.• High safety without automatic failover mode.• You are making the decision to start using the mirror

server as the principal (no data loss).

•  ALTER DATABASE $(MirrorDatabaseName) SET SAFETY FULLALTER DATABASE $(MirrorDatabaseName) SET PARTNER FAILOVER

Page 20: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Failover variations 3Forced service

– Mirror server being available but possibly not synchronized.

– Mirror server can be forced to take over when the principal server has failed.

– Possibly means data loss because the transactions were not synchronized.

– For high safety without automatic failover mode (high-protection mode) or high-performance mode.

Page 21: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

---Run the ALTER DATABASE databaseName SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS SET @strSQL = 'ALTER DATABASE ' + @strDatabaseName + ' SET PARTNER OFF' EXEC sp_executesql @strSQL SET @strSQL = 'RESTORE DATABASE ' + @strDatabaseName + ' WITH RECOVERY' EXEC sp_executesql @strSQL PRINT 'Bringing ' + @strDatabaseName + ' ONLINE'

OR ALTER DATABASE <DatabaseName> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS

Failover variations 3Forced service

Page 22: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Rafael Choice

• Asynchronous mirroring without automatic failover .

• Mirroring asynchronously (high-performance mode)

• Failover is performed manually.

• when you respond to a failure, you can make a decision as to whether to fail over all databases to the mirroring partners or simply try to resolve the failing database.

Page 23: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Steps to Set Up DB mirroringIn General

1. Create endpoints on all of the instances.

2. Create a login for the service accounts of the other instances if they do not exist.

3. Grant connect permissions to the service accounts of the other instances on the endpoint.

4. Set the principal partner for the mirror database on the mirror partner.

Page 24: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Steps to Set Up DB mirroring In General

5. Set the mirror partner for the principal database on the principal partner.

6. If using a witness server, set the witness partner on the principal partner to enable automatic failover.

7. If not using a witness server, you may want to change the operating mode from “High safety (synchronous)” to “High performance (asynchronous).

 

Page 25: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup – 3 options

• T-SQL with SPs and linked servers

• Alternatives - script creates a connection to each server– T SQL with sqlcmd & CONNECT command . – PowerShell . – I will show option T SQL with sqlcmd

Page 26: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

T-SQL with SPs & linked servers disadvantage

• Create linked servers to allow MSSQL run commands against both partners and witness.

SET @PrincipalServer = @@ServerName SET @CurrDBName = DB_NAME() SET @EPName = 'MirroringEndPoint' -- Make sure linked server to mirror exists EXEC @Results = dbo.dba_ManageLinkedServer @ServerName = @ MirrorServer, @Action = 'create' IF @Results <> 0 BEGIN RETURN @Results; END

Page 27: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup – PowerShell 1

– PowerShell has the ability to load and use .Net objects.

– Load the SMO objects into PowerShell and use them

directly in the script.

– The SQL Team separated some of the SMO functions into separate DLLs in SQL Server 2008.

– The script checks the internal version of SMO and loads the SMOExtended object if you are using the SQL Server 2008 version of SMO.

– Disadvantage: SSMS support partially debugging Power Shell. Need editor.

 

Page 28: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup – PowerShell 2

Page 29: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup – PowerShell 3

Page 30: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup – PowerShell 4

Page 31: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Automating Setup - SQLCMD

– Command-line utility – Next generation of the isql and osql utilities– Can use variables within sqlcmd input files or scripts.– Admins have a lot of scripts each performs its own

functions on a specific server. – Consolidate into a single script using the :CONNECT

command.

Page 32: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Sqlcmd - Example 1 with variables

-- Set here Principal Server name :setvar PrincipalServer "userWXP.domain.local"--Set DBs names to DB mirroring (Principal databases) .

:setvar MirrorDatabaseName "AdventureWorks"--Set backup directory on principal server .:setvar BackupDirectory "D:\Database_Mirroring“

--Make a connection to Principal Server using Windows Authentication

:CONNECT $(PrincipalServer)GOBACKUP DATABASE [$(MirrorDatabaseName)] TO DISK='$(BackupDirectory)\$(MirrorDatabaseName).bak' WITH INIT;Go

Page 33: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Sqlcmd - Example 2 with variables file

/* Script variables */:r "d:\jobs\mssql\db_env.sql"/* End Of Script variables */

:CONNECT $(PrincipalServer)GOBACKUP DATABASE [$(MirrorDatabaseName)] TO DISK='$(BackupDirectory)\$(MirrorDatabaseName).bak‘ WITH INIT;

Go

Page 34: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Prepare the Database for MirroringSQLCMD Version

– Make sure the compatibility level is 90 - the min level required for database mirroring.

– If < 90, sets the compatibility level to the highest setting supported by the version of SQL Server.

– Make sure the database is using the Full Recovery model.

– If not changes the recovery model to Full .

Page 35: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Prepare the Database for MirroringSQLCMD Version

SELECT @Compatibility = D.compatibility_level, @RecoveryModel = D.recovery_model, @MirrState = DM.mirroring_state FROM sys.databases D INNER JOIN sys.database_mirroring DM ON DM.database_id = D.database_id WHERE D.database_id = @DBID IF @MirrState IS NOT NULL BEGIN RAISERROR('Database [%s] is already configured for mirroring on server [%s].', 16, 1, @DBName, @Server); RETURN; END IF @Compatibility < 90 …ELSE IF @MaxCompat >= 100 -- SQL Server 2008+ …IF @RecoveryModel <> 1 -- Full Recovery Model

Page 36: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Procedure to failover from/to Principal/mirror ServerSQLCMD Version

/* Script variables */:r "D:\jobs\mssql\db_env.sql“--Detects any DB that fit the criteria . --Issues the failback command one at a time for each DB .

USE [master]GOSELECT DB_ID(N'$(MirrorDatabaseName)') AS [Database ID];GOIF EXISTS (SELECT 1 FROM sys.database_mirroring WHERE database_id=DB_ID(N'$(MirrorDatabaseName)') AND mirroring_role_desc = 'PRINCIPAL') ALTER DATABASE $(MirrorDatabaseName) SET SAFETY FULLGO SELECT DB_ID(N'$(MirrorDatabaseName)') AS [Database ID];GOIF EXISTS (SELECT 1 FROM sys.database_mirroring WHERE database_id=DB_ID(N'$(MirrorDatabaseName)') AND mirroring_role_desc = 'PRINCIPAL') ALTER DATABASE $(MirrorDatabaseName) SET PARTNER FAILOVERGO

11.1&11.2

Page 37: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

 Database mirroring status table : dbm_monitor_data table

– Undocumented table in msdb .

– sp_dbmmonitorupdate creates, updates, truncates the database mirroring status table.

– DB Mirroring Monitor Job creates this table - Automatically the first time a database mirroring status update occurs.

– DB Mirroring Monitor & DB Mirroring Monitor Job call sp_dbmmonitorupdate system sp

– Frequently of updates ? • Depends on the method used and the configuration

settings.

Page 38: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

 Database mirroring status table :  select * from msdb.dbo.dbm_monitor_data order by local_time

desc

Query the db m

irrorin

g status table on

both the prin

cipal server a

nd the m

irror

server.

redo_rate is alw

ays 0 on the prin

cipal

server - does not re

do transactio

ns.

Page 39: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Database Mirroring Monitor Job 1

• Update the DB mirroring monitor table (sp_dbmmonitorupdate system sp)

• Default schedule is to run once a minute

• Can change from 1 to 120 minutes.

• If SQL Server Agent is disabled, Job cannot run.

• Created automatically when you start a database mirroring session using SSMS or T SQL

Page 40: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Database Mirroring Monitor Job 2

• sp_dbmmonitoraddmonitoring • Creates the Job with a default schedule to run every

minute.• Example: Create a new Database Mirroring Monitor

Job that runs every 10 minutes.– EXEC sp_dbmmonitoraddmonitoring 10

• sp_dbmmonitordropmonitoring • Drop the job. • No parameters • Example:

– EXEC sp_dbmmonitordropmonitoring

Page 41: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Database Mirroring Monitor Job 3

• sp_dbmmonitorchangemonitoring: • update the interval in which an existing Database

Mirroring Monitor Job will run. • 2 parameters

– Parameter argument is 1, which means update– period, followed by the new update interval for the value

argument.

• Example: run every 15 minutes.– EXEC sp_dbmmonitorchangemonitoring 1, 15

 

Page 42: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Understanding Warning Thresholds 1

• Events that are written to the Windows Event Log whenever the threshold exceeded.

• Can configure alerts to fire based on the error numbers for these events:

• Unsent log (error number 32042): – Number of kilobytes in unsent logs that can accumulate

on the principal server before this event is raised. – Important– Communication issue between partners ( high-

performance mode )– In high-safety mode if DB mirroring has been paused.

 

 

Page 43: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Understanding Warning Thresholds 2

 • Unrestored log (error number 32043):

• Configure the number of kilobytes in unrestored logs accumulated on the mirror server before this event is raised.

• Determine the amount of time it will take to roll forward the log on the mirror server in failover.

• Generally because the I/O subsystem on the mirror server cannot keep up with the logs coming from the principal server.

Page 44: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Understanding Warning Thresholds 3

• Oldest Unsent transaction (error number 32040):

• Number of minutes worth of transactions that can accumulate in the send queue on the principal server before this event is raised.

• Communication issue between partners - high-performance mode

• In high-safety mode if DB mirroring has been paused.

Page 45: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

  Understanding Warning Thresholds 4

• Mirror commit overhead (error number 32044): – Configure the number of milliseconds in the

average transaction delay that can be tolerated on the principal server before this event is raised.

– The time the principal server waits for the mirror server to write a transaction to the redo queue - only relevant in high-safety mode

 

Page 46: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 1

• Refreshes status every 30 sec (async connections to principal &mirror servers).

• Member of the dbm_monitor db role in MSDB (not sysadmin server role) have to wait for the data to be updated by the DB Mirroring Monitor Job

• Step 1: Registering Mirrored Databases• Step 2: Performing Health Checks

 

Page 47: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 2

Page 48: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 3

• Principal log : status of principal server as of the time displayed

• Unsent log– Num of kilobytes waiting in the send queue.

• Oldest unsent transaction– Oldest transaction in the send queue waiting to be sent to the

mirror server – Amount of potential data loss (in time) in the event of a failure.

• Time to send log (estimated):– Estimate for the amount of time for the principal server to transmit

transactions in the send queue to the mirror server.

Page 49: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 4

• Current send rate– Rate in kilobytes transactions are being sent to the mirror server. – Current rate of new transactions

• Current rate of new transaction– Rate in kilobytes of new transactions being written to the log on

the principal

Page 50: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 5

• Mirror log: status on the mirror server as of the time displayed in

 • Unrestored log

– Num of kilobytes waiting in the redo queue.

 • Time to restore log (estimated):

– Estimate time for mirror server to apply the transactions waiting in the redo queue to the mirror DB.

 • Current restore rate

– Rate in kilobytes that transactions are being restored to mirror DB.

 

Page 51: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Using the Database Mirroring Monitor 6

• Mirror commit overhead– Only for high-safety mode. – Num of milliseconds of average delay per transaction you can

accept while the principal server waits for a transaction to write to the redo queue on the mirror server before a warning is generated on the principal server.

 • Time to send and restore all current log (estimated):

– Estimated time to send and restore all of the transactions that have currently been committed on the principal server to the mirror server.

– Can be less than “Time to send log (estimated)” + “Time to restore log (estimated)”

– Because these are parallel operations.

Page 52: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Monitoring using system SP sp_dbmmonitorresults

Directly returning rows from DB mirroring status table. • Parameters:

– @database name: limits the result set to a single database.– @mode: Optional parameter that specifies the number of rows

returned by the result set.– The required input is an integer value between 0 and 9.

• • 0: Last row• • 1: Last 2 hours• ......• • 8: Last 1,000 rows• • 9: Last 1,000,000 rows or essentially all rows

•  – @update_table : Optional parameter

• 1 or 0 that determines whether the DB mirroring status table is updated before returning the result set.

Page 53: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Monitoring using system SP sp_dbmmonitorresults

EXEC sp_dbmmonitorresults

@database_name = N'adventureWorks',

@mode = 6,

@update_table

=

Page 54: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Managing Warning Thresholds using system SP 1

• Instead of the Database Mirroring Monitor• 3 SPs configure, view, and remove

warning thresholds: • sp_dbmmonitorchangealert, • sp_dbmmonitorhelpalert• sp_dbmmonitordropalert.

Page 55: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

   Managing Warning Thresholds using system SP 2

--Warn if the unset log exceeds the the threshold in KBexec sys.sp_dbmmonitorchangealert @database_name=N'$(MirrorDatabaseName)',@alert_id=2,@threshold = @enable_send_queue, @enabled = 1;

--Warn if the unrestored log exceeds the the threshold in KBexec

sys.sp_dbmmonitorchangealert @database_name=N'$(MirrorDatabaseName)',@alert_id=3,@threshold = @redo_queue, @enabled = 1;

--Warn if the age of the oldest unset transaction exceeds the threshold in minutes

exec sys.sp_dbmmonitorchangealert @database_name=N'$(MirrorDatabaseName)',@alert_id=1,@threshold = @time_behind, @enabled = 1;

--Warn if the mirror commit overhead exceeds the threshold in milliseconds

exec sys.sp_dbmmonitorchangealert @database_name=N'$(MirrorDatabaseName)',@alert_id=4,@threshold

= @average_delay, @enabled = 1;

Page 56: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Top wait Events Checks Network Waits DB mirror

= @average_delay, @enabled = 1;

Action Script

Run the query and analyze according the following

SELECT TOP 15wait_type, wait_time_msFROM sys.dm_os_wait_statsWHERE wait_type NOT IN('LAZYWRITER_SLEEP', 'SQLTRACE_BUFFER_FLUSH','REQUEST_FOR_DEADLOCK_SEARCH', 'LOGMGR_QUEUE','CHECKPOINT_QUEUE', '__EVENT','WAITFOR','BROKER_TASK_STOP', 'SLEEP_TASK', 'BROKER_TO_FLUSH')

ORDER BY wait_time_ms DESC

Page 57: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Top wait Events Checks Network Waits DB mirror 2

= @average_delay, @enabled = 1;

Network Waits: Explanation Action DBMIRROR_SEND indicate that the available

bandwidth is insufficient to support the volume of mirrored transactions occurring on the server. It can also indicate database mirroring oversubscription. .

If multiple DBs are mirrored, try reducing the number of mirrored databases, or increasing the network bandwidth by upgrading to a higher-speed adapter.

When troubleshooting network waits, it can be beneficial to also investigate the configurationsettings of the network adapter as well. Ensure that the server and client adapter settings match as closely as possible. Utilize full duplex and the maximum bandwidth settings available on the adapterTo monitor network adapter performance, the following network performance counterscan be collected:➤ Network\Current bandwidth➤ Network\bytes total/sec➤ Network\packets/sec

Page 58: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Real-time Queries

Principle DB

Continuous redo shipping, validation & apply

Real-time Reporting

Fast Incremental Backups

• Use fast backups on mirror DB• More than 1 mirror DB destination to improve DRP

Fast Backups

• Offload read-only queries to an up-to-date Mirror DB

Real-time Reporting

Mirror DB

What Next I Expect in DenaliOffload Processing– Improve Primary Performance!

Read-writeWorkload

Page 59: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Disasters happen every day...its a fact !

• Disasters cost money so why suffer by being unprepared?

• Organizations that survive typically have:

– management foresight– tested Processes &

procedures– back-up facilities

– A PLAN!!

Page 60: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Disaster Recovery Process

LAN/WAN

שחזור מטייפ גיבוי יכול לקחת ימים ••Data Centric Environments DRP ” אחרי אירועMean Time To Recoveryצמצום “•

Production Site Disaster Recovery Site

)redirect(

)resync backwards after source restoration(

X

Page 61: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Sample mirroring deployment Plan

Time Step Detail Step Duration

8:00 p.m.Disable all SQL jobs and

scheduled tasks3 min.

Verify that the database is using Full Recovery and do not

support Filestream2 min.

Create full backup of database 3 min.

Copy and restore full backup on mirror server

5 min.

Create transaction log backup of database

2 min.

Copy and restore transaction log backup on mirror server

5 min.

Page 62: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Sample mirroring deployment Plan

Time Step Detail Step Duration

Deploy new configuration files to web site and web service

Enable all SQL jobs and scheduled tasks

Install database mirroring maintenance procedures

Give testers green light to begin testing

Page 63: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

רי מי ה

ד"ר ע

קורס

T&E

הנדסת מערכת

יון טכנ

Page 64: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

מדדים )RTO (Recovery Time Objective

הזמן המרבי עד לחזרתה של המערכת לתפקוד מלא עבור תהליכים עסקיים שונים

)RPO (Recovery Point Objective הזמן המרבי שלגבי ניתן לאבד מידע . כמות המידע שהארגון מוכן לאבד ? יום שלם ,

מספר שעות /דקות אפס אבל RPO אבל לא תלוי בו (מערכות מסחר RTOמשתנה באותה סקלה כמו

RTO. (גדול יותר

Service Level Agreement MTTF(Mean Time Between Failure) , MTTRבהקשר לזה מדברים על זמינות ,

(Mean time To recover)

) High availabilityזמינות גבוהה (יכולת של המשתמש לגשת למערכת לצורך אחזור נתונים בכל עת

downtimeחוסר זמינות=

Page 65: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Riskמדדים : ניתוח סיכונים(Analysis (

תהליך לאיתור סיכונים צפויים ביישום תהליך או •מוצר חדש.

כולל הערכת ההסתברות וההשפעה הצפויה, •ודרכי התגובה, של כל סיכון על מנת לגדר אותו

ככל האפשר.רמת הסיכון נקבעת על בסיס המכפלה של •

"הסיכוי לתקלה "ו"עוצמת התקלה":•Risk Level = Probability*Impact

Page 66: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

תעדוף באתר חלופי – DRPכשבונים אתר •

קובעים את סדר השחזור לפי רמת החשיבות של המערכות

אילו מערכות לא ישוחזרו•רמת השירות שתינתן במסגרת אילוצי •

מצב חירום

Page 67: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

מדדי ביצועים

MOPs MOSs MOEs CI

פירוט מערכות באתר חלופי סדר

עליה

מהו סדר הקמת המערכות באתר החלופי

?DRPבאירוע

האם לכל האתר הראשי יש גיבוי באתר המשני ?

RPOערך מספרי - כמה מידע יכולים לאבד ?

האם אפשר לאבד מידע ?

RTOערך מספרי - תוך כמה זמן אתר חלופי ?DRPפעיל ב-

האם האתר DRPהחלופי ב-

מתפקד במהירות?

Page 68: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

מדדי ביצועים

MOPs MOSs MOEs CI

פירוט תקלה , סיכוי לתקלה , עוצמה ו-

Risk Level

? MTBFמהו כל כמה זמן

מתקיים Critical failure

מהו זמן הפעולה של המערכת ללא תקלות

קריטיות ?

האם הסיכוי לכשל באתר הראשי גבוה

?

MTTF , MTTR , זמינות – ערך

מספרי

רשימת התעדוף של המערכות באתר המשני

ומשאבים .

בשגרה וב- SLAמה ה- DRP?

האם הצרכנים יקבלו רמת שירות

טובה ?

Page 69: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

? DRPהאם אנו מוכנים לאירוע

שגרה

Page 70: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

מה עושים ?

הוכרזDRPאירוע

Page 71: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

DRPאירוע

אתר ראשי)Primary Site(

אתר משני)DR Site(

71

סנכרון

אתר ראשי מסונכרן לאתר משני

אירועDRPמוכרז

-סנכרון מופסק והstorage באתר הופך

להיות פעיל . בסיסי - R/Wהנתונים ל

השרתים הופכים להיותפעילים

קרה אסון באתר ראשי

Page 72: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

• Microsoft SQL Server 2008 R2 Unleashed (2010), Sams

• Pro SQL Server Disaster Recovery (2008) , Apress

• Accelerated SQL Server (2008) , Apress

• Professional Sql Server 2008 Internals And Troubleshooting (2010) ,

Wiley

• Pro SQL Server 2008 Administration (2009), Apress.

• Microsoft SQL Server 2008 High Availability with Clustering & Database Mirroring , (2010) , Wiley

• SQL Server 2008 Transact SQL Recipes 2008 , Apress.

Resources

Page 73: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

• Professional Association for SQL Server (www.sqlpass.org)

• SQL Server Central (www.sqlservercentral.com)

• Simple-Talk (www.simple-talk.com/sql)

• MSSQLTips.com (www.mssqltips.com)

• SQLTeam.com (www.sqlteam.com)

• SQL Server Community (www.sqlcommunity.com)

Resources

Page 74: SQL Server Database Mirroring

Proprietary of Rafael - Advanced Defense Systems.Ltd.

Discussion, questions & answers