How to Setup Mirroring in SQL Server ?(Screen Shots)

Leave a comment (14) Go to comments

What is Mirroring in SQL Server ?

Database mirroring is an alternative high-availability solution to failover clustering in SQL Server. Database mirroring supports automatic failover, but does not require cluster-capable hardware, and can therefore provide a cost-effective alternative to failover clustering. In this Article, we will implement Mirroring with witness Server and will Automatic Failover too.

What is the Hardware and software requirement for implementing Mirroring in SQL Server ?

There is no any such hardware and software requirement for implementing. Even SQL Server Standard Edition supports Mirroring. For More Details about feature supported by various editions, please check my previous post, "Does SQL Server Standard Edition Supports Mirroring?" To test the Automatic failover, you need three SQL Server Instances.

In case there is a firewall in between Principal, Mirror and Witness Server, please ensure there endpoint ports are Opened in firewall.

How to implement Database Mirroring in SQL Server 2008 R2?

Implementing SQL Server Mirroring is quite simple in SQL Server 2008 R2. For better understanding, Lets take an real business requirement and deploy mirroring with WITNESS Server (Automatic Failover)

I have already posted an Video Post, where a step by step implementation of mirroring is available, but you need to have silver light installed in your system to watch this video and a good bandwidth.

In this Article, I am going to implement a Mirroring using three SQL Server Instances, where

  1. Principal Server
  2. Mirror Server
  3. Witness Server

Principal Server Details

  • SQL Server Instance Name : <SERVER_NAME>\SQL1
  • Version : SQL Server 2008 R2
  • Edition : Evaluation Copy
  • Database Name : Test_SQLServer_Mirroring

Mirror Server Details

  • SQL Server Instance Name : <SERVER_NAME>\SQL2
  • Version : SQL Server 2008 R2
  • Edition : Evaluation Copy
  • Database Name : Test_SQLServer_Mirroring

Witness Server Details

  • SQL Server Instance Name : <SERVER_NAME>\SQL3
  • Version : SQL Server 2008 R2
  • Edition : Evaluation Copy

*Note : In this example, all these instances are named instances hosted on a single operative case. In case you are implementing in your production environment, All these three roles should be on different machines.

We are going to perform following Steps to setup Mirroring and automatic Failover Testing

  1. Backup Primary Database (Principal Server)
  2. Using latest backup files, Restore database on Mirror Server with NORECOVERY Option
  3. Set up Mirroring using Wizard where we will define
    1. Identify of Principle Server, Mirror Server and Witness Server
    2. Create End Points for Principle Server, Mirror Server and Witness Server
    3. Configure Security
  4. Start Mirroring
  5. Test Manual Failover
  6. Test Automatic Failover

STEP 1 -  Backup Primary Database (Principle Server)

On Principal Server Perform a full backup and copy this backup file to mirror server for restore. Backup is quite simple, which can be taken using the following Script on Principal Server (.\SQL1)

-- This will Backup Database named Test_SQLServer_Mirroring to C:\temp\Mirroring\TEST.bak file 
BACKUP DATABASE [Test_SQLServer_Mirroring] TO  DISK = N'C:\temp\Mirroring\TEST.bak' WITH NOFORMAT, NOINIT,  NAME = N'Test_SQLServer_Mirroring-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

STEP 2 -  Restore Database on Secondary Database (Mirror Server)

On Mirror Server, Restore the database with same name with NORECOVERY option on Server .\SQL2 Restore is quite simple, which can be taken using the following Script or by SSMS

-- Restore Database name Test_SQLServer_Mirroring] on Mirror Server (.\SQL2) with NORECOVERY option
RESTORE DATABASE [Test_SQLServer_Mirroring] FROM  DISK = N'C:\temp\Mirroring\TEST.bak' WITH  FILE = 1,  MOVE N'Test_SQLServer_Mirroring' TO N'C:\temp\Mirroring\SQL2_Test_SQLServer_Mirroring.mdf',  MOVE N'Test_SQLServer_Mirroring_log' TO N'C:\temp\Mirroring\SQL2_Test_SQLServer_Mirroring_1.ldf',  NORECOVERY,  NOUNLOAD,  STATS = 10
GO

STEP 3 - Set up Mirroring using Wizard where we will Identify of Principle Server, Mirror Server and Witness Server, Create End Points for Principle Server, Mirror Server and Witness Server and will also configure Security

Open SSMS and connect to Principal Server >>> Database, which you wanted to enabled for mirroring >>> right click >>> and Select Properties

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

which will open up a Database Properties Box like this and Click on Mirroring

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Once you are on Mirroring Properties page, select "Configure Security…" button, which will open a Configure Database Mirroring Security Wizard

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Next screen, will ask you, do you want to include Witness Server or not ? Witness Server is useful to initiate Automatic failover. As per our requirement, we will be opting to include Witness Server, so we will Select YES

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring



Next screen will ask you, where you wanted to save the configuration, In case we opted for Automatic Failover / Witness Server, configuration must be saved at Witness Server. In case, we do not want to include Witness Server and would like to to do Manual failover, then we can have option for saving Configuration either on Principal Server or on Mirror Server.

