SlideShare a Scribd company logo
1 of 20
SQL Server 2012 Mirroring

Mahesh Dahal

1/7/13

Mirroring MSSQL Server 2012
Mirroring a SQL Server Database on SQL Server 2012 R2
Database mirroring is a solution for increasing the availability of a SQL Server database. Mirroring is
implemented on a per-database basis and works only with databases that use the full recovery model.
However, this feature will be removed in a future version of Microsoft SQL Server. Avoid using this
feature in new development work, and plan to modify applications that currently use this feature. Use
AlwaysOn Availability Groups instead. I will try to Blog the same in future Blogs.
Database mirroring maintains two copies of a single database that must reside on different server
instances of SQL Server Database Engine. Typically, these server instances reside on computers in
different locations. Starting database mirroring on a database, initiates a relationship, known as a
database mirroring session, between these server instances.

One server instance serves the database to clients (the principal server). The other instance acts as a hot
or warm standby server (the mirror server), depending on the configuration and state of the mirroring
session. When a database mirroring session is synchronized, database mirroring provides a hot standby
server that supports rapid failover without a loss of data from committed transactions. When the
session is not synchronized, the mirror server is typically available as a warm standby server (with
possible data loss).
The principal and mirror servers communicate and cooperate as partners in a database mirroring
session. The two partners perform complementary roles in the session: the principal role and the mirror
role. At any given time, one partner performs the principal role, and the other partner performs the
mirror role. Each partner is described as owning its current role. The partner that owns the principal role
is known as the principal server, and its copy of the database is the current principal database. The
partner that owns the mirror role is known as the mirror server, and its copy of the database is the
current mirror database. When database mirroring is deployed in a production environment, the
principal database is the production database.
Database mirroring involves redoing every insert, update, and delete operation that occurs on the
principal database onto the mirror database as quickly as possible. Redoing is accomplished by sending a
stream of active transaction log records to the mirror server, which applies log records to the mirror
database, in sequence, as quickly as possible. Unlike replication, which works at the logical level,
database mirroring works at the level of the physical log record. Beginning in SQL Server 2008, the
principal server compresses the stream of transaction log records before sending it to the mirror server.
This log compression occurs in all mirroring sessions.

Benefits of Mirroring
Database mirroring is a simple strategy that offers the following benefits:

Increases availability of a database.
In the event of a disaster, in high-safety mode with automatic failover, failover quickly brings the
standby copy of the database online (without data loss). In the other operating modes, the database
administrator has the alternative of forcing service (with possible data loss) to the standby copy of the
database. For more information, see Role Switching, later in this topic.
Increases data protection.
Database mirroring provides complete or almost complete redundancy of the data, depending on
whether the operating mode is high-safety or high-performance. For more information, see Operating
Modes, later in this topic.
A database mirroring partner running on SQL Server 2008 Enterprise or later versions automatically tries
to resolve certain types of errors that prevent reading a data page. The partner that is unable to read a
page requests a fresh copy from the other partner. If this request succeeds, the unreadable page is
replaced by the copy, which usually resolves the error.

Improves the availability of the production database during upgrades.
To minimize downtime for a mirrored database, you can sequentially upgrade the instances of SQL
Server that are hosting the failover partners. This will incur the downtime of only a single failover. This
form of upgrade is known as a rolling upgrade. For more information, see Install a Service Pack on a
System with Minimal Downtime for Mirrored Databases.

Prerequisites:
1. For a mirroring session to be established, the partners and the witness, if any, must be running
on the same version of SQL Server.
2. The two partners, that is the principal server and mirror server, must be running the same
edition of SQL Server. The witness, if any, can run on any edition of SQL Server that supports
database mirroring.
3. The database must use the full recovery model. The simple and bulk-logged recovery models do
not support database mirroring. Therefore, bulk operations are always fully logged for a
mirrored database. For information about recovery models, see Recovery Models (SQL Server).
4. Verify that the mirror server has sufficient disk space for the mirror database.
5. When you are creating the mirror database on the mirror server, make sure that you restore the
backup of the principal database specifying the same database name WITH NORECOVERY. Also,
all log backups that were created after that backup was taken must also be applied, again WITH
NORECOVERY.
6. It is recommended that all the primary, secondary and Witness server be on the AD.
Step 1. Confirm the Recovery Model
Mirroring only works in Full Recovery Model. So it is important that you confirm or change the recovery
model to FULL.
1.
2.
3.
4.

Right click on the database
Go to Properties
GO to Options
In the Recovery Model Window Change the option to FULL

