Read + Write + Report
Home | Start a blog | About Orble | FAQ | Blogs | Writers | My Orble | Login

Database Mirroring Automating Failover for Multiple SQL Server Databases With No Witness

March 6th 2009 04:59
Database Mirroring Automating Failover for Multiple SQL Server Databases With No Witness



----------------------------- ----------------------------- -------------
Problem
In a previous tip on Database Mirroring Automating Failover for Multiple SQL Server Databases, you've seen how you can failover all of the databases in a mirroring session if one database fails over. However, what happens if you don't have a witness server and your principal server goes, how do you make your mirror server the principal and bring all your databases online?

Solution
This solution extends the tip by reading the sys.databases and the sys.database_mirroring catalog views from the mirrored server and automatically (or manually, depending on your requirements) failover databases that are in a database mirroring pair. One case would be when you have a database mirroring pair in a high-protection operating mode without a witness requiring you to do a manual failover, whether planned or unplanned. You can use this script in the Failover Databases job as described in this tip or simply run it on the mirror database in case you decide to do a manual failover instead of an automated one.


This script uses the FORCE_SERVICE_ALLOW_DATA_LOSS option as in a real disaster, the primary database will be inaccessible. The process will recover the mirror database by finishing all completed transactions and rolling back unfinished ones. Since the old primary is inaccessible, some data may be lost because the synchronous data transfer may not have completed between the time the primary database went down and the transactions got committed on the mirror database.

--This script does a failover of all the databases in a database mirroring session

--to the Mirror server. This will be used in cases where the PRINCIPAL server is no longer available
--and the mirrored databases have to be brought online.
--NOTE: Run this script in the MIRRORED server instance

SET NOCOUNT OFF
DECLARE @strSQL NVARCHAR(200) --variable for dynamic SQL statement - variable size should change depending on the
DECLARE @strDatabasename NVARCHAR(50) --variable for destination directory
DECLARE MyCursor CURSOR FOR --used for cursor allocation
SELECT name FROM master.sys.databases a
INNER JOIN master.sys.database_mirroring b
ON a.database_id=b.database_id
WHERE NOT mirroring_guid IS NULL
AND mirroring_role_desc='MIRROR'
OPEN MyCursor
FETCH Next FROM MyCursor INTO @strDatabasename
WHILE @@Fetch_Status = 0
BEGIN
---Run the ALTER DATABASE databaseName SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
SET @strSQL = 'ALTER DATABASE ' @strDatabaseName ' SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS'
EXEC sp_executesql @strSQL

PRINT 'Bringing ' @strDatabaseName ' ONLINE'
PRINT '============================ ============'
FETCH Next FROM MyCursor INTO @strDatabasename
END
CLOSE MyCursor
DEALLOCATE MyCursor

Once the databases are online, you can now redirect your applications to the new principal server.



36
Vote
Add To: del.icio.us Digg Furl Spurl.net StumbleUpon Yahoo


   

   

   


Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Notify extra people about this comment
Is this a private comment?
List the Email Addresses or Orble Tags of the people you would like to be notified about this comment


One per line max of 30

List the Email Addresses or Orble Tags of the people you would like to be notified about this private comment thread. Only the people in this list will be able to see or reply to your comment.


One per line max of 30

Your Name
(for the email going out to the above list, it can be different to your Orble Tag)
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
4 Posts
11 Posts
1 Posts
77 Posts dating from May 2008
Email Subscription
Receive e-mail notifications of new posts on this blog:
0

Siddharth sood's Blogs

37 Vote(s)
0 Comment(s)
1 Post(s)
84 Vote(s)
0 Comment(s)
2 Post(s)
37 Vote(s)
0 Comment(s)
1 Post(s)
50 Vote(s)
0 Comment(s)
1 Post(s)
29 Vote(s)
0 Comment(s)
1 Post(s)
76 Vote(s)
0 Comment(s)
2 Post(s)
169 Vote(s)
0 Comment(s)
4 Post(s)
213 Vote(s)
2 Comment(s)
5 Post(s)
26 Vote(s)
0 Comment(s)
1 Post(s)
25 Vote(s)
0 Comment(s)
1 Post(s)
Moderated by Siddharth sood
Copyright © 2006 2007 2008 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]