By: Brady Upton | Updated: 2012-06-07 | Comments (33) | Related: > Database Mirroring
Problem
I'm planning on patching my SQL Servers to the latest service pack, but I'm not sure how to complete this for a environment that is using database mirroring.
Solution
In this tip, I am going to outline my environment and then walk through the process of patching mirrored servers.
My test environment consists of two SQL Server 2005 SP2 servers named SSQL1 (principal) and SSQL2 (mirror) that contain eleven mirrored databases. The database mirroring operating mode is set to asynchronous and I'm upgrading to SP4.
Here is a look at the two mirrored instances.
Step 1
Always backup all system and user databases before applying patches. Refer to this SQL Server backup tutorial for more information about creating backups.
Step 2
Remote Desktop into the "Mirror" server (SSQL2 in our example) and download/copy the patch to the server.
Step 3
Stop all SQL Services on the "Mirror" server.
Step 4
Run the patch on the "Mirror" server.
Step 5
Once the patch is complete, reboot the "Mirror" server.
Step 6 (optional)
If your database mirroring is set to asynchronous (High Performance mode), we will need to synchronize the databases first. To do this we will need to issue the following statement for every database on the "Principal" server that is mirrored.
Here are the commands for the 11 databases on my server.
Step 7
The databases might change to "synchronizing" while the transactions catch up. Once all of the databases show "synchronized", as shown below, we can perform the manual failover.
We can perform the failover using the following statement on the principal server for each database:
Here are the commands for the 11 databases on my server.
We can now see that the servers have switched roles.
Step 8 (optional)
Once the failover has taken place and all the databases have switched roles we can set the operating mode back to asynchronous using the following statement on the new principal server:
Here are the commands for the 11 databases on my server.
Patch the New Mirror Server
Now that the roles have been swapped, we will patch our "new" mirror server (SSQL1 in our example).
Step 9
Remote Desktop into the "new" "Mirror" server (SSQL1 in our example) and download/copy the patch to the server.
Step 10
Stop all SQL Services.
Step 11
Run the patch on the server.
Step 12
Once the patch is complete, reboot the server (SSQL1).
Step 13
Upon reboot and login, make sure all databases come online clean and synchronized.
Step 14
You now have two choices, leave the databases alone and leave SSQL2 as the principal and SSQL1 as the mirror or you can fail back to return the environment back to how it was from the beginning.
Step 15 (optional)
If you want to failback again follow these steps.
If you are using asynchronous mode issue this statement for each database:
Once the databases are synchronized then run this statement for each database:
If you need to turn the asynchronous mode on again run this statement for each database:
Here is an example of the commands to run on both servers.
Next Steps
- If you are already using synchronous mirroring please ignore the "SET SAFETY" steps
- To learn how to create a mirrored environment check out this tip
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2012-06-07