Step 2. Prepare the Backup
5. Take Full Backup of the Primary DB

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Step 3. Restore the Backup
6. Take a Transaction log backup of the Primary DB
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

7. Restore the DB in secondary server with same name and No Recovery Model
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

8. Restore the Transactional Log Backup in the Secondary DB and use No Recovery Model
9. Go to the Primary Server right Click on Database, Go to properties.
Step 4. Configure the Mirroring
It is advised to connect to all the instances and server from a single machine. Here I am connecting to
two server and three instances. Server1, Server2 and Server1witness

Mirroring on SQL Server 2012 Server 2012
Mirroring on SQL
Mahesh Dahal
Mahesh Dahal
maheshdahal@live.com
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

10. GO to primary Server and Right Click on the Database and go to properties
11. Then go to Mirroring
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Click on Configure Security and Follow the Steps

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Click on Next
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Click on Yes. You can also Choose No, If you like to Setup the Mirroring without the Witness.

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Give your Domain Administrators User account for all three Instances.
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Click Start Mirroring
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com
Mirroring on SQL Server 2012
Mahesh Dahal
maheshdahal@live.com

Your Database has been mirrored. You can can see the status next to the database. You can also
go to the Mirroring page and manually failover to confirm the Mrroring.

Mahesh Dahal
Microsoft Innovation Center, Nepal
maheshdahal@live.com

More Related Content

What's hot

Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
Simon Huang
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architecture
Amit Bhalla
 

What's hot (20)

Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
10 Problems with your RMAN backup script - whitepaper
10 Problems with your RMAN backup script - whitepaper10 Problems with your RMAN backup script - whitepaper
10 Problems with your RMAN backup script - whitepaper
 
Physical architecture of sql server
Physical architecture of sql serverPhysical architecture of sql server
Physical architecture of sql server
 
10 ways to improve your rman script
10 ways to improve your rman script10 ways to improve your rman script
10 ways to improve your rman script
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Less01 architecture
Less01 architectureLess01 architecture
Less01 architecture
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
SQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore PlanSQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore Plan
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Data Guard Architecture & Setup
Data Guard Architecture & SetupData Guard Architecture & Setup
Data Guard Architecture & Setup
 
Standard Edition High Availability (SEHA) - The Why, What & How
Standard Edition High Availability (SEHA) - The Why, What & HowStandard Edition High Availability (SEHA) - The Why, What & How
Standard Edition High Availability (SEHA) - The Why, What & How
 
10 Problems with your RMAN backup script
10 Problems with your RMAN backup script10 Problems with your RMAN backup script
10 Problems with your RMAN backup script
 
Oracle GoldenGate Performance Tuning
Oracle GoldenGate Performance TuningOracle GoldenGate Performance Tuning
Oracle GoldenGate Performance Tuning
 
Introduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard BrokerIntroduction to Oracle Data Guard Broker
Introduction to Oracle Data Guard Broker
 
Sql server logshipping
Sql server logshippingSql server logshipping
Sql server logshipping
 
Oracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret InternalsOracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret Internals
 
Why oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cWhy oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19c
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
AlwaysON Basics
AlwaysON BasicsAlwaysON Basics
AlwaysON Basics
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
 

Similar to Mirroring in SQL Server 2012 R2

Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
webhostingguy
 
Database Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David IzahkDatabase Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David Izahk
sqlserver.co.il
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql Server
Rishikesh Tiwari
 
Using MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlexUsing MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlex
webhostingguy
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
liufabin 66688
 
Sql 2012 always on
Sql 2012 always onSql 2012 always on
Sql 2012 always on
dilip nayak
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBA
Concentrated Technology
 
Sql server’s high availability technologies
Sql server’s high availability technologiesSql server’s high availability technologies
Sql server’s high availability technologies
venkatchs
 
Be05 introduction to sql azure
Be05   introduction to sql azureBe05   introduction to sql azure
Be05 introduction to sql azure
DotNetCampus
 
Log shippingbestpractices
Log shippingbestpracticesLog shippingbestpractices
Log shippingbestpractices
Antilamps
 
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docxDBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
seifusisay06
 
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
webhostingguy
 
Sql server mirroring
Sql server mirroringSql server mirroring
Sql server mirroring
sateesh7114
 

Similar to Mirroring in SQL Server 2012 R2 (20)

Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
 
Database Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David IzahkDatabase Mirror for the exceptional DBA – David Izahk
Database Mirror for the exceptional DBA – David Izahk
 
