DBMirroring FAQS 1740971251
DBMirroring FAQS 1740971251
availability by sending the log buffer between a principal server (the primary) and a mirror
server (the secondary).
Key Components
Mirroring Modes
Prerequisites
sql
sql
3. Configure Mirroring:
o Use SQL Server Management Studio (SSMS) to configure mirroring.
o Connect to the principal server, right-click the database, select "Tasks," then
"Mirror," and follow the wizard to set up the mirror server and (if desired) the
witness server.
4. Start Mirroring:
o Once configured, start the mirroring session.
sql
sql
sql
• High Availability: Quick failover to the mirror server ensures minimal downtime.
• Data Protection: Synchronous mirroring ensures no data loss.
• Automatic Failover: With a witness server, automatic failover is possible.
Disadvantages:
Mirroring is an effective method for enhancing the availability and reliability of SQL Server
databases
• SYNCHRONIZING
• SYNCHRONIZED
• SUSPENDED
• PENDING_FAILOVER
• DISCONNECTED
• SYNCHRONIZING: The mirror database is catching up with the principal database. Log
records are being sent from the principal to the mirror server. This state indicates that the mirror
database is not yet fully synchronized with the principal.
• SYNCHRONIZED: The mirror database is fully synchronized with the principal database.
All transactions are committed on both the principal and mirror databases. This state indicates
that the databases are in sync, and failover can occur without data loss.
• SUSPENDED: The mirroring session has been temporarily paused. This can happen due to
manual intervention or issues such as network problems. In this state, the mirror database is not
receiving transaction log records from the principal database.
• PENDING FAILOVER: A failover is in progress. This state indicates that the principal
database is failing over to the mirror server. Once the failover is complete, the mirror server will
become the new principal server.
• DISCONNECTED: The principal and mirror servers cannot communicate. This state
indicates a network issue or that one of the servers is down. The mirroring session will resume
once the communication is restored.
• 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.
• 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.
• SUSPENDED: SUSPENDED is a persistent state that survives partner shutdowns and startups.
• 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.
• 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.
• DISCONNECTED: The partner has lost communication with the other partner.
Yes, you can configure database mirroring between a 32-bit and a 64-bit machine in SQL Server. The key
requirements are ensuring both systems are running compatible versions of SQL Server, and they are
properly networked and configured for database mirroring
Yes, you can configure Log Shipping and Database Mirroring together in SQL Server. This combination
allows you to leverage the benefits of both high availability and disaster
But it will very complicated, due to lsn mismatch. I have never done but google source I have copied the
above ans
No, you cannot rename a mirrored database in SQL Server directly while it is part of a mirroring
session. This is because database mirroring relies on the specific naming conventions to maintain
the state and synchronization between the principal and mirror databases.
If you need to rename a mirrored database, you would have to break the mirroring session first,
rename the database, and then reconfigure the mirroring. Here are the steps you could follow:
sql
ALTER DATABASE [YourDatabase] SET PARTNER OFF;
sql
sql
No, it's not strictly required for the drive letters to be the same on both servers involved in a
database mirroring configuration. However, having the same drive letters can simplify the
configuration and management of the databases. Here are a few considerations:
1. Backup and Restore Paths: If the drive letters are different, you'll need to adjust the
backup and restore file paths accordingly during the initial setup.
2. Script Adjustments: Any scripts or maintenance tasks that refer to specific drive paths
will need to account for the differences.
3. Log Shipping Considerations: If you're using log shipping in conjunction with database
mirroring, consistent drive letters can simplify the configuration.
If the drive letters are different on the principal and mirror servers in your database mirroring
setup, you'll need to take a few additional steps to add a new datafile. Here's a step-by-step guide
to help you through the process:
Step-by-Step Guide
oEnsure that you specify the appropriate path and filename for the new datafile on
the principal server.
2. Backup the Transaction Log on the Principal Server:
o After adding the datafile, take a transaction log backup on the principal server to
capture the changes:
sql
sql
4. Resume Mirroring:
o Resume the mirroring session to continue synchronization between the principal
and mirror databases:
sql
Summary
• Principal Server: Add the datafile and take a transaction log backup.
• Mirror Server: Copy and restore the transaction log backup, specifying the appropriate
path for the new datafile.
• Resume Mirroring: Ensure the databases are in sync and mirroring continues as
expected.
If you need to change the collation of a database that is part of a mirroring setup, you will need
to break the mirroring session, change the collation, and then reconfigure the mirroring. Here are
the steps you can follow:
sql
sql
sql
Summary
• Principal and Mirror Databases: Must have the same collation settings.
• Steps: Remove mirroring, change collation, reconfigure mirroring.
1. Automatic Failover
• Description: In this scenario, the mirror server automatically takes over the principal role
without any manual intervention.
• Requirements:
o High-safety mode with automatic failover: The mirroring session must be
configured in synchronous mode with a witness server.
o Witness Server: A third server (witness) must be involved to monitor the health
of the principal server.
o Availability: Ensures minimal downtime.
2. Manual Failover
• Description: The DBA initiates the failover manually, allowing planned maintenance or
controlled failover.
• Requirements:
o High-safety mode: The mirroring session must be in synchronous mode.
o Command: Execute the following on the principal server to initiate the failover:
sql
• Description: This type of failover is used when the principal server is not accessible, and
immediate service is required.
• Requirements:
o High-performance mode: The mirroring session must be in asynchronous mode.
o Risk: There is a risk of data loss since the mirror server might not have all the
latest transactions.
o Command: Execute the following on the mirror server to force service:
sql
Planned
Manual Failover High-safety DBA None
Maintenance
In SQL Server high availability and disaster recovery solutions, "hot standby" and "warm
standby" refer to different configurations and readiness levels of standby servers.
Hot Standby
• Description: A hot standby server is fully operational and synchronized with the primary
server. It can take over immediately in case of a primary server failure, with minimal
downtime.
• Example: Database Mirroring in high-safety mode with automatic failover and Always
On Availability Groups with synchronous-commit mode.
• Characteristics:
o Real-time Synchronization: The standby server receives real-time updates and is
always in sync with the primary server.
o Automatic Failover: The failover process is automatic and quick, ensuring high
availability.
o Immediate Availability: The standby server is ready to take over instantly,
minimizing downtime.
Warm Standby
• Description: A warm standby server is not fully synchronized with the primary server
but can be brought online relatively quickly. It requires some manual intervention and
might have a short period of downtime.
• Example: Log Shipping and Database Mirroring in high-performance mode.
• Characteristics:
o Periodic Synchronization: The standby server receives periodic updates (e.g.,
transaction log backups) from the primary server.
o Manual Failover: The failover process requires manual intervention to bring the
standby server online.
o Short Downtime: The standby server may require some time to catch up with the
primary server, resulting in a short period of downtime.
Sure, let’s dive into how log transmission and transaction commits work in High Performance
Mode and High Safety Mode in SQL Server Database Mirroring.
• Log Transmission:
o In this mode, transaction log records are sent to the mirror server asynchronously.
o The principal server does not wait for the mirror server to acknowledge receipt of
the log records.
o This reduces the overhead on the principal server and allows transactions to
commit faster, but at the risk of potential data loss.
• Transaction Commits:
o Transactions on the principal server are committed as soon as the transaction log
records are written to the local log file.
o The principal server proceeds without waiting for the mirror server to
acknowledge the log records, resulting in lower transaction latency.
• Log Transmission:
o In this mode, transaction log records are sent to the mirror server synchronously.
o The principal server waits for the mirror server to acknowledge the receipt and
hardening of the log records before committing the transaction.
o This ensures that both the principal and mirror databases are in sync, providing
high data safety.
• Transaction Commits:
o Transactions on the principal server are committed only after the mirror server has
acknowledged that the transaction log records are written to its local log file.
o This adds some latency to the transaction commit process but guarantees that no
data is lost in case of a failover.
Summary of Differences
Log
Mode Transaction Commits Pros Cons
Transmission
Choosing the appropriate mode depends on your requirements for data safety versus transaction
performance. High Performance Mode is suitable for scenarios where performance is critical and
occasional data loss is acceptable. High Safety Mode is preferred when data integrity and
consistency are paramount.
sql
ALTER DATABASE [YourDatabase]
SET PARTNER SYNC OFF;
sql
ALTER DATABASE [YourDatabase]
SET PARTNER SYNC ON;
Example
Here's an example of how to change the operating mode for a database named MyDatabase:
Set to High Performance Mode (Asynchronous)
sql
ALTER DATABASE [MyDatabase]
SET PARTNER SYNC OFF;
sql
ALTER DATABASE [MyDatabase]
SET PARTNER SYNC ON;
No, SQL Server database mirroring requires setting up endpoints for communication between the
principal and mirror servers. Endpoints are necessary to establish a secure and reliable
connection between the servers involved in the mirroring session.
Here's a brief overview of the steps to create and configure mirroring endpoints:
sql
sql
sql
GRANT CONNECT ON ENDPOINT::[MirroringEndpoint] TO
[MirrorServerLogin];
o On the mirror server, grant CONNECT permissions to the principal server's login:
sql
sql
sql
Endpoints are essential for establishing the communication channels between the principal and
mirror servers, enabling them to exchange transaction log records and maintain synchronization.
Q: Suppose your table size is of 300 GB and you have to rebuild it.
Tell me Q: what is the precautionary step you will take so that your
mirroring should not be effected?
Rebuilding a large table in a database mirroring setup requires careful planning to ensure that
mirroring is not adversely affected. Here are some precautionary steps you should take:
Precautionary Steps
sql
sql
sql
Summary
Moving a datafile in a database that is part of a mirroring session requires careful planning to
ensure that the mirroring session remains consistent and uninterrupted. Here are the steps to
move a datafile in a mirrored database:
sql
sql
sql
o Physically move the datafile to the new location using your preferred file
management tool (e.g., Windows Explorer, command line).
5. Bring the Principal Database Offline:
o Temporarily take the database offline to ensure the file move is complete:
sql
sql
sql
o Physically move the datafile to the new location on the mirror server.
8. Resume Database Mirroring:
o Resume the mirroring session to synchronize the changes:
sql
Summary of Steps
Yes, deleting a datafile on the principal server will have significant consequences and will affect
the mirroring session. Here's what happens and why it's a critical issue:
1. Database Corruption:
o Deleting a datafile will lead to database corruption because the SQL Server
engine relies on all datafiles to maintain the integrity of the database. The
database will become inconsistent and potentially unusable.
2. Mirroring Session Disruption:
o The mirroring session will be disrupted because the mirror server will no longer
receive a consistent stream of transaction log records. The mirror server will
detect the inconsistency and the mirroring session will be suspended.
3. Error Messages:
o SQL Server will generate error messages indicating the missing datafile and the
inability to continue operations. You will see errors in the SQL Server error log
and the Windows Event Log.
Recovery Steps
If a datafile is accidentally deleted, here are the steps you should take to attempt recovery:
1. Immediate Action:
o Stop any ongoing operations and prevent any further transactions that might
compound the issue.
2. Restore from Backup:
o Restore the affected database from the most recent full backup, along with any
differential and transaction log backups.
o On the principal server:
sql
3. Reconfigure Mirroring:
o Once the database is restored and consistent, reconfigure the mirroring session.
Summary
Full Quorum —>This is when all 3 Witness,Principal and the Mirror can
communicate with each other.Since witness is present automatic failover
occurs.
Quorum —>This state exist if the Witness and either partner can
communicate with it.
Partner-to-Partner —>When only the Principal and Mirror can
communicate with each other.
Q: What are the requirements for setting up database mirroring?
Additional
To set up database mirroring in SQL Server, you need to meet several requirements and follow
specific steps. Here are the key requirements:
• Enterprise, Developer, or Standard Edition: Ensure that you are using one of these
editions as they support database mirroring.
3. Network Configuration
• Endpoints: Configure TCP endpoints on both the principal and mirror servers for
mirroring communication.
• Network Ports: Ensure that the network ports used by the endpoints are open and
accessible.
• Logins and Permissions: Ensure that the principal and mirror servers have appropriate
logins and permissions to connect to each other's endpoints.
• Certificates: If using certificates for authentication, ensure that they are properly
configured.
5. Database Preparation
• Full Backup and Restore: Take a full backup of the principal database and restore it on
the mirror server using the WITH NORECOVERY option.
• Transaction Log Backup: Take a transaction log backup of the principal database and
restore it on the mirror server using the WITH NORECOVERY option.
• Operating Modes: Choose the appropriate operating mode (High Safety with or without
automatic failover, or High Performance).
7. Disk Space and Resource Planning
• Sufficient Disk Space: Ensure that there is enough disk space on both the principal and
mirror servers to accommodate the database files and transaction logs.
• SQL Server Configuration: Ensure that SQL Server is properly configured for database
mirroring, including any necessary settings for memory, CPU, and I/O resources.
1. Create Endpoints:
o On the principal server:
sql
sql
sql
sql
sql
sql
sql
Summary
1. Principal and mirror are running SQL Server 2005 or newer (Standard or
Enterprise Edition).
2. Principal and mirror have enough space for the database.
3. For automatic failover, witness must be running.
4. Principal database must be in FULL recovery model.
5. Mirror database must be prepared prior to mirroring setup - one full backup
and one transaction log backup need to be taken on principal and restored
WITH NORECOVERY on mirror.
A to additional Q: yes, but principal has to be earlier then mirror, for
example 2005 -> 2008. SQL Server 2000 does not support database
mirroring at all.
Default port no is
5022 is default port number for mirroring in sql server
Q: Monitoring Mirroring?
Using Database Mirroring Monitor
On the principal:
· Log Bytes Sent/sec: Number of bytes of the log sent to the mirror per
second.
· Log Send Queue KB: Total kilobytes of the log that have not yet been
sent to the mirror server.
· Transaction Delay: Delay (in milliseconds) in waiting for commit
acknowledgement from the mirror. This counters reports the total delay for
all the transactions in process at that time. To determine the average delay
per transaction, divide this counter by the Transactions/sec counter. When
running asynchronous mirroring this counter will always be 0.
· Transactions/sec: The transaction throughput of the database.This
counter is in the Databases performance object.
· Log Bytes Flushed/sec: The rate at which log records are written to the
disk. This is the log generation rate of the application. It plays a very
important role in determining database mirroring performance.This counter
is in the Databases performance object.
· Disk Write Bytes/sec: The rate at which the disk is written to. This
counter is in the Logical Disk performance object and represents. Monitor
this counter for the data as well as the log disks.
On the mirror:
· Redo Bytes/sec: Number of bytes of the transaction log applied on the
mirror database per second.
· Redo Queue KB: Total kilobytes of hardened log that remain to be applied
to the mirror database to roll it forward.
· Disk Write Bytes/sec: The rate at which the disk is written to. This
counter is in the Logical Disk performance object and represents. Monitor
this counter for the data as well as the log disks on the mirror.
Q: Mirroring Requirements?
· SQL Server 2005 with SP1 or SQL Server 2008
· Database should be in FULL recovery model.
· Service Broker should be enabled on the database.
· Both the servers should have either Enterprise or standard editions.
· Both the servers should have same edition.
· Witness server can have any edition.
· Database name should be same
· Collation should be same
Q: Advantages of Mirroring?
• Hardware or software upgrades can be simplified.
• It increases the data protection(disaster recovery).
• Increases the database availability on syn mode.
• Cost of DB mirroring less compare to clustering.
• It is robust and efficient than log shipping and replication.
• It support the full text.
• Failover is fast compare to cluster.
• Mirror server can be used to host databases for other application
Q: Disadvantages
• Does not support filestream.
• potential loss of data in async mode(high performance).
• Mirror server is not available for read-only purpose.
• It works at the database level, not at the server level.
• Multiple database fail-over.
• Q: Enhancements in 2008
• Automatic page repair(823,824,829 page errors).
• compression of mirroring data stream.
• Log send buffers - efficient use
• Write-ahead event enhanced in 2008
• Page read-ahead during the undo phase
Q: What is the page error's in mirroring
Automatic page repair(823,824,829 page errors).
823 syclic redendancy failure
824 logical errors
825 restore pending
Data page read error in principal then entry in suspect pages table in msdb db for
the particler page. page is marked as restore pending making it in accessible to
application queries. mirror state is suspended till recover the page.
Can check suspect pages:
SELECT * FROM msdb..suspect_pages;
Q: What is the default of end points (port numbers) of principal, mirror and
witness servers? How to find the Port numbers?
The default port numbers of principal, mirror and Witness servers are 5022, 5023
and 5024.
To Find Port Number:- SELECT name, port FROM sys.tcp_endpoints.
Q: Trace flags are used to temporarily set specific server characteristics or
to switch off/on a particular behavior. 1400 Trace flag is used in mirroring.
To set trace flag for Database mirroring:- Configuration Manager > Right click on
server instance > Properties > Advanced tab > Startup parameters > -t1400 (add).
Q: How to monitoring Mirroring?
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 occurs 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
Q: What is Hardening?
As quickly as possible, the log buffer is written to the transaction log on disk, a
process called hardening.
Q: What is Log buffer?
A log buffer is a special location in memory (RAM). SQL Server stores the changes
in the database’s log buffer.
Q: How to Setup Fully Qualified Names for Database Mirroring?
I. FQDN Error
One or more of the server network addresses lacks a fully qualified domain name
(FQDN). Specify the FQDN for each server, and click Start Mirroring again.
The syntax for a fully-qualified TCP address is:
TCP://<computer_name>.<domain_segment>[.<domain_segment>]:<port>
Section 1.01
Section 1.02 II. RECTIFYING FULLY QUALIFYED NAMES
1) To View Endpoints:-SELECT * FROM sys.database_mirroring_endpoints;
2) Remove existing all Endpoints from Principal, Mirror and Witness servers :-
DROP ENDPOINT [ENDPOINT_NAME]
3) Adding "local" as the primary DNS suffix as follows:-
a) Right-click My Computer, and then click Properties. The System Properties dialog
box will appear.
b) Click the Computer Name tab.
c) Click Change. The Computer Name Changes dialog box will appear.
d) Click More. The DNS Suffix and NetBIOS Computer Name dialog box will appear.
e) Enter the appropriate DNS suffix for the domain.
f) Select the Change primary DNS suffix when domain membership changes check
box.
g) Click OK to save the changes, and then click OK to exit the Computer Name
Changes dialog box.
h) Click OK to close the System Properties dialog box, and then restart the
computer for the change to take effect.
4) Reconfigure the Database mirroring either GUI or T-SQL
Q: Database mirroring is disabled by default. Database mirroring is
currently provided for evaluation purposes only and is not to be used in
production environments. To enable database mirroring for evaluation
purposes, use trace flag 1400 during startup. For more information about
trace flags and startup options, see SQL Server Books Online. (Microsoft
SQL Server, Error: 1498)
Answer:
This is a common error & everyone is know to this error. Database mirroring is
officially supported from SQL Server 2005 SP1, hence in the RTM version database
mirroring is disabled by default. You can use TRACE 1400 to enable in RTM version
or else update your SQL Server with latest service pack.
Adding Trace Flag to Startup parameter
• Goto RUN --> Type sqlservermanager.msc
• Right click on SQL Server(instancename) service and click on properties
• Click on Advanced tab
• In the startup parameters enter this ;-T1400 and click on OK
• Restart SQLservices and then try configuring db mirroring
Or
• Update SQL Server to latest service pack.
Mirroring States:
SYNCHRONIZING: Indicates that the mirror database is trying to catch up with the principal
database. This is typically seen when you just start database mirroring or in high-performance
mode.
SUSPENDED: Indicates that the mirror database is not available. During this time the
principal is referred to as running exposed, as it is processing transactions but not sending
any transaction log records to the mirror.
PENDING_FAILOVER: Indicates the state that the principal goes through before
transitioning to the mirror role.
DISCONNECTED: Indicates that the partners are unable to communicate with each other.
High Automatic
FULL Synchronous Y Y
Availability or Manual
High
FULL Synchronous Y N Manual only
Protection
High
OFF Asynchronous N N/A Forced only
Performance
Mirror Monitoring
The following query returns the descriptions for basic database mirroring session information
about either the principal or the mirror.
SELECT
DB_NAME(database_id) AS 'DatabaseName'
, mirroring_role_desc
, mirroring_safety_level_desc
, mirroring_state_desc
, mirroring_safety_sequence
, mirroring_role_sequence
, mirroring_partner_instance
, mirroring_witness_name
, mirroring_witness_state_desc
, mirroring_failover_lsn
FROM sys.database_mirroring
WHERE mirroring_guid IS NOT NULL;
The following is an analogous query returns relevant descriptive session information about the
witness server that you run on the witness.
SELECT
Database_name
, safety_level_desc
, safety_sequence_number
, role_sequence_number
, is_suspended
, is_suspended_sequence_number
, principal_server_name
, mirror_server_name
FROM sys.database_mirroring_witnesses;