Академический Документы
Профессиональный Документы
Культура Документы
Database Mirroring
by Michael Otey
McGraw-Hill/Osborne. (c) 2010. Copying Prohibited.
MicrosoftSQLServer2008:HighAvailabilitywithClustering&DatabaseMirroring
SQL Server 2008 Standard or Enterprise editions Database mirroring is only supported in the SQL Server 2008
Standard and Enterprise editions. The SQL Server 2008 Standard Edition is limited to synchronous mirroring mode.
The SQL Server 2008 Enterprise Edition supports both synchronous and asynchronous modes. More information
about mirroring components and modes is presented in the next section. The SQL Server 2008 Express Edition can
function only as a witness.
Full recovery model All mirrored databases must use the Full recovery model. You cannot mirror a database that
uses the Simple or Bulk recovery models.
Single mirror target Database mirroring is limited to use between two systems. You cannot set up multiple database
mirroring targets. If you need to send database transactions to multiple targets, then you must use log shipping.
User databases only You can set up database mirroring only for user databases. You cannot mirror any of the system
databases including the master, model, msdb, or tempdb. In addition, only databases are mirrored. Other database
entities such as logins that may be required by applications are not mirrored. To support full automatic failover, you
must manually add logins to the mirror system.
McGrawHill/Osborne,TheMcGrawHillCompanies(c)2010,CopyingProhibited
MicrosoftSQLServer2008:HighAvailabilitywithClustering&DatabaseMirroring
independent third party that determines which system will act as the principal server.
Database mirroring can be set up with a single database, or it can be set up for multiple databases. Database mirroring is
initialized by taking a backup of the database that you want to mirror on your principal server and then restoring that
backup to your mirroring server. This puts the underlying database data and schema in place on both the principal and the
mirror servers. In other words, the mirrored database must exist on the mirror server before the mirroring process can
begin. The backup and restore process can use any of SQL Servers standard media types, including tape or disk.
Database mirroring works by capturing transaction logs on the principal server and sending them on to the mirror server.
So in essence, the database mirroring is a real-time log shipping application. When a client system writes a transaction on
the principal server, that transaction actually gets written to the principal servers transaction log file before it is written into
the data file. Next, database mirroring monitors the transaction log, pulling out transaction records for the mirrored
databases and sending them to the mirror server. The mirror server receives the transaction where it gets written to the
mirroring servers transaction log. To keep its data files up-to-date, the mirroring server is essentially in a state of
continuous recovery, taking the data from the log and updating the data file.
After the mirroring server has written the record to its log, it sends an acknowledgment to the principal server that the
record has been received. For synchronous mirroring mode operations, the principal server waits to receive an
acknowledgment from the mirroring server before sending its response back to the client, telling it the operation is
completed. For asynchronous mode the principal does not wait for a response from the mirror before replying to the client
and allowing the client to continue. More information about database mirroring modes is presented in the next section of
this chapter.
Database mirroring can be set up so database failover can be performed either automatically or manually. Automatic
failover is only supported for asynchronous database mirroring. A third system that acts as a witness is also required for
automatic failover. Each system gets a vote as to who will be the primary server. It takes two votes to decide on the primary
server. This is important because its possible that the communications between the primary server and the mirror server
could be cut off, in which case each system would elect itself to function as the primary server. The witness casts the
deciding vote.
Database Mirroring Modes
Database mirroring can operate in one of two modes depending on the level of performance and data protection thats
required: high safety mode or high performance mode. The database mirroring mode is controlled by the Transaction
Safety database property. When the Transaction Safety property is set to OFF, database mirroring operates in high
performance asynchronous mode. If Transaction Safety is set to FULL, then database mirroring will operate in high safety
synchronous mode. You can set the Transaction Safety property using the ALTER DATABASE command on the principal
server as illustrated in the following listings:
-- Turn on high performance mode
ALTER DATABASE <database> SET PARTNER SAFETY OFF
-- Turn on high safety mode
ALTER DATABASE <database> SET PARTNER SAFETY FULL
If there is no witness, then database mirroring operates in high safety mode without automatic failover. In this case if the
principal database is unavailable, the mirror is suspended, but service can be manually forced to the mirror. If the mirror
becomes unavailable, then the principal continues to run.
High Safety Mode with a Witness
If the witness is present, then the synchronous mode operates in high safety mode with automatic failover. In this mode,
database availability is the highest priority, and the database will be available as long as two of the three database
mirroring components (principal, mirror, witness) are present. If the principal server becomes unavailable, the mirror will
initiate an automatic failover and will assume the role of the principal. If the mirror server becomes unavailable, then
Page 3 / 5
ReprintedforMSUSR/vraraus@microsoft.com,Microsoft
McGrawHill/Osborne,TheMcGrawHillCompanies(c)2010,CopyingProhibited
MicrosoftSQLServer2008:HighAvailabilitywithClustering&DatabaseMirroring
operation continues unaffected on the principal server. If the witness becomes unavailable, then operation continues
unaffected on the principal server, but no failover can happen until the witness is returned and a quorum can be
reestablished.
Synchronous Mode Database Mirroring Data Flow
Page 4 / 5
ReprintedforMSUSR/vraraus@microsoft.com,Microsoft
McGrawHill/Osborne,TheMcGrawHillCompanies(c)2010,CopyingProhibited
MicrosoftSQLServer2008:HighAvailabilitywithClustering&DatabaseMirroring
Figure 6-2: Using database mirroring and database snapshots to create a read-only reporting server
In Figure 6-2, you can see the principal database is populated with data from the organization OLTP line-of-business
application. Database mirroring is used to create a mirrored copy of that database on a remote server. Then database
snapshots are used on the mirror database to create a read-only copy of the mirrored database. That database snapshot
can be freely accessed in read-only mode by queries and reporting applications.
Combining Database Mirroring and Failover Clustering
Windows failover clustering and database mirroring are high-availability solutions that are designed to address different
levels of system availability. Windows failover clustering is designed to provide server-level protection. Failover clustering
uses multiple servers to provide protection from server failure by allowing the workload of the failed server to be
automatically assumed by one of the other servers. Windows failover clustering can provide protection from both planned
and unplanned downtime. Database mirroring is a database-level solution. More information about Windows failover
clustering can be found in Chapter 2. Database mirroring enables data protection by sending transaction log records of a
primary database to a standby database.
While Windows failover clustering and database mirroring can be used separately, they can also be used together.
Combining these technologies can provide a more complete level of overall system protection. Database mirroring can be
used to enhance the availability provided by Windows failover clustering by providing protection from site and disk failures
for mission-critical databases. Figure 6-3 shows an example of using Windows failover clustering in conjunction with
database mirroring for site-level protection of your vital databases.
Page 5 / 5
ReprintedforMSUSR/vraraus@microsoft.com,Microsoft
McGrawHill/Osborne,TheMcGrawHillCompanies(c)2010,CopyingProhibited