High availability solution database mirroring
High availability solution database mirroringHigh availability solution database mirroring
High availability solution database mirroring
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql Server
 
Using MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlexUsing MS-SQL Server with Visual DataFlex
Using MS-SQL Server with Visual DataFlex
 
SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)SQL Server High Availability Solutions (Pros & Cons)
SQL Server High Availability Solutions (Pros & Cons)
 
High availability solutions bakostech
High availability solutions bakostechHigh availability solutions bakostech
High availability solutions bakostech
 
Database operations
Database operationsDatabase operations
Database operations
 
Sql2008 (1)
Sql2008 (1)Sql2008 (1)
Sql2008 (1)
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
 
Sql 2012 always on
Sql 2012 always onSql 2012 always on
Sql 2012 always on
 
Sql Sever Presentation.pptx
Sql Sever Presentation.pptxSql Sever Presentation.pptx
Sql Sever Presentation.pptx
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBA
 
Sql server’s high availability technologies
Sql server’s high availability technologiesSql server’s high availability technologies
Sql server’s high availability technologies
 
Configuring sql server - SQL Saturday, Athens Oct 2014
Configuring sql server - SQL Saturday, Athens Oct 2014Configuring sql server - SQL Saturday, Athens Oct 2014
Configuring sql server - SQL Saturday, Athens Oct 2014
 
Be05 introduction to sql azure
Be05   introduction to sql azureBe05   introduction to sql azure
Be05 introduction to sql azure
 
Log shippingbestpractices
Log shippingbestpracticesLog shippingbestpractices
Log shippingbestpractices
 
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docxDBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
 
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
VirtualCenter Database Maintenance: VirtualCenter 2.0.x and ...
 
Sql server mirroring
Sql server mirroringSql server mirroring
Sql server mirroring
 

More from Mahesh Dahal

More from Mahesh Dahal (7)

Backup your tables to SQL Azure using SQL Stretch
Backup your tables to SQL Azure using SQL StretchBackup your tables to SQL Azure using SQL Stretch
Backup your tables to SQL Azure using SQL Stretch
 
Privacy Policy for Quake Nepal
Privacy Policy for Quake NepalPrivacy Policy for Quake Nepal
Privacy Policy for Quake Nepal
 
Ebook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solutionEbook 70 533 implementing microsoft infrastructure solution
Ebook 70 533 implementing microsoft infrastructure solution
 
70 533 implementing microsoft azure infrastructure solutions Preparation Guide
70 533 implementing microsoft azure infrastructure solutions Preparation Guide70 533 implementing microsoft azure infrastructure solutions Preparation Guide
70 533 implementing microsoft azure infrastructure solutions Preparation Guide
 
RDP Connection to Linux Azure Virtual Machine
RDP Connection to Linux Azure Virtual Machine RDP Connection to Linux Azure Virtual Machine
RDP Connection to Linux Azure Virtual Machine
 
Creating and hosting a Azure Website with a custom domain
Creating and hosting a Azure Website with a custom domainCreating and hosting a Azure Website with a custom domain
Creating and hosting a Azure Website with a custom domain
 
