Your SlideShare is downloading. ×
Database Mirror for the exceptional DBA – David Izahk
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Database Mirror for the exceptional DBA – David Izahk


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. תאריך
    Database Mirror for the exceptional DBA
    דוד יצחק
    רפא"ל – מערכות לחימה מתקדמות בע"מ
  • 2. 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
  • 3. 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)
    Currently ME (System Engineering)
  • 4. 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.
    Next Session (?) :
    Reporting Considerations
    Merge Replication and Database Mirror as a combined solution
    Database Mirroring and failover Cluster combination
    .Net coding with Database Mirror
  • 5. Key Terms-1
    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
    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
  • 6. Key Terms- 2
    Optional Server that monitor the principal and mirror servers to provide a quorum
    Opposite server when referring to the principal and mirror servers
    Bound to a network protocol
    Allows SQL servers to communicate across the network.
  • 7. Key Terms - 3
    Active relationship between the servers involved in DB mirroring
    Allows them to maintain server state information about one another
    Possible roles:
    Witness role—Can be any edition of a SQL Server (even SQL Server Express).
    Principal role
    Mirror role
    After a failure, the mirror server takes over the principal role, and the roles reverse.
  • 8. 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 broughtonline as the principal DB
  • 9. Copy-on-Write Technology
    2. Log record
    Copied to mirror server over Network
    1. Client
    Principle Server
    Mirror Server
    Mirror DB
    3.physical log record is written to the mirror DB
    Principle DB
    2.transaction is written
    to principal server’s transaction log
    4. acknowledgment to principal server of its write success
    Mirror DB is exactly the same as the Principal DB
  • 10. Principle
    1. Write the data to transaction log and commit the data
    DB Mirror High Performance
    2. Send the transaction to mirror
    3. Write the data to transaction log and commit the data
    4. Send Acknowledgement to principle
  • 11. Principle
    1. Write the data to transaction log
    DB Mirror High Safety with Witness
    2. Send the transaction to mirror
    3. Write the data to transaction log and commit the data
    4. Send Acknowledgement to principle
    5. Commit the data
  • 12. 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.
  • 13. 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.
  • 14. Flow to determine the operating Mode for DB
  • 15. Operating Modes
  • 16. Database Mirroring Operating Modesin SSMS
  • 17. 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.
  • 18. 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.
  • 19. 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).
  • 20. 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.
  • 21. Failover variations 3Forced service
    SET @strSQL='ALTER DATABASE '+ @strDatabaseName+' SET PARTNER OFF'
    SET @strSQL='RESTORE DATABASE '+ @strDatabaseName+' WITH RECOVERY'
    PRINT'Bringing '+ @strDatabaseName+' ONLINE'
  • 22. 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.
  • 23. Steps to Set Up DB mirroringIn General
    Create endpoints on all of the instances.
    Create a login for the service accounts of the other instances if they do not exist.
    Grant connect permissions to the service accounts of the other instances on the endpoint.
    Set the principal partner for the mirror database on the mirror partner.
  • 24. Steps to Set Up DB mirroring In General
    Set the mirror partner for the principal database on the principal partner.
    If using a witness server, set the witness partner on the principal partner to enable automatic failover.
    If not using a witness server, you may want to change the operating mode from “High safety (synchronous)” to “High performance (asynchronous).
  • 25. 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
  • 26. 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
    RETURN @Results;
  • 27. 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.
  • 28. Automating Setup – PowerShell 2
  • 29. Automating Setup – PowerShell 3
  • 30. Automating Setup – PowerShell 4
  • 31. 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.
  • 32. Sqlcmd- Example 1 with variables
    -- Set here Principal Server name
    :setvarPrincipalServer "userWXP.domain.local"
    --Set DBs names to DB mirroring
    (Principal databases) .
    :setvarMirrorDatabaseName "AdventureWorks"
    --Set backup directory on principal server .
    :setvarBackupDirectory "D:Database_Mirroring“
    --Make a connection to Principal Server using
    Windows Authentication
    :CONNECT $(PrincipalServer)
    BACKUPDATABASE [$(MirrorDatabaseName)] TO
  • 33. Sqlcmd - Example 2 with variables file
    /* Script variables */
    :r "d:jobsmssqldb_env.sql"
    /* End Of Script variables */
    :CONNECT $(PrincipalServer)
    BACKUPDATABASE [$(MirrorDatabaseName)]
  • 34. 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 .
  • 35. Prepare the Database for MirroringSQLCMD Version
    SELECT @Compatibility =D.compatibility_level,
    FROMsys.databases D
    INNERJOINsys.database_mirroring DM ONDM.database_id=D.database_id
    WHERED.database_id= @DBID
    IF @MirrStateISNOTNULL
    RAISERROR('Database [%s] is already configured for mirroring on server [%s].',
    16, 1, @DBName, @Server);
    IF @Compatibility < 90

    ELSEIF @MaxCompat>= 100 -- SQL Server 2008+

    IF @RecoveryModel<> 1 -- Full Recovery Model
  • 36. 11.1&11.2
    Procedure to failover from/to Principal/mirror Server
    SQLCMD Version
    /* Script variables */
    :r "D:jobsmssqldb_env.sql“
    --Detects any DB that fit the criteria .
    --Issues the failback command one at a time for each DB .
    SELECTDB_ID(N'$(MirrorDatabaseName)')AS [Database ID];
    IFEXISTS(SELECT 1 FROMsys.database_mirroringWHEREdatabase_id=DB_ID(N'$(MirrorDatabaseName)')ANDmirroring_role_desc='PRINCIPAL')
    SELECTDB_ID(N'$(MirrorDatabaseName)')AS [Database ID];
    IFEXISTS(SELECT 1 FROMsys.database_mirroringWHEREdatabase_id=DB_ID(N'$(MirrorDatabaseName)')ANDmirroring_role_desc='PRINCIPAL')
  • 37.  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.
  • 38.  Database mirroring status table :  select * from msdb.dbo.dbm_monitor_data order by local_timedesc
    Query the db mirroring status table on both the principal server and the mirror server.
    redo_rate is always 0 on the principal server - does not redo transactions.
  • 39.   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
  • 40.   Database Mirroring Monitor Job 2
    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
    Drop the job.
    No parameters
    EXEC sp_dbmmonitordropmonitoring
  • 41.   Database Mirroring Monitor Job 3
    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
  • 42.   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.
    Communication issue between partners ( high-performance mode )
    In high-safety mode if DB mirroring has been paused.
  • 43.   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.
  • 44.   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.
  • 45.   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
  • 46.    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
  • 47.    Using the Database Mirroring Monitor 2
  • 48.    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.
  • 49.    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
  • 50.    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.
  • 51.    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.
  • 52.     Monitoring using system SP sp_dbmmonitorresults
    Directly returning rows from DB mirroring status table.
    @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.
  • 53.     Monitoring using system SP sp_dbmmonitorresults
    @mode = 6,
  • 54.     Managing Warning Thresholds using system SP 1
    Instead of the Database Mirroring Monitor
    3 SPs configure, view, and remove warning thresholds:
  • 55. = @average_delay, @enabled = 1;
        Managing Warning Thresholds using system SP 2
    --Warn if the unset log exceeds the the threshold in KB
    execsys.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 KB
    execsys.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
    execsys.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
  • 56. = @average_delay, @enabled = 1;
    Top wait Events Checks Network Waits DB mirror
  • 57. = @average_delay, @enabled = 1;
    Top wait Events Checks Network Waits DB mirror 2
  • 58. Read-writeWorkload
    Real-time Reporting
    Real-time Reporting
    Fast Incremental Backups
    Fast Backups
    • Offload read-only queries to an up-to-date Mirror DB
    • 59. Use fast backups on mirror DB
    • 60. More than 1 mirror DB destination to improve DRP
    What Next I Expect in DenaliOffload Processing– Improve Primary Performance!
    Continuous redo
    shipping, validation & apply
    Mirror DB
    Principle DB
  • 61. 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!!
  • 62. Disaster Recovery Process
    • שחזור מטייפ גיבוי יכול לקחת ימים
    • 63. Data Centric Environments
    • 64. צמצום “Mean Time To Recovery” אחרי אירועDRP
    Disaster Recovery Site
    Production Site
    (resync backwards after source restoration)
  • 65. Sample mirroring deployment Plan
  • 66. Sample mirroring deployment Plan
  • 67. ד"ר עמי הרי
    קורס T&E
    הנדסת מערכת טכניון
  • 68. מדדים
    (RTO) Recovery Time Objective
    הזמן המרבי עד לחזרתה של המערכת לתפקוד מלא עבור תהליכים עסקיים שונים
    (RPO) Recovery Point Objective
    הזמן המרבי שלגבי ניתן לאבד מידע . כמות המידע שהארגון מוכן לאבד ? יום שלם , מספר שעות /דקות
    משתנה באותה סקלה כמו RTO אבל לא תלוי בו (מערכות מסחר RPO אפס אבל RTO גדול יותר) .
    Service Level Agreement
    בהקשר לזה מדברים על זמינות , MTTF(Mean Time Between Failure) , MTTR (Mean time To recover)
    זמינות גבוהה (High availability)
    יכולת של המשתמש לגשת למערכת לצורך אחזור נתונים בכל עת
    חוסר זמינות= downtime
  • 69. מדדים : ניתוח סיכונים(Risk Analysis)
    תהליך לאיתור סיכונים צפויים ביישום תהליך או מוצר חדש.
    כולל הערכת ההסתברות וההשפעה הצפויה, ודרכי התגובה, של כל סיכון על מנת לגדר אותו ככל האפשר.
    רמת הסיכון נקבעת על בסיס המכפלה של "הסיכוי לתקלה "ו"עוצמת התקלה":
    Risk Level = Probability*Impact
  • 70. תעדוף
    כשבונים אתר DRP באתר חלופי – קובעים את סדר השחזור לפי רמת החשיבות של המערכות
    אילו מערכות לא ישוחזרו
    רמת השירות שתינתן במסגרת אילוצי מצב חירום
  • 71. מדדי ביצועים
  • 72. מדדי ביצועים
  • 73. שגרה
    האם אנו מוכנים לאירוע DRP ?
  • 74. אירוע DRP הוכרז
    מה עושים ?
  • 75. אירוע DRP
    אתר ראשי מסונכרן לאתר משני
    • קרה אסון באתר ראשי
    • 76. אירוע DRP מוכרז
    • 77. סנכרון מופסק וה- storage באתר הופך להיות פעיל . בסיסי הנתונים לR/W-
    • השרתים הופכים להיות פעילים
    אתר ראשי
    (Primary Site)
    אתר משני
    (DR Site)
  • 78. Resources
    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.
  • 79. Resources
    Professional Association for SQL Server (
    SQL Server Central (
    Simple-Talk ( ( (
    SQL Server Community (
  • 80. Discussion, questions & answers