Database Mirroring in SQL Server 2005
Database Mirroring in SQL Server 2005
Copyright
This is a preliminary document and may be changed substantially prior to final commercial release of the software
described herein.
The information contained in this document represents the current view of Microsoft Corporation on the issues discussed
as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted
to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented
after the date of publication.
This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR
STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright,
no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form
or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express
written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering
subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the
furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual
property.
Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos,
people, places, and events depicted herein are fictitious, and no association with any real company, organization, product,
domain name, e-mail address, logo, person, place, or event is intended or should be inferred.
2005 Microsoft Corporation. All rights reserved.
Microsoft and ActiveX are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or
other countries.
The names of actual companies and products mentioned herein may be the trademarks of their respective owners.
Table of Contents
Database Mirroring in SQL Server 2005............................................................1
Introduction......................................................................................................1
Database Mirroring Overview............................................................................1
Operating Modes.............................................................................................2
Transaction Safety...........................................................................................2
The Quorum and the Witness Server..................................................................3
High Availability Operating Mode.......................................................................3
High Protection Operating Mode........................................................................4
High Performance Operating Mode.....................................................................4
Database Snapshots and the Mirror Database.....................................................4
Client-side Redirect..........................................................................................5
Database Mirroring and SQL Server 2005 Editions...............................................6
Database Mirroring Dynamics...........................................................................7
Setup and Security..........................................................................................7
Database Mirroring Catalog Views....................................................................10
Database Mirroring States and Transitions........................................................13
Principal Server Database States................................................................14
Mirror Server Database States...................................................................16
Witness Server States...............................................................................16
Transferring Transaction Log Records...............................................................17
Database Mirroring Role Changes....................................................................21
Automatic Failover....................................................................................21
Manual Failover........................................................................................22
Forced Service.........................................................................................23
Database Mirroring Availability Scenarios.......................................................23
High Availability Scenarios with Server Loss......................................................24
Summary: High Availability Scenarios with Server Loss.................................34
High Availability Scenarios with Communication Loss.........................................36
Summary: High Availability Scenarios with Communication Loss: Three Sites...39
Summary: High Availability Scenarios with Communication Links Broken.........43
High Protection Scenarios...............................................................................43
High Performance Scenarios............................................................................44
Implementing Database Mirroring..................................................................46
Monitoring Database Mirroring.........................................................................46
Database Mirroring Perfmon Counters.........................................................46
Estimating Redo and Catch-up Time............................................................47
Profiler Events..........................................................................................47
Troubleshooting Database Mirroring.................................................................47
i
Troubleshooting Setup...............................................................................47
Troubleshooting Runtime Errors..................................................................48
Safety vs. Performance..................................................................................48
Testing Database Mirroring.............................................................................49
Preparing the Mirror server for Failover............................................................50
Multi-Database Issues....................................................................................50
Database Mirroring and High Availability Technologies...................................51
Database Mirroring and Clustering...................................................................53
Database Mirroring and Transactional Replication...............................................53
Database Mirroring and Log Shipping...............................................................54
Conclusion.......................................................................................................56
ii
Introduction
Database mirroring is a new SQL Server 2005 technology available for review for
increasing database availability. Database mirroring transfers transaction log records
directly from one server to another and can quickly fail over to the standby server. You
can code client applications to automatically redirect their connection information, and
in the event of a failover, automatically connect to the standby server and database.
Fast failover with minimal data loss has traditionally involved higher hardware cost and
greater software complexity. Database mirroring, however, can fail over quickly with no
loss of committed data, does not require proprietary hardware, and is easy to set up
and manage.
The principal database must be in the FULL recovery model. Log records that
result from bulk-logged operations cannot be sent to the mirror database.
The mirror database must be initialized from a restore of the principal database
with NORECOVERY, followed by restores in sequence of principal transaction log
backups.
The mirror database must have the same name as the principal database.
Note: For more information about the terms related to database mirroring, see
"Overview of Database Mirroring" in SQL Server 2005 Books Online.
Operating Modes
There are three possible operating modes for a database mirroring session. The exact
mode is based on the setting of transaction safety and whether a witness server is part
of the mirroring session.
Table 1.
Operating
Transaction
Quorum
Witness
Failover
safety
Transfer
mechanism
Mode
required
server
Type
High
Availability
FULL
Synchronous
Automatic
or Manual
High
Protection
FULL
Synchronous
Manual
only
High
Performance
OFF
Asynchronous
N/A
Forced
only
If safety is FULL and a witness is set, synchronous data transfer will occur, and a
quorum is required for database service. A quorum vote requires at least two servers to
decide which role, principal or mirror, each of the two partner servers should play.
In order to explore the three operating modes in more detail, let's first take a closer
look at transaction safety and the role of a quorum.
Transaction Safety
If transaction safety (or just 'safety') is set to FULL, the principal and mirror servers
operate in a synchronous transfer mode. As the principal server hardens its principal
database log records to disk, it also sends them to the mirror. The principal then waits
for a response from the mirror server. The mirror responds when it has hardened those
same log records to the mirror's log disk. When safety is set OFF, the principal does not
wait for acknowledgment from the mirror, and so the principal and mirror may not be
fully synchronized (that is, the mirror may not quite keep up with the principal).
perform an automatic failover. At that point, the mirror server instance will change its
role to become the new principal and recover the database. The mirror server can
become available quickly because the mirror has been replaying the principal's
transaction logs and its transaction log has been synchronized with the principal's.
Also, SQL Server 2005 can make a database available to users earlier in the recovery
process. SQL Server database recovery consists of three phases: the analysis phase,
the redo phase, and finally the undo phase. In SQL Server 2005, a newly recovered
database can become available for use as soon as the redo phase is finished. Therefore
if a database mirroring failover occurs, the recovered new principal database can
become available for use as soon as it finishes the redo phase. Because the mirror
database has been replaying transaction log records all along, all the mirror serves has
to do is finish the redo process, which normally can be accomplished in seconds.
Client-side Redirect
In SQL Server 2005, if you connect to a database that is being mirrored with ADO.NET
or the SQL Native Client, your application can take advantage of the drivers' ability to
automatically redirect connections when a database mirroring failover occurs. You must
specify the initial principal server and database in the connection string, and optionally
the failover partner server.
There are many ways to write the connection string, but here is one example,
specifying server A as the principal, server B as the mirror, and AdventureWorks as the
database name:
"Data Source=A;Failover Partner=B;Initial
Catalog=AdventureWorks;Integrated Security=True;"
The failover partner in the connection string is used as an alternate server name if the
connection to the initial principal server fails. If the connection to the initial principal
server succeeds, then the failover partner name will not be used, but the driver will
store the failover partner name that it retrieves from the principal server on the clientside cache.
Assume a client is successfully connected to the principal, and a database mirroring
failover (automatic, manual, or forced) occurs. The next time the application attempts
to use the connection, the ADO.NET or SQL Native Client driver will detect that the
connection to the old principal has failed, and will automatically retry connecting to the
new principal as specified in the failover partner name. If successful, and there is a new
mirror server specified for the database mirroring session by the new principal, the
driver will retrieve the new partner failover server name and place it in its client cache.
If the client cannot connect to the alternate server, the driver will try each server
alternately until the login timeout period is reached.
The great advantage of using the database mirroring support built into ADO.NET and
the SQL Native Client driver is that you do not need to recode the application, or place
special code in the application, to handle a database mirroring failover.
If you do not use the ADO.NET or SQL Native Client automatic redirection, you can use
other techniques that will enable your application to fail over. For example, you could
use Network Load Balancing to manually redirect connections from one server to
another, while the client just connects to a virtual server name. You might also write
your own redirection code and retry logic.
However, all these techniques for coordinating client redirection with a database
mirroring have an important limitation. Database mirroring occurs only at the database
level, not the server level. Be careful if your application relies on querying several
databases on a server, or uses multi-part object names to query across several
databases. When several databases reside on one server, and they are mirrored to a
standby server, it is possible that one of several databases might fail over to the
standby but the others remain on the original server. In that case, you might need one
connection per database that you are querying, so that you do not attempt crossdatabase queries on a standby server where only one database is a principal and the
remaining are mirrors.
Database
Enterprise
Developer
Standard
Workgroup
SQL
Mirroring
Edition
Edition
Edition
Edition
Express
Partner
Witness
Safety = FULL
Safety = OFF
Available during
UNDO after
failover
Parallel redo
Database
Snapshots
Feature
A few database mirroring features require SQL Server 2005 Enterprise or Developer
Editions:
database snapshots;
6
Use of multiple threads for replaying the transaction log on the mirror database
(parallel REDO).
SQL Express and the Workgroup Edition can be used as a witness server, but they
cannot be used as a partner server in database mirroring.
and optionally logins, before constructing and executing the CREATE ENDPOINT
commands. You can also execute the CREATE ENDPOINT command using TransactSQL. (See "How to: Create a Mirroring Endpoint (Transact-SQL)" in SQL Server
Books Online.)
If you are setting up database mirroring on a domain, and all SQL Server instances use
the same service login and password, you do not need to create logins on each server.
Similarly, on a workgroup, if all SQL Server instances use the same service login and
password, you do not need to create logins on the servers. Just leave the logins blank
on the Configure Database Mirroring Security Wizard when setting up endpoints.
Each database endpoint must specify a unique port on the server. When working with
SQL Server instances on separate machines, these port numbers can all be the same
and the Configure Database Mirroring Security Wizard will automatically suggest port
5022 as the port. If any of the SQL Server instances are on the same machine, each
instance must have a distinct port and the port numbers must be unique.
Suppose you want to have three servers in a High Availability mirroring session. Server
A will be the principal, server B the mirror, and server W the witness. For server A, the
following command will create an endpoint on port 5022:
CREATE ENDPOINT [Mirroring]
AS TCP (LISTENER_PORT = 5022)
FOR DATA_MIRRORING (ROLE = PARTNER, ENCRYPTION = ENABLED);
Note that the role has been specified as PARTNER, so that this server may take on the
role of principal or mirror for any given database mirroring database. The same
command is issued on server B. Since server B is a SQL Server instance on a distinct
physical machine, the port number is the same. Then for server W, you can issue
CREATE ENDPOINT [Mirroring]
AS TCP (LISTENER_PORT = 5022)
FOR DATA_MIRRORING (ROLE = WITNESS, ENCRYPTION = ENABLED);
Note that for server W, the role is specified as WITNESS.
By default, the endpoint is not started. You can next start each endpoint using the
following query on each server:
ALTER ENDPOINT [Mirroring] STATE = STARTED;
Optionally, you can insert the STATE option in the CREATE ENDPOINT command. This
process is repeated on each server.
When you create an endpoint using CREATE ENDPOINT, you can restrict access by IP
address using the protocol specific arguments. You can restrict access to a particular set
of IP addresses by combining the RESTRICT_IP with ALL option, and the EXCEPT_IP
with the list of just those special IP addresses you want. (See "CREATE ENDPOINT" in
SQL Server Books Online.)
You can inspect the database mirroring endpoints on a server by querying the
sys.database_mirroring_endpoints catalog view:
SELECT *
FROM sys.database_mirroring_endpoints;
8
4. To start database mirroring, you next specify the partners and witness. You need
database owner permissions to start and administer a given database mirroring
session. On server A, the intended principal server, you tell SQL Server to give a
particular database the principal role and what its partner (mirror) server is:
-- Specify the partner from the principal server
ALTER DATABASE [AdventureWorks] SET PARTNER =
N'TCP://B.corp.mycompany.com:5022';
The partner name must be the fully qualified computer name of the partner. Finding
fully qualified names can be a challenge, but the Configure Database Mirroring Security
Wizard will find them automatically when establishing endpoints.
The fully qualified computer name of each server can also be found running the
following from the command prompt:
IPCONFIG /ALL
Concatenate the "Host Name" and "Primary DNS Suffix". If you see something like:
Host Name . . . . . . . . . . . . : A
Primary Dns Suffix . . . . . . . : corp.mycompany.com
Then the computer name is just A.corp.mycompany.com. Prefix 'TCP://' and append
':<port number>' and you then have the partner name.
On the mirror server, you would just repeat the same command, but with the principal
server named:
-- Specify the partner from the mirror server
ALTER DATABASE [AdventureWorks] SET PARTNER =
N'TCP://A.corp.mycompany.com:5022';
On the principal server, you next specify the witness server:
-- Specify the witness from the principal server
ALTER DATABASE [AdventureWorks] SET WITNESS =
N'TCP://W.corp.mycompany.com:5026';
You do not need to execute any additional commands on the witness server after the
initial CREATE ENDPOINT.
Finally, you specify the safety level of the session, on the principal server:
-- Set the safety level from the principal server
ALTER DATABASE [AdventureWorks] SET SAFETY FULL;
At this point, mirroring will start automatically, and the principal and mirror servers will
synchronize.
You can adjust the timeout value for determining partner outage, using the TIMEOUT
parameter to ALTER DATABASE. For example, to change the TIMEOUT value to 20
seconds (the default is 10), on the principal server issue:
-- Issue from the principal server
ALTER DATABASE [AdventureWorks] SET PARTNER TIMEOUT 20;
Finally, you can adjust the size of the redo queue on the mirror by issuing the ALTER
DATABASE with the REDO_QUEUE option on the principal server. The following query
will set the redo queue to 100 megabytes on the mirror:
-- Issue from the principal server
ALTER DATABASE [AdventureWorks] SET PARTNER REDO_QUEUE 100MB;
Once you have specified the partners, mirroring will start immediately.
, is_suspended_sequence_number
, principal_server_name
, mirror_server_name
FROM sys.database_mirroring_witnesses;
Now let's compare the output of both queries in a typical database mirroring session.
Assume you've just set up mirroring from server A to server B with safety as FULL. (For
sample code to set up the following configuration, see "Setup and Security" in
Implementing Database Mirroring, later.) The witness server is server W and you're
mirroring the AdventureWorks database. Table 3 shows the possible output of the above
queries for the two partners.
Table 3. The output of sys.database_mirroring on a sample High Availability
session for both partners.
Partner
Principal
Mirror
metadata
values:
values:
column
Server A
Server B
db_name(database_id)
AdventureWorks
AdventureWorks
mirroring_role_desc
PRINCIPAL
MIRROR
mirroring_safety_level_des
c
FULL
FULL
mirroring_state_desc
SYNCHRONIZED
SYNCHRONIZED
mirroring_safety_sequence
mirroring_role_sequence
mirroring_partner_instance
TCP://B.corp.mycompany
.com:5022
TCP://A.
.corp.mycompany.com:5022
mirroring_witness_name
TCP://W.corp.mycompany TCP://W.corp.mycompany.co
.com:5022
m:5022
mirroring_witness_state_de CONNECTED
sc
CONNECTED
mirroring_failover_lsn
95000000007300001
95000000007300001
Note that each partner in the database mirroring session keeps all the same metadata,
from that partner's perspective. Each partner keeps its own database name, the safety
setting of the entire session, the mirroring state of the database, and two sequence
counters.
11
Both partner database states and the witness state are kept by each partner server:
The mirroring_state_desc shows the state that the partner database has in the
session.
Witness
Corresponding partner
metadata
values
metadata
column
column
database_name
AdventureWorks
db_name(database_id)
safety_level_desc
FULL
mirroring_safety_level_desc
safety_sequence_number
mirroring_safety_sequence
role_sequence_number
mirroring_role_sequence
is_suspended
is_suspended_sequence_numb
er
principal_server_name
TCP://A.
.corp.mycompany.com
:5022
mirror_server_name
TCP://B.corp.mycomp
any.com:5022
Note that the witness server's metadata contains the safety description, the safety
sequence number, and the role sequence number, though under slightly different
names. The witness also keeps data about whether the session is suspended, and keeps
the principal and mirror server names. Note that the witness sever catalog view does
not report the mirroring failover lsn, and it does not keep the database states.
12
All the metadata required for database mirroring (in particular the mirroring failover lsn
and partner server names) are kept by the mirroring partners. The witness only keeps
data necessary for its role as a witness in a High Availability mode, in particular the role
sequence number, which tracks the number of role changes in the session. This counter
is used to help decide when a principal server can make a role change, as you'll learn in
the scenarios in the next section.
13
If safety is FULL, the principal database always starts off in the SYNCHRONIZING
state, and transitions to the SYNCHRONIZED state when the principal and mirror
transactions logs are synchronized.
If safety is FULL and the principal server is disconnected from the witness server
but can still process transactions, the database is exposed.
The following table shows the states that a principal database can be in, and some of
the events that can cause a transition to another state.
Table 5. Principal Database states with a witness set and with safety FULL and
safety OFF.
Safety
Principal
Event
Resulting State
Quorum
Exposed
Able
to
serve
db
Initial State
FULL
SYNCHRONIZING
Synchronization
occurs
SYNCHRONIZED
FULL
SYNCHRONIZED
Session is
paused
SUSPENDED
FULL
SYNCHRONIZED
Redo errors on
the mirror
SUSPENDED
FULL
SYNCHRONIZED
Mirror
unavailable
DISCONNECTED
Y, with
witness
N, no
witness
OFF
SYNCHRONIZING
Session is
paused
SUSPENDED
OFF
SYNCHRONIZING
Redo errors on
the mirror
SUSPENDED
OFF
SYNCHRONIZING
Mirror
unavailable
DISCONNECTED
Y, with
witness
N, no
witness
Table 1 Principal Database states with no witness set and with safety FULL and safety
OFF.
Safety
Principal
Event
Resulting State
Exposed
14
Able
Initial State
to
serve
db
FULL
SYNCHRONIZING
Synchronization
occurs
SYNCHRONIZED
FULL
SYNCHRONIZED
Session is
paused
SUSPENDED
FULL
SYNCHRONIZED
Redo errors on
the mirror
SUSPENDED
FULL
SYNCHRONIZED
Mirror
unavailable
DISCONNECTED
OFF
SYNCHRONIZING
Session is
paused
SUSPENDED
OFF
SYNCHRONIZING
Redo errors on
the mirror
SUSPENDED
OFF
SYNCHRONIZING
Mirror
unavailable
DISCONNECTED
When safety is FULL, the principal first enters the SYNCHRONIZING state and as soon
as it synchronizes with the mirror, both partners enter the SYNCHRONIZED state. When
safety is OFF, the partner databases start with the SYNCHRONIZING state. Once the
mirror has caught up, the state goes to SYNCHRONIZED and stays there regardless of
how far behind it is.
For both safety settings, if the session is paused or there are redo errors on the mirror,
the principal enters the SUSPENDED state. If the mirror becomes unavailable, the
principal will enter the DISCONNECTED state.
In the DISCONNECTED and SUSPENDED states:
When a witness has been set, if the principal can form a quorum with the
witness or mirror server, the principal database is considered exposed. That
means the principal database is active with user connections and processing
transactions. However, no log records are being sent to the mirror database, and
if the principal should fail, the mirror will not have any of the transactions from
the principal from the point the principal entered that state. Also, the principal's
transaction log cannot be truncated, so the log file will be growing indefinitely.
When a witness has been set, if the principal cannot form a quorum with another
server, it cannot serve the database. All users will be disconnected and no new
transactions will be processed.
Note: Management Studio's Object Explorer will report the principal database states
next to the database name in the Server tree graph. It will report a principal's
SYNCHRONIZED state as 'Principal, Synchronizing' and the DISCONNECTED state as
'Principal, Disconnected.'
15
Event
Resulting State
FULL
SYNCHRONIZING
Synchronization
occurs
SYNCHRONIZED
FULL
SYNCHRONIZED
Session is paused
SUSPENDED
FULL
SYNCHRONIZED
SUSPENDED
FULL
SYNCHRONIZED
Principal database
unavailable
DISCONNECTED
OFF
SYNCHRONIZING
Session is paused
SUSPENDED
OFF
SYNCHRONIZING
SUSPENDED
Just as with the principal, Management Studio's Object Explorer will report some of the
mirror database states next to the database name in the Server tree. It will report a
mirror's SYNCHRONIZED state as 'Mirror, Synchronizing' and the DISCONNECTED state
as 'Mirror, Disconnected.'
Event
Resulting State
CONNECTED
DISCONNECTED
UNKNOWN
Since the state of the witness server is actually recorded in the partner servers, and not
on the witness server, these states are set from the vantage point of the partners. So
seeing a DISCONNECTED status for the witness server implies that the partners are
disconnected from the witness. When database mirroring starts up, if the mirror cannot
initialize with the principal, the witness will enter an UNKNOWN state.
16
17
Server B
Principal, Synchronized
Mirror, Synchronized
and
the transaction is considered committed
New transactions are written to the
principal's log buffer.
The key point in the sequence above is that when safety is FULL, the principal server
hardens its log buffer and sends a copy of the log records from the buffer to the mirror,
both at the same time. It then waits for the completion of its own I/O and the I/O of
the mirror before considering the transaction complete. When the principal receives its
response from the mirror, the principal can then proceed to the next hardening.
Despite the close coordination between principal and mirror when safety is FULL,
database mirroring is not a distributed transaction and does not use a two-phase
commit.
In database mirroring, you have two transactions being played out on two
servers, not one transaction distributed across them.
Database mirroring does not use the partner servers as resource managers in a
distributed transaction
2. When safety is OFF, the principal does not wait for acknowledgment from the mirror
server, so the number of committed transactions on the principal can get ahead of the
mirror, as shown in Table 9.
19
Server B
Principal, Synchronizing
Mirror, Synchronizing
and
and
20
Automatic - occurs only in the High Availability mode (safety is FULL and a
witness is part of the session
Manual - occurs in the High Availability and High Protection operating modes
(safety is FULL) and the partner databases are both SYNCHRONIZED.
Forced service (allow data loss) - used primarily in the High Performance (safety
OFF) mode to immediately and manually recover the mirror database.
When safety is FULL, the best way to reverse the roles of the servers is to use manual
failover, not forced service.
Automatic Failover
Automatic failover is a feature of database mirroring in the High Availability operating
mode (safety FULL with a witness). In most cases, SQL Server can accomplish an
automatic database mirroring failover in a few seconds. It can do this in part because
the SQL Servers involved in a database mirroring session all test each other's presence.
This process is called a 'ping', though it involves much more than an ordinary IP
address ping. The mirror and witness servers contact the principal server for the
presence of the physical server, for the presence of the SQL Server instance, and the
availability of the principal database. Similarly, the principal and the witness each ping
the mirror server for availability of the physical server, the SQL Server instance, and the
recovering state of the mirror database.
Suppose the database mirroring session has been set up with safety FULL and with a
witness server. The mirror server, Server B, finds through its ping that the principal
Server A is unavailable. Server B communicates with the witness server and receives
confirmation that the witness also cannot see Server A. Then Server B will form a
quorum with the witness server and promote itself into the principal role. It will recover
its database and notify the witness that it is now has the principal role (though the
database will be in a disconnected state, and the new principal database's transaction
log cannot be truncated).
Server B's new principal database continues to replay transaction log activity, but it has
been in a redo state continuously and in most cases there will be little left to do. In
database mirroring for all SQL Server editions, the new principal database becomes
available as soon as it finishes its redo state. When the database enters the undo state,
it becomes available for user connections. Finishing the redo state occurs normally in a
few seconds, although the remaining undo phase could be much longer. In database
mirroring, the new principal database becomes available for serving user connections as
soon as the redo process is finished. The new principal server B's database is in a
DISCONNECTED state and is exposed, but it can place its database into service just as
soon as the redo phase is completed.
21
Usually it will take more time to redirect an entire application from the old principal to
the new principal than a database mirroring automatic failover will take. The application
must detect and retry connections, which may add some time to the process. In
addition, if new logins using SQL Server authentication have been added to the servers,
you may need to map those logins to the new principal using the system stored
procedure sp_change_users_login. Complete application failover may also be delayed if
any critical objects on the old principal, such as SQL Agent jobs, have not also been
copied to the new principal server. (For more information, see "Preparing the Mirror
server for Failover" in the Implementation section later.)
Now suppose the old principal server comes online. There is a negotiation process that
must occur between the two servers if they are reversing roles, as in a manual failover,
or an automatic failover where the old principal is repaired fairly quickly. Before
mirroring can restart, the two partner servers need to find out how they can
synchronize with each other. The mirroring failover lsn plays a critical role in this
process.
Server A (the new mirror) is behind, but it is not clear how much. Server A reports to
server B (the new principal) the last mirroring failover lsn that it received from server B.
Server B, on the other hand, has had committed work which has brought its mirroring
failover lsn to a more recent state. Both servers then agree that server B has the
correct failover lsn, and that server A must catch up to it. Server B sends a sufficient
number of transaction records to server A that it can replay in order to become
synchronized.
Manual Failover
A manual failover is a way of causing the two partner servers to reverse their roles in
an orderly way and without any errors. It requires that safety be set to FULL, and that
the principal and mirror databases are in the SYNCHRONIZED state.
You cause a manual failover by invoking the ALTER DATABASE command on the
principal server:
ALTER DATABASE AdventureWorks SET PARTNER FAILOVER;
or by clicking the Failover button in the Database Properties/Mirroring dialog in
Management Studio. A manual failover causes current users to be disconnected and
rolls back any unfinished transactions from the old principal database. It will recover the
mirror database by finishing all completed transactions in the redo queue, and rolling
back (in the undo phase) unfinished transaction. The old mirror is assigned the principal
role, and the old principal database takes on the new role of mirror. The two servers will
negotiate a new starting point for mirroring based on their mirroring failover lsns, and
proceed with their roles reversed.
You can use a manual failover as a way of accomplishing a 'rolling upgrade' to the
server operating systems or SQL Server instances, provided you upgrade the mirror
server first before initializing mirroring. For more information, see 'Manual Failover' in
SQL Server Books Online.
22
Forced Service
You can cause a forced service on the mirror by invoking the ALTER DATABASE
command:
ALTER DATABASE AdventureWorks SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS;
Normally this is only useful if you have safety OFF, and if the principal is no longer
operating. You can also use this command with safety FULL but if the recovered mirror
server cannot form a quorum, it cannot serve the database. Therefore it's better to use
this command only with safety OFF (the High Performance mode). Some data may be
lost because the asynchronous data transfer may not have kept the mirror fully up to
date with committed transactions from the principal.
A server loss could occur when either one of the partner databases, or one of the
SQL Server instances, become unavailable. Alternately, the lines of communication
between the database mirroring partner servers may be interrupted, even though the
servers themselves continue to operate.
The following scenarios consider simultaneous failures of two components as a
sequential failure of one component followed by another. For example, if Servers A and
B appear to fail simultaneously, the mirroring system will treat that event as a
sequence: Server A followed by Server B, or vice versa.
You can use the following rules to determine the expected results of an unavailability
event:
1. When a witness has been set, the principal server requires a quorum
with at least one other server to keep its database in service.
If a principal cannot form a quorum, it can no longer serve the database.
2. When safety is FULL, if neither the mirror nor the witness can see the
principal, the mirror server can form a quorum with the witness and
change its role to become a new principal server, assuming a the
mirroring session was SYNCHRONIZED when the principal went away.
This is an automatic failover.
3. When safety is FULL, if the principal has done work while in quorum
with the witness but disconnected from the mirror, a principal failure
will not allow the mirror to form a quorum with the witness and take on
the role of a new principal server.
This prevents work being lost by the session.
4. When safety is FULL, if a failed principal server rejoins a session after
being down or isolated, and the old mirror has previously taken on the
role of new principal (in quorum with the witness), the old principal will
take on the role of new mirror in the session.
23
During the failover event, the mirror and the witness incremented the mirroring role
sequence counter. Because the old principal's mirroring role sequence counter is less
than that on the other partner server and the witness server, those two servers have
formed a quorum before the old principal rejoined the session, and new work may have
occurred on the new principal. The old principal takes on the mirror role in the session.
5. When a witness has been set, the principal requires a quorum to serve
the database. If the witness has not been set (the status of the
sys.database_mirroring column mirroring_witness_name is NULL),
then a quorum is not required by the principal to serve the database.
No witness means that no automatic failover can occur. If there is no automatic failover,
there is never a problem with split brain, and the principal does not need to contact
another server to form a quorum.
Figure 1. The sample database mirroring session starts in the High Availability
operating mode.
Physically, all three servers may be on the same site and connected through a local
network, or they may be at independent sites connected through a WAN. Server A and
Server B may change roles, but Server W always remains the witness server.
Now consider what would happen if one of the servers goes down.
24
Figure 2. In High Availability mode, when the principal Server A fails, a failover
occurs.
After the principal server A is lost, the mirror and the witness servers form a quorum
and an automatic failover occurs. If you are able to bring back the original principal
server, then it will take on the mirror role.
Note: To cause a failover in High Availability mode, a failure could occur at many
levels: the physical server could be down, the SQL Server instance on the principal
could be stopped or failed, or the principal database on the server could be
unavailable or suspect. When a principal server is lost in the following scenarios, it
could be cause by any of these events.
Because Servers B and W can form a quorum, and neither can see server A, Server B
can promote itself as the new principal. However, without a mirror server, the mirroring
session is considered exposed.
When you bring back Server A, it becomes the new principal and the mirroring session
is no longer exposed
A single server failure may be a rare event. An even rarer event would be to have two
servers fail. Even though rare, it is useful to inspect the results.
Two servers might fail simultaneously or nearly at the same time, but from the
database mirroring standpoint, the result will be as if one server failed followed by
another. Therefore these scenarios only consider what happens when servers fail in
sequence.
The next two scenarios consider what occurs when the principal Server A failure is
followed by two alternate server failures:
25
Figure 3. Role changes due to principal server loss followed by new principal
loss.
After Server A fails, Server B becomes the new principal, but it cannot send data to a
mirror, so the principal is exposed, even though it can still serve the database. When a
Server A failure is followed by Server B failing, there is no mirroring because Server B is
down.
If you bring back Server A first, it detects from the mirroring_role_sequence number at
the Witness W that the witness has since formed a new quorum. Server A adopts the
role of mirror and waits for Server B to come back. As soon as Server B is brought
back, it will begin the process of mirroring to Server A. If you bring back Server B first,
then you are back to the original scenario shown in HASL1.1.
Note: if Server W is lost after Server A and then Server B is lost, bringing all three
servers down, the switched roles for Server A and Server B will persist
independently of the server restoration sequence.
26
Figure 4. When a witness server loss follows an initial principal server loss, the
new principal cannot serve the database.
When the witness server W is lost after the principal Server A is lost, the new principal
Server B is still the principal but it is isolated, cannot form a quorum, and cannot serve
the database.
If you bring back Server A first, Server B's mirroring_role_sequence number will be one
greater than Server A's, because a failover has occurred. This indicates to Server A that
Server B now has the principal role after Server A did. Server A forms a quorum with
server B and becomes the mirror, and then both servers synchronize. Until Server W is
brought back, no automatic failover can occur.
Note: if Server B is lost after Server A and then Server W is lost, the new roles for
Server A and Server B will persist independently of the server restoration sequence.
27
Figure 5. In High Availability mode, when the mirror Server B fails, no failover
occurs.
No automatic failover will occur and the partners will not exchange roles. When Server
B is restored, all three servers return to their original roles and states.
The following tables show the database states and quorum during the loss and recovery
of the mirror Server B.
Note that the session is exposed without a mirror, because the data is not being placed
in redundant databases.
As soon as you can restore Server B, it will resume its mirror role and when the two
partners are synchronized, the mirroring session is no longer considered exposed.
The next two scenarios consider what occurs when the mirror server B failure is
followed by a failure of the principal Server A or witness Server W.
28
29
Figure 7. A mirror server loss followed by a witness loss leaves the principal
server unable to serve the database.
During the server outages of mirror followed by the witness, the principal Server A
retains its principal role, but because it cannot form a quorum with any other server,
and safety is FULL, it cannot serve the database, and disconnects all users.
If Server B is restored first, mirroring resumes, although no automatic failover is
possible without a witness.
If Server W is restored first, the scenario is the same as shown in Figure 5.
Note: if Server A is lost after Server B and then Server W were lost, bringing back
the servers in any order preserves the same final results.
30
Figure 8. In High Availability mode, when the witness Server W fails first,
mirroring continues.
When you restore Server W, the partner servers Server A and Server B keep their
original roles.
The following tables show the changes of database state and quorum during the failure
and restoration of the witness server.
The next two scenarios consider what occurs when the witness server W failure is
followed by a failure of the principal Server A or mirror Server B.
31
Figure 9. The partner roles remain the same after an initial witness server loss
followed by a principal server loss.
If you bring back server W first, Server B detects from the witness that the last good
principal was server A and so Server B remains the mirror. When you finally bring back
Server A it keeps the principal role.
Note: if Server B is lost after Server W and then Server A were lost, bringing back
the servers in any order will not affect the end results.
32
Figure 10. When the Witness server fails, followed by the Mirror server, the
principal must take its database out of service.
Note: if Server A is lost after first Server W and then Server B are lost, bringing
back the servers in any order will not affect the final results.
33
34
Quorum
Result
state
event
A is lost
Intermediate
B and W
(HASL1.1)
Failover:
A is down
Database
B: Principal,
on B is in
DISCONNECTED
service,
W: Witness,
session is
CONNECTED
exposed
Second
Quorum
Result
event
B is down
None
No
database
(HASL1.2)
in service
W is down
None
(HASL1.3)
Ending
First
state
Server
Result
Second
Server
Back
Back
Final State
A is down
Bring
A: Mirror,
Bring
A: Mirror,
B is down
back A
DISCONNECTED
back B
SYNCHRONIZ
W: Witness
B is down
B: Principal,
W: Witness
SYNCHRONIZ
No
A is down
Bring
A: Mirror
Bring
database
B: Principal,
back A
B: Principal
back W
in service
DISCONNECTED,
W: Witness,
CONNECTED
W is down
not in service
W is down
B is lost
A and W
(HASL2.1)
Database
A: Principal,
A is down
on A is in
DISCONNECTED
(HASL2.2)
service,
session is
exposed
None
No
A is down
Bring
A is down
Bring
A: Principal,
database
B is down
back B
B: Mirror,
back A
SYNCHRONIZ
in service
B is down
W: Witness
W: Witness,
CONNECTED
W is down
None
(HASL2.3)
DISCONNECTED
B: Mirror,
W: Witness
SYNCHRONIZ
No
A: Principal,
Bring
A: Principal,
Bring
database
DISCONNECTED,
back B
SYNCHRONIZED
back W
in service
not in service
B: Mirror,
B is down
SYNCHRONIZED
W is down,
W is down
W: Witness,
CONNECTED
DISCONNECTED
W is lost
(HASL3.1)
A and B
Database
A: Principal,
on A is in
SYNCHRONIZED
A is down
None
(HASL3.2)
No
A is down
Bring
database
B: Mirror,
back W
in service
A is down
Bring
A: Principal,
B: Mirror,
back A
SYNCHRONIZ
service,
B: Mirror,
DISCONNECTED
DISCONNECTED
B: Mirror,
session is
SYNCHRONIZED
W is down,
W: Witness
SYNCHRONIZ
W is down
DISCONNECTED
exposed
B is down
None
No
A: Principal,
W: Witness,
CONNECTED
Bring
A: Principal,
Bring
database
35
in service
DISCONNECTED,
back W
DISCONNECTED,
not in service
not in service
B is down
B is down
W is down,
W: Witness
back B
DISCONNECTED
36
Figure 11. The initial High Availability configuration for three independent
servers has three independent communication lines.
Note: for an explanation of the diagrams on the following pages, see "High
Availability Mode with Server Loss" above.
37
Based on Figure 11, there are three different lines that could break first: A/B, A/W, and
B/W. Note that when a single communication line is down all three servers still operate.
Only the line between the principal and the mirror has any effect, as shown in Table 11.
Table 11. Summary of single-line communication line breaks.
Initial
condition
Event
Quorum
Result
Condition
A: Principal,
SYNCHRONIZED
A/B link
broken
A and W
Database on
A in service,
exposed
A: Principal,
DISCONNECTED
B: Mirror,
SYNCHRONIZED
B: Mirror,
DISCONNECTED
W: Witness,
W: Witness,
CONNECTED
CONNECTED
A/W
A and B
Database on
A in service
A: Principal,
SYNCHRONIZED
B: Mirror,
SYNCHRONIZED
W: Witness,
CONNECTED
B/W
A and B
Database on
A in service
A: Principal,
SYNCHRONIZED
B: Mirror,
SYNCHRONIZED
W: Witness,
CONNECTED
Only the break in the principal/mirror connection has an effect. The other breaks of
principal/witness or mirror/witness do not change the database mirroring session's
behavior.
In summary, what Table HACL1 shows is:
38
Now consider what happens if a second line breaks. The two lines could break
simultaneously, or in sequence.
If two line breaks occur simultaneously, the end result will the same as one line
breaking followed by the other. However, the exact sequence is unpredictable
beforehand; only the subsequent behavior will indicate the sequence to which the
simultaneous break will be equivalent.
For our purposes, therefore, we will only consider sequential line breaks. Table 12
shows the basic scenarios, as named in this section, for communication line breaks in
the High Availability Mode.
Table 12. Most of the communication line breaks at the two-line level become
equivalent to the server-down scenario of one server down.
Scenario
First
line
break
Scenario
Second
line
break
Result
Equivalent
scenario
for
remaining
servers
See
scenario
HACL1.1
A/B
HACL1.2
A/W
Server A
isolated
Server A
down
(none)
HACL1.3
B/W
Server B
isolated
Server B
down
HASL2.1
HACL2.1
A/B
Server A
isolated
Server A
down
HASL1.1
HACL2.2
B/W
Server W
isolated
Server W
down
HASL3.1
HACL3.1
A/W
Server W
isolated
Server W
down
HASL3.1
HACL3.2
A/B
Server B
isolated
Server B
down
HASL2.1
HACL2.1
HACL3.1
A/W
B/W
What Table HACL2 shows is that all sequential two-line communication breaks are
equivalent to the single-server-down scenarios of the previous section, so we won't
repeat any analysis of them here.
What is important to note is that:
Only one scenario with two communication breaks leads to a failover: the
principal/witness line break followed by the principal/mirror line break.
39
Figure 12. In High Availability mode, when the principal/mirror link is broken and
followed by a break in the principal/witness line, no failover occurs
After the principal/mirror link is broken, followed by the principal/witness break, Server
A is isolated and takes its database out of service. Server B and W do not form a
quorum because Server A may have done work that is not on Server B.
If the principal/witness (A/W) line break is repaired first, Server A will resume its
principal role, in a DISCONNECTED state. However, no mirroring will be occurring
because there the line between the principal and the mirror is still not repaired.
If the principal/mirror (A/B) line break is repaired first, Server A will resume its
mirroring to Server B although without a witness, so the session is exposed. However,
no automatic failover is possible until the principal/witness line is finally repaired.
40
41
Table 13. Summary of one-line and two-line breaks for Safety FULL and three independent servers in the High Availability
mode.
First
Quorum
Result
Event
A/B link
A and W
Intermediate
Second
state
Event
Quorum
Result
Ending state
Repaired
Database
A: Principal,
A/W link
No database
A: Principal,
broken
on A in
DISCONNECTED
broken
in service,
DISCONNECTED, cannot
(HACL1.1)
service,
B: Mirror,
(HACL1.2)
A isolated
serve db
exposed
DISCONNECTED
B: Mirror, DISCONNECTED
W: Witness
W: Witness
B/W link
Line
B and W
Database on
A: Principal, DISCONNECTED
broken
A and W
A in service,
B: Mirror, DISCONNECTED
(HACL1.3)
exposed
A/B
A: Principal, SYNCHRONIZED
B: Mirror, SYNCHRONIZED
W: Witness
A/B
W: Witness
B isolated
A/W link
Database
A: Principal,
broken
A and B
on A in
SYNCHRONIZED
(HACL2.1)
service
B: Mirror,
service,
SYNCHRONIZED
exposed
W: Witness
B and W
(HACL2.2)
B/W link
A and B
Database on
A is not in service
B is in
A/W
B: Principal, DISCONNECTED
B: Principal, DISCONNECTED
W: Witness
W: Witness
A/W
A: Mirror, DISCONNECTED
Database on
A: Principal, SYNCHRONIZED
broken
A is in
A: Principal, SYNCHRONIZED
B: Mirror, SYNCHRONIZED
B: Mirror, SYNCHRONIZED
(HACL2.3)
service
W: Witness, isolated,
W: Witness
DISCONNECTED
B/W link
Database
A: Principal,
A/W link
broken
A and B
on A in
SYNCHRONIZED
broken
(HACL3.1)
service,
B: Mirror,
exposed
SYNCHRONIZED
A and B
Database on
A: Principal, SYNCHRONIZED
A is in
B: Mirror, SYNCHRONIZED
B: Mirror, SYNCHRONIZED
W: Witness, isolated,
W: Witness
service
B/W
A: Principal, SYNCHRONIZED
DISCONNECTED
W: Witness
A/B link broken
A and W
Database on
A: Principal, DISCONNECTED
A is in
B: Mirror, DISCONNECTED,
B: Mirror, DISCONNECTED
service,
isolated
W: Witness
exposed
B/W
A: Principal, DISCONNECTED
W: Witness
42
Scenario HACL4: Two sites with the witness on the mirror site
When there is only one line of communication between the sets of servers, you must
choose where to put the witness server. To start with, assume you put the witness with
the mirror database server. There will be just one line of communication between the
two sets of servers, and it line may be interrupted, as shown in Figure 13.
Figure 13. The communication line between the principal and the
mirror/witness site is interrupted.
Server A cannot see the witness Server W or the mirror database's Server B, and
therefore cannot form a quorum. Server B and Server W can form a quorum, but
neither can see the principal on Server A. The result of the line break is illustrated in
Figure 14.
Figure 14. Failover occurs when communication is interrupted and the witness
is on the mirror site.
Because Server A cannot see the witness Server W or its former mirror partner Server
B, it must enter a disconnected state and make its database unavailable.
Server B and Server W can form a quorum. Server B cannot see Server A, and Server
W Server B attempts to become the principal and bring its database online. Because
Server W cannot see Server A, it agrees with Server B. Server B now has a quorum,
takes on the principal role in this session, and recovers its database.
If you restore the communication line, Server A will see that Server B is a principal, and
it will also detect that the witness Server W views Server B as the principal. Server A
will change its role to that of mirror, and attempt to synchronize with new principal.
When done, the resulting configuration is illustrated in Figure 15.
43
Figure 15. The restored version of this scenario has mirroring in the reverse
direction.
To summarize: When the witness resides on a remote site with the mirror, automatic
failover will occur if the communication line between sites is interrupted.
Scenario HACL5: Two sites with the witness on the principal site
In this High Availability scenario, assume you put the witness server on the same site
as the principal database's server, as shown in Figure 16, and the communication
between the two sites is interrupted.
44
In a High Availability configuration with only one line of communication, the witness
server resides either with the principal or the mirror.
When the witness resides on a remote site with the mirror, automatic failover will
occur if the communication line between sites is interrupted.
When the witness server is on the same site as the principal, and the mirror on a
remote site, communication interruption between sites will not cause an
automatic failover.
not possible. There is only one communication line between the servers, and it can be
interrupted, resulting in the configuration illustrated in Figure 18.
Figure 19. If the mirror server is unavailable in a High Protection scenario, the
principal database is unaffected.
Case 3. If the principal database becomes unavailable in a High Protection scenario, the
mirror database must remain a mirror, but it will be in a disconnected state, as shown
in Figure 20.
Figure 20. If the principal becomes unavailable in High Protection, the mirror
database will enter a disconnected state.
Because the High Protection operating mode does not have a witness set, disruptions
do not cause the principal database to become unavailable, and the mirror database
remains in a recovering state.
46
47
48
For each partner, the Sends/sec and Receives/sec counters show the number of discrete
send and receive actions, giving gives you a sense of the rate at which the servers are
communicating. The Bytes Sent/sec and Bytes Received/sec counters show the total
number of bytes sent and received on each partner server for those sends and receives.
Profiler Events
SQL Server 2005 Profiler contains one event class for database mirroring. The
Database:Database Mirroring State Change event will record whether the server being
monitored undergoes a state change. (See the topic "Database Mirroring State Change
Event Class" in SQL Server Books Online.) It is helpful to include the Database Name
and the State columns when using this event class. You can use this event to alert you
to any state change in the database mirroring session.
Troubleshooting Setup
If you've installed database mirroring but it won't start, retrace the steps that you took
during setup.
7. Make sure that the mirror server has caught up close enough in time to the
principal. If you see the following message when you attempt to start mirroring,
The remote copy of database "AdventureWorks" has not been rolled forward to a
point in time that is encompassed in the local copy of the database log. (Microsoft
SQL Server, Error: 1412)
you know that the mirror is not caught up. You need to apply transaction log
backups from the principal to the mirror (with NORECOVERY) in order to catch the
mirror up to a point where it can start receiving log records from the principal.
8. Make sure that the SQL Server Windows service accounts on each server are trusted
on each other server. If the servers are on non-trusted domains, make sure the
certificates are correct.
9. Make sure that the endpoints are not just defined, but also started, by querying the
sys.database_mirroring_endpoints catalog view:
49
50
Because the mirror server is continuously replaying data modification transactions that
it receives from the principal, the data cache on the mirror server will be 'hot'. In other
words, the data cache will be populated with data and index pages based on the same
kinds of changes made on the principal. To make the mirror cache even more like the
principal's cache, database mirroring also passes SELECT hints to the mirror so that the
cache used for querying data also is reproduced on the mirror server. This will aid in
making the mirror more like the principal and will reduce the remaining redo time in the
case of a failover. Obviously, any additional activity on the mirror server, including
queries against database snapshots, will affect the state of the cache and could increase
the duration of time to finish the redo phase in the event of a failover.
To test a server failure, just shut down the SQL Server instance, either through
SQL Configuration Manager or using SHUTDOWN WITH NOWAIT.
To test a database failure, stop the SQL Server service and rename the
underlying .mdf file, and then restart the SQL Server.
To cause a redo error on the mirror, add a file to the principal database on a
driver volume that does not exist on the mirror server.
Another way to cause a redo error on the mirror is to force the mirror server
data file to run out of disk space.
To force a database shutdown on the principal, force the principal's data file to
run out disk space.
To cause a log buffer hardening to fail on the principal or mirror, force the log file
to run out of disk space.
51
Multi-Database Issues
Many applications make use of multiple databases on a single server. One application
may reference multiple databases, or perhaps many applications all make use of several
databases. However, database mirroring works with a single database at a time. You
need to take this into account when designing mirroring into your database
architecture.
If you desire the High Availability mode, your best fit will be when one application
matches up with one database. Then if an automatic failover occurs, the application no
longer requires any databases on the principal server. Consider what might happen if
you have multiple databases on a single server and operate in the High Availability
mode. If there is a physical server outage, a SQL Server instance failure, or a
communication failure, all the databases would automatically fail over to the standby
server, and their mirrors would then become new principal databases. If the witness is
visible, the application could connect to the new principal databases. But what would
happen if one of the databases incurred a torn page from a disk fault, so that only the
52
one database failed over? In that case, it might be impossible to get the application to
connect to all the right databases.
Therefore applications that rely on multiple databases will not be good candidates for
the High Availability mode of database mirroring. You may be able to use safety OFF,
with the realization that you will not have automatic failover, but you will have a highperformance method of keeping another database server in sync.
Log Shipping - Assume SQL Server built-in log shipping with a separate
monitoring.
In this section we'll compare the basic features of those four technologies, and drill
down into areas where database mirroring may complement or prove a better solution.
The following table shows a number of availability features for all four technologies.
Table 14. Comparing SQL Server 2005 High Availability technologies.
Category
Failover
characteristics
Availability
Feature
Database
Mirroring
(HA Mode)
Failover
Clustering
Log
Shipping
Transactional
Standby
Type
Hot
Hot
Warm
Hot
Automatic
role change
Yes
Yes
Custom
coding
required
Custom coding
required
Failover
preserves
committed
work
Yes
Yes
No
No
Failover type
Automatic
and Manual
Automatic
and
manual
Database
downtime
during
Seconds
30 seconds
+ database
recovery
Variable
Variable
Replication
53
failover
Physical
configuration
Management
Client Access
Redundant
storage
locations
Yes
No (shared
disk)
Yes
Yes
Hardware
requirements
Standard
servers
Cluster
Certified
Servers
and
Storage
Standard
servers
Standard
servers
Physical
distance limit
None
100 Miles
None
None
Additional
server role
Witness
None
Monitor
Distributor
Complexity
level
Low
High
Low
Medium
Standby
Accessible
Via
database
snapshots;
possible
performance
impact
No
R/O but
incompatible
with
restores
Multiple
Secondaries
No
No
Yes
Yes
Load delay
on
secondary
No
No
Yes
No
Scope of
availability
Database
Server
instance
Database
Database
Client
redirect
Support in
ADO.NET
and SQL
Native
Client
None
required,
Virtual IP
Custom
coding
required
Custom coding
required
The above table summarizes many of the characteristics of all four high availability
technologies. The next sections make some more detailed comparisons.
instance on a cluster gets one virtual server name and IP address that remains the
same no matter what node of the cluster is hosting the instance.
If you need database protection at the server level (for example, your application
requires access to many databases on the same database server simultaneously),
failover clustering may be a more appropriate choice. However, if you are concerned to
provide availability for one database at a time, database mirroring has a number of
advantages.
Unlike clustering, database mirroring does not require proprietary hardware and does
not have a potential failure point with shared storage. Database mirroring brings the
standby database into service much faster than any other high availability technology,
and works well with new capabilities in ADO.NET and SQL Native Access Client for
client-side failover.
You cannot use database mirroring within a cluster, but you may consider using
database mirroring as a method for creating a hot standby for a cluster instance
database. If you do, be forewarned that because a cluster failover is longer than the
timeout value on database mirroring, a High Availability mode mirroring session will
react to a cluster failover as a failure of the principal server. It would then put the
cluster node into a mirroring state.
55
Figure 24. You may log ship a principal database to a remote location.
The advantage here is that in the event of a loss of the entire site, the data is available
on the secondary site. However, in the event of a database mirroring failover, log
shipping from Server B to the remote standby will normally have to be reinitialized.
Another scenario for using log shipping to complement database mirroring would be as
a local standby for the principal server where the database mirroring session is being
used for disaster recovery. In this case, the mirroring session is in the High Performance
mode, with the mirror on a remote site as the remote standby.
56
Figure 25. You can log ship a principal database as a method of preserving all
transactions.
In the High Performance mode, there is a potential for data loss if the principal fails and
the mirror is recovered using a forced service recovery. If you are log shipping the old
principal, and if the transaction log file of the old principal is undamaged, you can make
a 'tail of the log' backup of the principal to get the last set of log records from the
transaction log. If the standby log shipping database has had every other transaction
log backup applied to it, you can then apply the tail of the log backup to the standby
server and not lose any of the old principal's data. You can then compare the data in
the log shipping standby server with the remote database and potentially copy missing
data to the remote server.
In any case, comparing log shipping to database mirroring should make it clear that it
is important to keep database and transaction log backups of the principal database.
Applying these log backups to a log shipping server can supplement your database
mirroring configuration.
57
Conclusion
Database mirroring is a new SQL Server 2005 technology that can deliver high
availability and high performance solutions for database redundancy. In database
mirroring, transaction log records are sent directly from a principal to a mirror database
whenever the principal's transaction log buffer is written to disk (hardened). This
technique can keep the mirror database nearly up to date with the principal, and with
no loss of committed data. In the High Availability operating mode, if the principal fails,
the mirror server will automatically become a new principal and recover its database.
Using the new ADO.NET or SQL Native Access Client drivers, applications can also
perform an automatic failover from the client servers as well. Database mirroring
becomes an important new option in the array of high availability technologies
supported by SQL Server 2005.
For more information:
SQL Server TechNet site: http://www.microsoft.com/technet/prodtechnol/sql
SQL Server Developer Center: http://msdn.microsoft.com/sql
Microsoft SQL Server site: http://www.microsoft.com/sql/
Did this paper help you? Please give us your feedback. On a scale of 1 (poor) to 5
(excellent), how would you rate this paper?
58