As per our requirement (Automatic Failover), we will opt for Witness Server Instance.

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Next Screen where we need to specify information about the SQL instance where the database was originally located. In out example this is .\SQL1

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Here we have option to specify the TCP / IP port on which endpoint will be listening to requests. In case there is a firewall in between Principal and Mirror Server, please ensure there these ports are Open.

In our example, all these three instances are hosted on a single physical box that the reason we will opt for different port for Mirror and Witness Server End point.


Adding to this we have an option to encrypt data, which travel between principal, mirror and witness server. In case we opt for this, we assume that you are already have certificates, otherwise, this will work without Certificates too.

So In Select Principal Option, we specified .\SQL1 as Server name and used Windows Authentication to connect to principal server, which has sysadmin privileges. We also checked the Encrypt Data option and 5022 is the Port number which we used for Principal endpoint.

Next Screen where we need to specify information about the SQL instance where the mirror copy of the database will be located, in our example this is ./SQL2

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

So In Select Mirror Option, we specified .\SQL2 as Server name and used Windows Authentication to connect to principal server, which has sysadmin privileges. We also checked the Encrypt Data option and 5023 is the Port number which we used for Mirror endpoint.

Next Screen where we need to specify information about the SQL instance that monitors the status of the principal and mirror server instances

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

So In Select Witness Server Option, we specified .\SQL3 as Server name and used Windows Authentication to connect to principal server, which has sysadmin privileges. We also checked the Encrypt Data option and 5024 is the Port number which we used for Mirror endpoint.

Next Screen will actually create these endpoint in the respective Server

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

This is Work in progress status, Once this is being configured and running, you will get a confirmation status as shown below.

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

STEP 4 -  Start Mirroring

Once this is Done, you are ready to start the mirroring, the wizard, will itself ask you to do that, as shown in the following screen shot

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Once, you click on YES, this will implement the mirroring and will take some time to revert back to old screen, Please wait, as this wait is depends on changes which has been performed on Principal Server after full backup. This could take 30 minutes too.

Once this check all configuration and synchronized data, you will get the YES button enabled as shown below.

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Once, this is Done, you mirroring setup is completed. We can verify that by checking database status connecting to Principal and Mirror Instance via SSMS. We will get a status like below

Database Status at Principal Server

Database status would be Principal and Synchronized, is (Role,Status) as shown below in the screen shot.

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

Database Status at Mirror Server

Database status would be Mirror, Synchronized and restoring, is (Role,Status) as shown below in the screen shot.

How to Setup Mirroring in SQL Server ?(Screen Shots) What is Mirroring in SQL Server sql server database mirroring wizard Setup Mirroring in SQL Server screenshots Setup Mirroring in SQL Server screenshot How to implement Database Mirroring in SQL Server 2008 R2 Hardware and software requirement for implementing SQL Server Mirroring Hardware and software requirement for implementing Mirroring in SQL Server database status Principal and Synchronized database status Mirror Synchronized and restoring

This is quite lengthy post, so Post Check Implementation and Failover Testing (Step 5 and Step 6) I will be posting in next article.

If you liked this post then,

Subscribe to this Blog via Email:

Click here to Subscribe to FREE email updates from "DBATAG ", so that you do not miss out anything on SQL Server !!!

Tags : What is Mirroring in SQL Server,Hardware and software requirement for implementing SQL Server Mirroring ,Hardware and software requirement for implementing Mirroring in SQL Server ,How to implement Database Mirroring in SQL Server 2008 R2, How to implement Database Mirroring in SQL Server 2008 R2,Setup Mirroring  in SQL Server  screenshot,Setup Mirroring  in SQL Server  screenshots, sql server database mirroring wizard

EOF - How to Setup Mirroring in SQL Server ?(Screen Shots), SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000
Leave a comment

14 Comments.

  1. hi, how can i solve this error?

    This mirroring configuration is not supported. Because the principal server instance, TSPI-GPSVR01, is not Standard Edition, the mirror server instance cannot be Standard Edition.

    Thanks!

  2. Venkateshwar Reddy suravaram

    Nice tutorial it’s helped me to configure mirroring in SQL Server 2008 .
    Thanks !!!

  3. Hi, will you be posting steps 5 and 6 this tutorial is very good.

  4. Hello,

    I am getting Error 1418 after clicking Start mirroring button. I have created three instancess in one singler server (2012 version), can you please suggest me on the error to resolve. I have configure in my office laptop and all TCP ports are enabled. please reply / mail me suggestions.

    Thanks

  5. Hi,
    I have did the things what you have mentioned in your post 1 it helped me a lot.I need to test mirroring can you provide the post 2 url pls

  6. I have done everything what has been written in this tutorial but i cannot connect to mirror server. I obtain 1418 error. I have not the same domain for all machines. Do you have any idea why it doesn’t working?
    I thought that this was problem with endpoint on mirror server but everything looks good. Have you configured something else?

  7. but how make instacne in same sql server?

  8. sir
    but how to make instance ? in same sql server? is it possible that one server is 2008 and other r2 can mirroring can be possible

    SERVER_NAME>\SQL1
    SERVER_NAME>\SQL2
    SERVER_NAME>\SQL3

    • YEs, you can have multiple instances in single windows machine. for this you need to run the SQL Server setup every time and during the installtion, select named Instances and proceed…

  9. What does this mean?
    There is no any such hardware and software requirement for implementing

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Trackbacks and Pingbacks: