How to create database mirroring

What is database mirroring and  How to create database mirroring?

Database mirroring is software solution  for increasing database availability.It maintains two copies of single database,one as principal database and other as mirror database.So during disaster if primary database server fails then mirror database can be used by application to access the data.This reduces the down time caused during disasters. Mirrored database can not be accessed by application unless roles are switched (Transferring principal role to mirror server) but database snapshot can be created on mirrored database which can be used for read only queries (Load balancing). Refer SQL Server database snapshot steps to create snapshot   

Database  Mirroring can be  implemented  only on databases,that use the full recovery model. The simple and bulk-logged recovery models do not support database mirroring. 

Database mirroring is not applicable in system databases(master,msdb, tempdb, or model databases)

Database mirroring maintains two copies of a single database that must reside on different server instances of SQL Server Database Engine.

There are two mirroring operating modes.

1.High-safety mode:Commit changes at the principal and then transfer them to the mirror.It is asynchronous.

2.High-performance mode:Always commit changes at both the principal and mirror server.It is synchronous

All database mirroring sessions support only one principal server and one mirror server.

Steps to create mirroring:

I have two instances SQLPC\PRADEEPA  which will act as principal server and SQLPC\PK92 will act as mirrored server.

Choose a database in the principal instance which will act as Principal database,

I have created database named “Mirrordatabase” for which we are going to start mirroring.

Create a backup for the Mirrordatabase in the principal server.

clip_image001

Set the backup type in full recovery mode.Select back up destination as disk.Select add to add the destination folder.

clip_image001[4]

  In destination,add the destination folder with .bak extension and click ok. 

clip_image002

Click ok and complete the backup. 

clip_image001[6]

Now restore the backup of the database in mirrored server (destination server) with same name.

clip_image001[8]

  Type the name of the database and restore the database from device.

clip_image002[4]

Select the backup file and click ok.

clip_image001[16]

Now backup location is added.click ok and continue.

clip_image001[18]

Select the backup sets to restore.Then click Options from select a page.

clip_image001[20]

Select the recovery state as RESTORE WITH NORECOVERY.Also change the restore file name in restore as if you are creating mirror on same server for testing.Click ok.

clip_image001[22]

Database restore completed successfully.

clip_image001[24]

Configure mirroring in primary database by selecting properties.

clip_image001[26]

In Database properties window select mirroring and configure it.

clip_image001[28]

Here we dont have witness server.But we can include witness server instance also.Click Next.

clip_image001[30]

Specify principal server instance,listener port and endpoint name.Click Next.

clip_image001[32]

Connect mirror server instance.

clip_image001[34]

Connect it.

clip_image001[36]

Click Next and continue.

clip_image001[38]

Service accounts could be created in this window.

clip_image001[40]

Click Finish and complete the wizard.

clip_image001[42]

Close the window after configuring database mirroring.

clip_image001[44]

Start the mirroring by clicking start mirroring.

clip_image001[46]

We could select either High performance mode or High safety mode based upon our application need from below window.

clip_image001[48]

Mirroring is successfully created. 

clip_image001[50]

You could perform failover between primary database and mirror database by selecting Failover option in properties window.

clip_image001[52]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s