• Like
  • Save
Database Mirror for the exceptional DBA – David Izahk
Upcoming SlideShare
Loading in...5
×
 

Database Mirror for the exceptional DBA – David Izahk

on

  • 3,897 views

 

Statistics

Views

Total Views
3,897
Views on SlideShare
3,440
Embed Views
457

Actions

Likes
0
Downloads
90
Comments
0

3 Embeds 457

http://www.sqlserver.co.il 419
http://blogs.microsoft.co.il 37
url_unknown 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Database Mirror for the exceptional DBA – David Izahk Database Mirror for the exceptional DBA – David Izahk Presentation Transcript

    • תאריך
      סימוכין
      1
      Database Mirror for the exceptional DBA
      דוד יצחק
      רפא"ל – מערכות לחימה מתקדמות בע"מ
      cimid@rafael.co.il
      4.4.2011
    • 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
    • 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)
    • 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:
      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.
       
    • 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
    • Copy-on-Write Technology
      2. Log record
      Copied to mirror server over Network
      I
      1. Client
      transaction
      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
      *
    • Principle
      1. Write the data to transaction log and commit the data
      DB Mirror High Performance
      2. Send the transaction to mirror
      Mirror
      3. Write the data to transaction log and commit the data
      4. Send Acknowledgement to principle
    • Principle
      1. Write the data to transaction log
      DB Mirror High Safety with Witness
      2. Send the transaction to mirror
      Mirror
      3. Write the data to transaction log and commit the data
      4. Send Acknowledgement to principle
      5. Commit the data
    • 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.
    • 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.
    • Flow to determine the operating Mode for DB
    • Operating Modes
    • Database Mirroring Operating Modesin SSMS
    • 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
    • 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.
    • 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).
       
      ALTERDATABASE $(MirrorDatabaseName)SETSAFETYFULL
      ALTERDATABASE $(MirrorDatabaseName)SETPARTNERFAILOVER
    • 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.
    • Failover variations 3Forced service
      ---Run the ALTER DATABASE databaseName SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
      SET @strSQL='ALTER DATABASE '+ @strDatabaseName+' SET PARTNER OFF'
      EXECsp_executesql@strSQL
      SET @strSQL='RESTORE DATABASE '+ @strDatabaseName+' WITH RECOVERY'
      EXECsp_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.
    • 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.
    • 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).
       
    • 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
    • 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
    • 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.
       
    • Automating Setup – PowerShell 2
    • Automating Setup – PowerShell 3
    • Automating Setup – PowerShell 4
    • 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.
    • 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)
      GO
      BACKUPDATABASE [$(MirrorDatabaseName)] TO
      DISK='$(BackupDirectory)$(MirrorDatabaseName).bak'
      WITHINIT;
      Go
    • Sqlcmd - Example 2 with variables file
      /* Script variables */
      :r "d:jobsmssqldb_env.sql"
      /* End Of Script variables */
      :CONNECT $(PrincipalServer)
      GO
      BACKUPDATABASE [$(MirrorDatabaseName)]
      TODISK='$(BackupDirectory)$(MirrorDatabaseName).bak‘
      WITHINIT;
      Go
    • 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 .
    • Prepare the Database for MirroringSQLCMD Version
      SELECT @Compatibility =D.compatibility_level,
      @RecoveryModel=D.recovery_model,
      @MirrState=DM.mirroring_state
      FROMsys.databases D
      INNERJOINsys.database_mirroring DM ONDM.database_id=D.database_id
      WHERED.database_id= @DBID
      IF @MirrStateISNOTNULL
      BEGIN
      RAISERROR('Database [%s] is already configured for mirroring on server [%s].',
      16, 1, @DBName, @Server);
      RETURN;
      END
      IF @Compatibility < 90

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

      IF @RecoveryModel<> 1 -- Full Recovery Model
    • 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 .
      USE[master]
      GO
      SELECTDB_ID(N'$(MirrorDatabaseName)')AS [Database ID];
      GO
      IFEXISTS(SELECT 1 FROMsys.database_mirroringWHEREdatabase_id=DB_ID(N'$(MirrorDatabaseName)')ANDmirroring_role_desc='PRINCIPAL')
      ALTERDATABASE $(MirrorDatabaseName)SETSAFETYFULL
      GO
      SELECTDB_ID(N'$(MirrorDatabaseName)')AS [Database ID];
      GO
      IFEXISTS(SELECT 1 FROMsys.database_mirroringWHEREdatabase_id=DB_ID(N'$(MirrorDatabaseName)')ANDmirroring_role_desc='PRINCIPAL')
      ALTERDATABASE $(MirrorDatabaseName)SETPARTNERFAILOVER
      GO
    •  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.
    •  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.
    •   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
    •   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
    •   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
       
    •   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.
       
       
    •   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.
    •   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.
    •   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
       
    •    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
       
    •    Using the Database Mirroring Monitor 2
    •    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.
    •    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
    •    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.
       
    •    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.
    •     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.
    •     Monitoring using system SP sp_dbmmonitorresults
      EXECsp_dbmmonitorresults
      @database_name=N'adventureWorks',
      @mode = 6,
      @update_table=
    •     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.
    • = @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
      execsys.sp_dbmmonitorchangealert@database_name=N'$(MirrorDatabaseName)',@alert_id=4,@threshold
    • = @average_delay, @enabled = 1;
      Top wait Events Checks Network Waits DB mirror
    • = @average_delay, @enabled = 1;
      Top wait Events Checks Network Waits DB mirror 2
    • Read-writeWorkload
      Real-time Reporting
      Real-time Reporting
      Fast Incremental Backups
      Fast Backups
      • 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
      What Next I Expect in DenaliOffload Processing– Improve Primary Performance!
      Real-time
      Queries
      Continuous redo
      shipping, validation & apply
      Mirror DB
      Principle DB
    • 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!!
    • Disaster Recovery Process
      • שחזור מטייפ גיבוי יכול לקחת ימים
      • Data Centric Environments
      • צמצום “Mean Time To Recovery” אחרי אירועDRP
      (redirect)
      X
      LAN/WAN
      Disaster Recovery Site
      Production Site
      (resync backwards after source restoration)
    • Sample mirroring deployment Plan
    • Sample mirroring deployment Plan
    • ד"ר עמי הרי
      קורס T&E
      הנדסת מערכת טכניון
    • מדדים
      (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
    • מדדים : ניתוח סיכונים(Risk Analysis)
      תהליך לאיתור סיכונים צפויים ביישום תהליך או מוצר חדש.
      כולל הערכת ההסתברות וההשפעה הצפויה, ודרכי התגובה, של כל סיכון על מנת לגדר אותו ככל האפשר.
      רמת הסיכון נקבעת על בסיס המכפלה של "הסיכוי לתקלה "ו"עוצמת התקלה":
      Risk Level = Probability*Impact
    • תעדוף
      כשבונים אתר DRP באתר חלופי – קובעים את סדר השחזור לפי רמת החשיבות של המערכות
      אילו מערכות לא ישוחזרו
      רמת השירות שתינתן במסגרת אילוצי מצב חירום
    • מדדי ביצועים
    • מדדי ביצועים
    • שגרה
      האם אנו מוכנים לאירוע DRP ?
    • אירוע DRP הוכרז
      מה עושים ?
    • אירוע DRP
      אתר ראשי מסונכרן לאתר משני
      • קרה אסון באתר ראשי
      • אירוע DRP מוכרז
      • סנכרון מופסק וה- storage באתר הופך להיות פעיל . בסיסי הנתונים לR/W-
      סנכרון
      • השרתים הופכים להיות פעילים
      אתר ראשי
      (Primary Site)
      אתר משני
      (DR Site)
      71
    • 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.
    • 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)
      SQL Server Community (www.sqlcommunity.com)
    • Discussion, questions & answers