SQL Server Database Mirroring
SQL Server Database Mirroring
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)
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
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
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.
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 roleCan 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.
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
Copy-on-Write Technology
2. Log record Principle Server Copied to mirror Mirror Server server over Network Mirror DB I
Principle DB 2.transactio n is written to principal servers transaction log
1. Client
transaction
write success
Mirror
Principle
Mirror
1. Write the data to transaction log 5. Commit the data 4. Send Acknowledgement to principle
Proprietary of Rafael - Advanced Defense Systems.Ltd.
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.
Proprietary of Rafael - Advanced Defense Systems.Ltd.
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.
Operating Modes
Mode Risk of data loss Zero Data Loss Double Failure Protection Zero Data Loss Single Failure Protection Potential for Minimal Data Loss Transport Description
SYNC
High safety with automatic failover &witness High safety without automatic failover ,without witness Principle never waits for mirror acknowledgement
SYNC
ASYNC
in SSMS
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
Proprietary of Rafael - Advanced Defense Systems.Ltd.
Failover variations 1
Automatic failover: high-availability mode
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 FULL ALTER DATABASE $(MirrorDatabaseName) SET PARTNER FAILOVER
Failover variations 3
Forced 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 (highprotection mode) or high-performance mode.
Failover variations 3
Forced service
---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
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.
Automating Setup 3
options
command.
Go
Prepare the Database for Mirroring SQLCMD 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 .
11.1&11.2
Database mirroring status table : select * from msdb.dbo.dbm_monitor_data order by local_time desc
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
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.
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.
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.
Instead of the Database Mirroring Monitor 3 SPs configure, view, and remove warning thresholds:
sp_dbmmonitorchangealert, sp_dbmmonitorhelpalert sp_dbmmonitordropalert.
= @average_delay, @enabled = 1;
--Warn if the unrestored log exceeds the the threshold in KB exec 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
Proprietary of Rafael - Advanced Defense Systems.Ltd.
= @average_delay, @enabled = 1;
Script SELECT TOP 15 wait_type, wait_time_ms FROM sys.dm_os_wait_stats WHERE 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
= @average_delay, @enabled = 1;
Principle DB
Mirror DB
Offload read-only queries to an up-to-date Mirror DB Use fast backups on mirror DB More than 1 mirror DB destination to improve DRP
Proprietary of Rafael - Advanced Defense Systems.Ltd.
A PLAN!!
Proprietary of Rafael - Advanced Defense Systems.Ltd.
(redirect)
Production Site
8:00 p.m.
Disable all SQL jobs and scheduled tasks Verify that the database is using Full Recovery and do not support Filestream Create full backup of database
3 min.
2 min.
5 min.
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
(RTO) Recovery Time Objective
()High availability
= downtime
: ) Risk (Analysis
. , , . " "" ": Risk Level = Probability*Impact
.Proprietary of Rafael - Advanced Defense Systems.Ltd
DRP
MOPs
-RPO
MOSs
MOEs
?DRP ?
CI
? ? - DRP ?
-RTO
- ?DRP
MOPs
, , - Risk Level
MOSs
?MTBF Critical failure
MOEs
?
CI
?
, MTTR , MTTF .
- SLA - ? DRP
? DRP
Proprietary of Rafael - Advanced Defense Systems.Ltd.
DRP
?
Proprietary of Rafael - Advanced Defense Systems.Ltd.
DRP
DRP - storage . -R/W
)(Primary Site
)(DR Site
17
Resources
Resources
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)