Deploying a MVC3 WebService in Windows Azure
Deploying a MVC3 WebService in Windows AzureDeploying a MVC3 WebService in Windows Azure
Deploying a MVC3 WebService in Windows Azure
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Mirroring in SQL Server 2012 R2

  • 1. SQL Server 2012 Mirroring Mahesh Dahal 1/7/13 Mirroring MSSQL Server 2012
  • 2. Mirroring a SQL Server Database on SQL Server 2012 R2 Database mirroring is a solution for increasing the availability of a SQL Server database. Mirroring is implemented on a per-database basis and works only with databases that use the full recovery model. However, this feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use AlwaysOn Availability Groups instead. I will try to Blog the same in future Blogs. Database mirroring maintains two copies of a single database that must reside on different server instances of SQL Server Database Engine. Typically, these server instances reside on computers in different locations. Starting database mirroring on a database, initiates a relationship, known as a database mirroring session, between these server instances. One server instance serves the database to clients (the principal server). The other instance acts as a hot or warm standby server (the mirror server), depending on the configuration and state of the mirroring session. When a database mirroring session is synchronized, database mirroring provides a hot standby server that supports rapid failover without a loss of data from committed transactions. When the session is not synchronized, the mirror server is typically available as a warm standby server (with possible data loss). The principal and mirror servers communicate and cooperate as partners in a database mirroring session. The two partners perform complementary roles in the session: the principal role and the mirror role. At any given time, one partner performs the principal role, and the other partner performs the mirror role. Each partner is described as owning its current role. The partner that owns the principal role is known as the principal server, and its copy of the database is the current principal database. The partner that owns the mirror role is known as the mirror server, and its copy of the database is the current mirror database. When database mirroring is deployed in a production environment, the principal database is the production database. Database mirroring involves redoing every insert, update, and delete operation that occurs on the principal database onto the mirror database as quickly as possible. Redoing is accomplished by sending a stream of active transaction log records to the mirror server, which applies log records to the mirror database, in sequence, as quickly as possible. Unlike replication, which works at the logical level, database mirroring works at the level of the physical log record. Beginning in SQL Server 2008, the principal server compresses the stream of transaction log records before sending it to the mirror server. This log compression occurs in all mirroring sessions. Benefits of Mirroring Database mirroring is a simple strategy that offers the following benefits: Increases availability of a database. In the event of a disaster, in high-safety mode with automatic failover, failover quickly brings the standby copy of the database online (without data loss). In the other operating modes, the database administrator has the alternative of forcing service (with possible data loss) to the standby copy of the database. For more information, see Role Switching, later in this topic.
  • 3. Increases data protection. Database mirroring provides complete or almost complete redundancy of the data, depending on whether the operating mode is high-safety or high-performance. For more information, see Operating Modes, later in this topic. A database mirroring partner running on SQL Server 2008 Enterprise or later versions automatically tries to resolve certain types of errors that prevent reading a data page. The partner that is unable to read a page requests a fresh copy from the other partner. If this request succeeds, the unreadable page is replaced by the copy, which usually resolves the error. Improves the availability of the production database during upgrades. To minimize downtime for a mirrored database, you can sequentially upgrade the instances of SQL Server that are hosting the failover partners. This will incur the downtime of only a single failover. This form of upgrade is known as a rolling upgrade. For more information, see Install a Service Pack on a System with Minimal Downtime for Mirrored Databases. Prerequisites: 1. For a mirroring session to be established, the partners and the witness, if any, must be running on the same version of SQL Server. 2. The two partners, that is the principal server and mirror server, must be running the same edition of SQL Server. The witness, if any, can run on any edition of SQL Server that supports database mirroring. 3. The database must use the full recovery model. The simple and bulk-logged recovery models do not support database mirroring. Therefore, bulk operations are always fully logged for a mirrored database. For information about recovery models, see Recovery Models (SQL Server). 4. Verify that the mirror server has sufficient disk space for the mirror database. 5. When you are creating the mirror database on the mirror server, make sure that you restore the backup of the principal database specifying the same database name WITH NORECOVERY. Also, all log backups that were created after that backup was taken must also be applied, again WITH NORECOVERY. 6. It is recommended that all the primary, secondary and Witness server be on the AD.
  • 4. Step 1. Confirm the Recovery Model Mirroring only works in Full Recovery Model. So it is important that you confirm or change the recovery model to FULL. 1. 2. 3. 4. Right click on the database Go to Properties GO to Options In the Recovery Model Window Change the option to FULL Step 2. Prepare the Backup 5. Take Full Backup of the Primary DB Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Step 3. Restore the Backup 6. Take a Transaction log backup of the Primary DB
  • 5. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com 7. Restore the DB in secondary server with same name and No Recovery Model
  • 6. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 7. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 8. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com 8. Restore the Transactional Log Backup in the Secondary DB and use No Recovery Model 9. Go to the Primary Server right Click on Database, Go to properties.
  • 9. Step 4. Configure the Mirroring It is advised to connect to all the instances and server from a single machine. Here I am connecting to two server and three instances. Server1, Server2 and Server1witness Mirroring on SQL Server 2012 Server 2012 Mirroring on SQL Mahesh Dahal Mahesh Dahal maheshdahal@live.com maheshdahal@live.com
  • 10. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 11. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 12. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com 10. GO to primary Server and Right Click on the Database and go to properties 11. Then go to Mirroring
  • 13. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 14. Click on Configure Security and Follow the Steps Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Click on Next
  • 15. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Click on Yes. You can also Choose No, If you like to Setup the Mirroring without the Witness. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 16. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 17. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Give your Domain Administrators User account for all three Instances.
  • 18. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 19. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Click Start Mirroring Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com
  • 20. Mirroring on SQL Server 2012 Mahesh Dahal maheshdahal@live.com Your Database has been mirrored. You can can see the status next to the database. You can also go to the Mirroring page and manually failover to confirm the Mrroring. Mahesh Dahal Microsoft Innovation Center, Nepal maheshdahal@live.com