Topics In This Module.
- Working with Database Mirroring
- Terminology
- Pre-requisites to implement Mirroring
- Pre check mirroring ports ENABLED or DISABLED
- Architecture
- Operating Modes
- Differences between Modes
- Port numbers involved in Mirroring
- Requirements for Mirroring
- Configuring Mirroring
- Mirroring failover
- Issues on Mirroring
Mirroring
What is Mirroring?
Mirroring is a technique where each and all individual transactions from buffer are
transferred from one database (Principal) to another database (Mirror), Through end
points.
In this technique whenever a DML is executed, according to WAL concepts the
transaction need to written to buffer as well as log file, from the primary server buffer the
transactions are transferred to other server buffer and log file only then the transaction
shows successful execution.
This says that the communication is happing through end points, hence we call it as an
End points Communication, default port for mirroring is 5022.
- TCP
- Https
Check List:
- Three Servers
- Primary Server/Instance
- Mirror Server/Instance.
- Witness Server/Instance (Optional for automatic failover)
- Recovery Model: Should be Full
- Recovery State: Should be No-Recovery i.e., Restoring mode.
- Sysadmin privileges for user who is configuring mirroring.
- Database Name, Instance Versions, compatibility, collation of database/instance must be same.
- SQL Server Instance Editions
- Asynchronous mirroring: Developer and Enterprise editions.
- Synchronous mirroring: Developer, Enterprise, standard.
- Needed to restore a full and tlog backup taken from primary in no-recovery mode i.e., in restoring mode and only then we can configure mirroring.
- SQL Server version greater than or equal to SQL 2005 RTM:
Note: It’s not recommended to configure mirroring on SQL Server 2005 RTM version, if needed to configure enable trace flag on all three instances, trace flag number: 1400, and then configure SQL Server 2005 RTM version, but still there is no SQL server monitor tool on SQL 2005 RTM version, so it’s recommended to use SQL server 2005 SP1 or greater to configure mirroring.
Mirroring Monitoring
- Using Mirroring Monitor tool.
- Right click on database -> reroute to tasks -> click on “Launch Database Mirroring Monitor”
- Using Stored procedures in MSDB database.
Points about Mirroring:
- Mirroring is introduced in SQL server 2005.
- This is a database level HA/DR technique and requires at least 2 servers/database to configure.
- In this configuration one can maintain only two copies of data i.e., an original data and a copy data, this means the configuration can be done only between two databases.
- We can also use 2 or 3 servers based on requirement the server used in this configuration are called as below with its properties:
- Principal Server – Maintains original data
- Mirror Server – Maintains a copy of original data
- Witness Server – Monitors the mirroring status between the mirroring pair.
- If 2 servers are used in the configuration then it is a DR – Disaster Recovery.
- If 3 servers are used in the configuration then it is a HA – High Availability.
- This technique works only when database is in FULL recovery model, and in restoring mode in mirror server and also the database name should be same in both principal and mirror servers.
Mirror Pair: Principle and Mirror server operating together that hence both are called
mirror pair.
Operating together: Transactions happening on principle are reflected to mirror using
endpoints this means operating together.
Quorum: The Relationship between principal database, mirror database and witness database are called quorum.
Endpoints: Mirroring is an endpoint-based communication; log records are copied from principal buffer to mirror buffer
Logical service point/name associated with a port number is an end point, we can use two types of end points they are TCP end points, HTTP end points
5022 is a default endpoint port for mirroring; this comes with Build-in Security encrypted data will be copied automatically through this end points.
- How to create or alter end points?
- How to use end points?
- How to check end points are working or not?
- How to check port number, end points, status of already configured mirroring?
Full Qualified Domain name:
Important Points:
Transactional safety types are Full or Half. There are three types of failovers in mirroring they are:
- Automatic Failover
- Manual Failover
- Forcible Failover
Mirroring can be configured in two types/modes they are:
Synchronous Mirroring Asynchronous Mirroring
Synchronous Mirroring
Low Performance but high reliability
Asynchronous Mirroring:
High Performance but No data reliability
- This is a DR technique, 2 servers are used to configure, only forcible failover.
- Data will not be in sync, High Performance Mode.
High Availability Mode High Protection Mode High Performance Mode
High Availability Mode
High Protection Mode
High Performance Mode
Synchronized state: When both the databases are in sync then the database will be in this state - Synchronizing state: When data is syncing between both the databases, the databases will be in this state
- Suspended state: When mirroring is paused or data/transactions are not coming from principal then we see databases in this state.
- Pending failover state: When the databases are failover from principal to mirror but still the users are connected to principal then database goes into this state.
- Disconnected state: communication is not happening or lost between principal and Mirror servers.
Creating Snapshot of a database:
Snapshot database should have same number of data files that the source database has and also should have size on disk Database should not be corrupted and should be online. Source database (the database on which snap is created) cannot be deleted when snap is present on that database We cannot perform database backup when snap is present. Snap database is read only database. We can read the mirror database only when snapshot database is present. Database shot is present only in Enterprise and developer editions
Remember Points (Note):
➔ Individual transactions are copied form principal database to mirror database using network end points. ➔ Once the transaction copied it is written on mirror database and once it is done in mirror database it acknowledges the transaction write. ➔ Only then the transaction is committed on principal. Which is a time taking process when compared to other techniques. ➔ Only two copies of data can be maintained in mirroring, main copy and mirror copy. ➔ Heartbeat is the timeout time between the databases principal and mirror
When principal database/servers fail?
High Availability mode: Failover happens automatically High Protection mode: We need to perform manual failover, from mirror server High Performance mode: We need to perform forcible failover with data loss, form mirror server
When Mirror database/servers fail?
High Availability mode: Operations/transactions cannot be performed High Protection mode: Operations/transactions cannot be performed High Performance mode: No effect, sync will be suspend/disconnect state As operations are not performed break the mirroring configuration after sync, for quick resolutions
When witness database/servers fail?
High Availability mode: Automatic failover does not happen, if any issues High Protection mode: No Witness server here High Performance mode: No Witness server here
When witness and mirror database/servers fail?
High Availability mode: Operations/transactions cannot be performed. High Protection mode: Operations/transactions cannot be performed. High Performance mode: No effect, sync will be suspend/disconnect state
As operations are not performed break the mirroring configuration after sync, for quick resolutions
When witness and principal database/servers fail?
High Availability mode: Operations/transactions cannot be performed, to resolve this perform manual failover and break mirroring. High Protection mode: Operations/transactions cannot be performed, to resolve this perform manual failover and break mirroring. High Performance mode: Operations/transactions cannot be performed, to resolve this forcible failover with data loss.
When Principal and mirror database/servers fail?
High Availability mode: Operations/transactions cannot be performed High Protection mode: Operations/transactions cannot be performed High Performance mode: Operations/transactions cannot be performed
Mirroring commands:
=>Run below on principal databases
#To disconnect the mirroring use the below
alter database <Database Name>set partner safety off
#To change the database mode from Async to sync
alter database <Database Name>set partner safety full
#To change the database mode from sync to Async
<Database Name> set partner off alter database
#To pause the mirroring between database use below
<Database Name> set partner suspend alter database
use below #To Resume the mirroring between databases,
alter database <Database Name> set partner resume
#To failover the databases from principal to mirror use below
<Database Name> set partner failover alter database
=>Run below on Mirror databases
#To pause the mirroring between database use below
<Database Name> set partner suspend alter database
#To Resume the mirroring between databases, use below
lter database <Database Name> set partner resume a
#To failover the databases from principal to mirror use below – manual failover
alter database <Database Name> set partner failover #only when principal is down
#To failover the databases from principal to mirror use below – forcible failover
<Database Name> set partner FORCE_SERVICE_ALLOW_DATA_LOSS alter database
#To switch the mirroring off use below
<Database Name> set witness off alter database
#When the database is in restoring to bring it online use below
<Database Name> with recovery restore database
Comments
Post a Comment