Search

Showing posts with label Mirroring. Show all posts
Showing posts with label Mirroring. Show all posts

Saturday, February 4, 2012

Advantage and disadvantage of Database Mirroring

Advantages Database Mirroring:
  1. Database mirroring supports full-text catalogs.
  2. Database Mirroring architecture is more robust and efficient than Database Log Shipping. It can be configured to replicate the changes synchronously to minimized data loss.
  3. Does not require special hardware (such as shared storage, heart-beat connection) and clusterware, thus potentially has lower infrastructure cost
  4. Configuration is simpler than log shipping and replication, and has built-in network encryption support (AES algorithm).
  5. It has automatic server failover and client failover mechanism.
  6. Because propagation can be done asynchronously, it requires less bandwidth than synchronous method (e.g. host-based replication, clustering) and is not limited by geographical distance with current technology.
Disadvantages of Log Shipping:

  1. Mirror server/database is not available for user operation.
  2. Potential data lost is possible in asynchronous operation mode. RTO will vary and depend on several factors, such as propagation interval time and bandwidth speed.
  3. Automatic server failover may not be suitable for application using multiple databases.
  4. It only works at database level and not at server level. It only propagates changes at database level, no server level objects, such as logins and fixed server role membership, can be propagated.

Wednesday, November 30, 2011

Pause or Resume a Database Mirroring Session


We can pause and resume any Database Mirroring any time. Pausing mirroring preserves the mirroring state. Sometime pausing is very useful to improve the performance of the principal server. Pausing sets the state of the mirroring session to SUSPENDED, and the mirror database no longer updated with the principal database. 

We should resume the mirroring session quickly because as long as the session is paused then transaction log cannot be truncated. If the session is paused for a long time the log file may be grow large causing the database unavailable.

When a session is paused the  principal database is remains available.

Steps to pause and resume a database mirroring session follow below steps:
  1. In Object explorer, connect to the principal server and click the server name to expand.

  2. click on the Database and select the database.

  3. Now right click the database, select Tasks, and then click on Mirror. Now, it will opens the Mirroring page of the Database Properties dialog box.

  4. To pause the session, click Pause.
    A Confirmation message will come, if you click Yes, the session is paused, and the button changes to Resume.

    For more information about the impact of pausing a session, see Pausing and Resuming Database Mirroring.
  5. To resume the session, click Resume.

    Ref: MSDN

Wednesday, November 23, 2011

Remove Database Mirroring


  1. During a database mirroring session, connect to the principal server instance, in Object Explorer, click the server name to expand the server tree.

  2. Expand Databases, and select the database.

  3. Right-click the database, select Tasks, and then click Mirror. This opens the Mirroring page of the Database Properties dialog box.

  4. In the Select a Page pane, click Mirroring.

  5. To remove mirroring, click Remove Mirroring. A prompt asks for confirmation. If you click Yes, the session is stopped and mirroring is removed from the database.

    For more information about the impact of removing mirroring, see Removing Database Mirroring.

  6. Optionally, you can recover the former mirror database. On the server instance that was the mirror server, use the following Transact-SQL statement:

    RESTORE DATABASE <DB_Name> WITH RECOVERY

Thursday, June 30, 2011

Monitoring Database Mirroring

Database Mirroring Monitor is a graphical user interface tool that enables system administrators to view and update status and to configure warning thresholds on several key performance metrics. You can monitor a mirrored database during a mirroring session to verify whether and how well data is flowing. 
There are different ways to monitor database mirroring, based on what information you want to track.
For basic information about the database mirroring state, safety level, and witness status, you can use catalog views.

Specifically, monitoring a mirrored database allow us to know:
·         Verify that mirroring is functioning.
·         Basic status includes knowing if the two server instances are up, that the servers are connected, and that the log is being moved from the principal to the mirror.
·         Determine whether the mirror database is keeping up with the principal database.
·         During high-performance mode, a principal server can develop a backlog of unsent log records that still need to be sent from the principal server to the mirror server. Furthermore, in any operating mode, the mirror server can develop a backlog of unrestored log records that have been written to the log file but still need to be restored on the mirror database.
·         Determine how much data was lost when the principal server instance becomes unavailable during high-performance mode.
·         You can determine data loss by looking at the amount of unsent transaction log (if any) and the time interval in which the lost transactions were committed at the principal.
·         Compare current performance with past performance.
·         When problems are occurring, a database administrator can view a history of the mirroring performance to help in understanding the current state. Looking at the history can allow the user to detect trends in performance, identify patterns of performance problems (such as times of day when the network is slow or the number of commands entering the log is very large).
·         Troubleshoot the cause of reduced data flow between mirroring partners.
·         Set warning thresholds on key performance metrics.
·         If a new status row contains a value that exceeds a threshold, an informational event is sent to the Windows event log. A system administrator can then manually configure alerts based on these events. For more information, see Using Warning Thresholds and Alerts on Mirroring Performance Metrics.

To launch the Database Mirroring Monitor, right click on the database in SSMS, select "Tasks", then "Launch Database Mirroring Monitor".   You then need to register your mirrored database by connecting to either the principle or the mirror, and selected the mirrored database.  You can then view the current statistics of the mirror, including previous snapshots of the mirror’s status.
The primary drawback to the Database Mirroring Monitor is that you must be watching it to ensure there’s no problems.  The Perfmon Counters provided by the SQL Server: Database Mirroring object provide similar information that can be found in the Database Mirroring Monitor, but with all the benefits of Perfmon counters, such as registering alerts, and having a performance baseline.  

