Database Mirroring Questions and Answers
Database Mirroring Questions and Answers
This is very interesting topic and consists of very wide range of terminologies and
scope. I will cover this topic in two blogs so that I can touch base all the possible Questions
from Database Mirroring.
1. What is Database Mirroring?
Database mirroring was introduced with Microsoft SQL Server 2005 technology that can be used to
design high-availability and high-performance solutions for database redundancy.
In database mirroring, transaction log records are sent directly from the principal database to the mirror
database. This helps to keep the mirror database up to date with the principal database, with no loss of
committed data. If the principal server fails, the mirror server automatically becomes the new principal
server and recovers the principal database using a witness server under high-availability mode. We will
discuss these modes later. Fundamentally to summarize there are three jargon to understand – Principal
database is the active live database that supports all the commands, Mirror is the hot standby and
witness which allows for a quorum in case of automatic switch over.
8. What is a Mirror?
This is the Hot standby server which has a copy of the database.
In asynchronous mode, committed transactions are not guaranteed to be recorded on the mirror server.
In this mode, the primary server sends transaction log pages to the mirror when a transaction is
committed. It does not wait for an acknowledgement from the mirror before replying to the application
that the COMMIT has completed. Should a failure occur on the primary server, it is possible that some
committed transactions may be lost when the mirror server takes over.
20. Is it possible to perform read only operation at mirrored database in mirror server?
Yes, using database snapshots.
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.
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.
30. Why we get the below error message while configuring database mirroring?
Msg 1416, Level 16, State 31, Line 3. Database is not configured for database mirroring
We need to restore the Full backup from principal server using With NoRecovery option and also one
transactional log backup from principal server using With NoRecovery option and then start configuring
mirroring.
31. Can we configure a single database to be mirrored to more than one server. i.e) One source &
many destination like logshipping?
No, It is not possible.
A database snapshot is a view of what the source database looked like at the time at which the snapshot
was created. This means that all the objects will be the same as what it was when the snapshot was taken
and all of the data will be exactly as it was then. To use database snapshots to recover from an unwanted
DML statement, you need to have a suitable snapshot in place. Snapshots can only be created by using a
T-SQL statement.
When you create a snapshot a sparse file is created for each data file
When data is modified in the source database for the first time, the old value of the modified data
is copied to the sparse file
If the same data is the subsequently changed again, those changes will be ignored and not copied
to the snapshot
When you query the snapshot, it first checks if the data is available in the snapshot. If it’s there it
reads if from the snapshot. If it’s not there, I reads through to the source database and gets the
data from there instead, because that means the data has not yet changed since the time the
snapshot was taken
When a database snapshot is created, a sparse file is added for each database file in the database of which
the snapshot was taken. A sparse file is basically an empty file. It does not contain any data until a change
is made to the source database
The maximum size a sparse file can grow to is the size of the original file at the time of the
database creation
No.
9) Can we detach a database snapshot?
No.
Database snapshots depend on the source database. They can only be created on the same server
as where the database resides (or the server to which the database is mirrored.)
While there are snapshots present, you cannot drop the database or add any new files to it
Once a database snapshot becomes suspect it cannot be saved. It just has to be deleted. This can
happen if the snapshot runs out of space or reaches the maximum sparse file size limit
You cannot create indexes on snapshots, they are strictly read only
The user permissions are exactly the same as it was in the source database. You cannot grant a
user access to a snapshot. You have to grant the access in the source database and then take
another snapshot first before the user will be able to access it
Using a mirror database that you are maintaining for availability purposes to offload reporting.
12) Can we configure mirroring between Standard Edition & Enterprise Edition or Vice Versa?
No it’s not possible, both principal and mirror should have same edition
No
14) Can I create multiple endpoints for configuring different databases for mirroring and point
each database to unique endpoint?
No
15) Can I configure a single database to be mirrored to more than one server. i.e) One source &
many destination like logshipping?
No
16) How to know the database mirroring connection time out in Mirroring?
17) How can I increase Heartbeat time between principal and mirror server? By default its 10 sec.
ALTER DATABASE AdventureWorks SET PARTNER TIMEOUT 30
If principle is down mirror will be disconnected with in recovery instead of synchronized with restoring
If mirroring is set to paused from principle then both principle & mirror in suspending
There are six methods are available for monitoring the Database Mirroring
a) Database Mirroring Monitor:- Database Mirroring Monitor is a GUI tool that shows update status and
to configure warning thresholds.
To open DM Monitor:- Right click on Principal Database > Tasks > Select Launch Database Mirroring
Monitor.
b) SQL Server Management Studio:- A green arrow on the mirror server is indicates running well. A red
arrow indicates problems that need to investigate.
c) SQL Server Log:- It provides information of Mirroring establishment and status. If any errors occur it
will be logged to SQL Server log and Windows event log.
d) Performance Monitor:- It can provides real-time information about Database mirroring. We can use
performance counters to get status of the database mirroring such as Bytes received/sec, Bytes sent/sec,
Transaction delay etc.
e) Profiler:- Profiler many events are providing the status of the Database mirroring
f) System Stored Procedures:-
sp_dbmmonitoraddmonitoring
sp_dbmmonitorchangemonitoring
sp_dbmmonitorhelpmonitoring
sp_dbmmonitordropmonitoring
22) What will be the impact if we add data files to the Primary database in Database Mirroring?
Data files will be added to the Mirror database if the identical location is present at the mirrored server
without any issues.
23) What will be the impact if we add data files to the Primary database with a location which is
not present on the Mirrored server in Database Mirroring?
Database mirroring will not work in this case. We have to break the Mirroring and take a Log backup of
the Primary database and restore it on the Mirror database using “WITH MOVE” and “NORECOVERY”
option. Once it’s done then Reestablish the mirroring.
24) If we add any users to the Primary database, will it be copied to the Mirror databases or not?
Yes, It will be copied to the Mirror database with the permissions. However you have to create the login
manually with the same SID.s
.NET Example
Log buffer is a small contiguous memory structure, only 60k maximum, to host in memory transaction
logs per database. When the transaction is committed, entire buffer will be written to transaction log file
before commit finishes.
Automatic page repair is supported by database mirroring. After certain types of errors corrupt a page,
making it unreadable, a database mirroring partner (principal or mirror) attempts to automatically
recover the page. The partner/replica that cannot read the page requests a fresh copy of the page from its
partner. If this request succeeds, the unreadable page is replaced by the readable copy, and this usually
resolves the error, this whole process is called Automatic Page Repair.
30) What are the error types which cause and Automatic Page Repair attempt?
31) What are the page types which are not repairable using Automatic Page repair option?
Automatic page repair cannot repair the following control page types:
Allocation pages: Global Allocation Map (GAM) pages, Shared Global Allocation Map (SGAM) pages,
and Page Free Space (PFS) pages.