Monitor Database Mirroring status Using TSQL Statements / Queries
We can also verify / check Database mirroring status using a system stored procedure,"sp_dbmmonitorresults".
Catalog Views
There are four views related to mirroring.  They are:
1.   sys.database_mirroring
2.   sys.database_mirroring_endpoints
3.   sys.database_mirroring_witnesses
4.   sys.dm_db_mirroring_connections
These views show information about the mirroring setup, but not a lot about the current status of how the mirror is operating. 
sys.database_mirroring contains a row for each mirror, including the current state of the mirror.
sys.dm_db_mirroring_connections has information about how much traffic the connection has experienced, and the last time that it had traffic, but viewing this is more appropriate for checking the configuration of the mirror, not constant monitoring.
You can then view the current statistics of the mirror, including previous snapshots of the mirror’s status.
Perfmon Counters
The primary drawback to the Database Mirroring Monitor is that you must be watching it to ensure there’s no problems.  The Perfmon Counters provided by the SQL Server: Database Mirroring object provide similar information that can be found in the Database Mirroring Monitor, but with all the benefits of Perfmon counters, such as registering alerts, and having a performance baseline.  The counters available are:
Name
Description
Bytes Received/sec
The number of bytes sent to the other server, per second
Bytes Sent/sec
The number of bytes received from the other server, per second
Log Bytes Received/sec
The number of bytes from the log received from the principle, per second
Log Bytes Sent/sec
The number of bytes from the log sent to the mirror, per second
Log Send Queue KB
The number of bytes in the log that has not been sent to the mirror
Pages Sent/sec
The number of transaction log pages sent per second
Receives/sec
The number of mirroring messages received per second
Redo Bytes/sec
The number of bytes of log rolled forwards per second on the mirror
Redo Queue KB
The number of bytes of transaction log that remains to be applied to the mirror to roll it forwards
Send/Receive Ack Time Sends/sec
The number of mirroring messages sent per second
Transaction Delay
The delay while waiting for the mirror to commit a transaction

Wednesday, May 25, 2011

Mirroring States



The mirrored database is always in a specific mirroring state  during a session. The DB State reflects the communication status, the difference in data between the partners and data flow. 
The Server instance monitor each other during the mirroring session. The principal and the mirror database uses the same mirroring state except the Pending_Failover mirroring state. 
These are the possible mirroring states of the database:

0 = Suspensed
1 = Disconnected from other partner
2 = Synchronizing
3 = Pending Failover
4 = Synchronized
5 = The partners are not synchronized. Failover is not possible now.
6 = The partners are synchronized. Failover is potentially possible. 
NULL = Database is inaccessible or is not mirrored.

Mirroring state
Description
Suspensed
The mirror copy of the database is not available. The principal database is running without sending any logs to the mirror server, a condition known as running exposed. This is the state after a failover.
A session can also become SUSPENDED as a result of redo errors or if the administrator pauses the session.
SUSPENDED is a persistent state that survives partner shutdowns and startups.
Disconnected
The partner has lost communication with the other partner.
Synchronizing
The contents of the mirror database are lagging behind the contents of the principal database. The principal server is sending log records to the mirror server, which is applying the changes to the mirror database to roll it forward.At the start of a database mirroring session, the database is in the SYNCHRONIZING state. The principal server is serving the database, and the mirror is trying to catch up.
Pending Failover
This state is found only on the principal server after a failover has begun, but the server has not transitioned into the mirror role.When the failover is initiated, the principal database goes into the PENDING_FAILOVER state, quickly terminates any user connections, and takes over the mirror role soon thereafter.
Synchronized
When the mirror server becomes sufficiently caught up to the principal server, the mirroring state changes to SYNCHRONIZED. The database remains in this state as long as the principal server continues to send changes to the mirror server and the mirror server continues to apply changes to the mirror database.
If transaction safety is set to FULL, automatic failover and manual failover are both supported in the SYNCHRONIZED state, there is no data loss after a failover.
If transaction safety is off, some data loss is always possible, even in the SYNCHRONIZED state.
Ref: MSDN 

Friday, May 6, 2011

Set Up a Mirror Database to Use the Trustworthy Property


To setup a mirror database to use the Trustworthy Property

  1. On the principal server instance, verify that the principal database has the Trustworthy property turned on.

    SELECT name, database_id, is_trustworthy_on FROM sys.databases 
    
    
  2. After starting mirroring, verify that the database is currently the principal database, the session is using a synchronous operating mode, and the session is already synchronized.


    SELECT database_id, mirroring_role, mirroring_safety_level_desc, mirroring_state_desc FROM sys.database_mirroring
    
    
  3. Once the mirroring session is synchronized, manually fail over to the mirror database.
    This can be done in either SQL Server Management Studio or using Transact-SQL:
  4. Turn on the trustworthy database property using the following ALTER DATABASE command:


    ALTER DATABASE <database_name> SET TRUSTWORTHY ON
    
    
  5. Optionally, manually failover again to return to the original principal.

  6. Optionally, switch to asynchronous, high-performance mode by setting SAFETY to OFF and ensuring that WITNESS is also set to OFF.

    Ref: MSDN