Question: What would be the best practice to configure Failover Clustering and Database Mirroring?
This question is frequently asked in one of the technical discussion groups I frequent. My reply follows.
I have a customer that wants to combine Failover Clustering with Database Mirroring in which the last one will be for disaster recovery. In order that the mirroring will act as primary only if the cluster fails, does the mirroring should be configured as manual? How do we configure mirroring in automatic when both nodes in the cluster fail?
My answer:
If you want automatic failover in case all clustering nodes fail, then you should definitely not set it to manual failover only. The best practice is to set the partner timeout period for mirroring to a number large enough to not be triggered by a cluster failover. The default timeout is 10 seconds.
The following command would set it to a timeout of 30 seconds:
Alter Database <Database Name> Set Partner Timeout 30;
Note: this can be set on the principal server only.
Question: Will the Mirror automatically fail back to the original Principal when it comes back online?
This question doesn't usually come up until someone has experienced an unplanned failover and something that they forgot about has been failing as a result. Hopefully this question will start coming up while planning for database mirroring.
Automatic failover only occurs as a result of the current Principal being offline. Database Mirroring does not have any mechanisms built in to set one server as the default active server. When the Mirror partner takes over as the active Principal partner, it will continue to serve as Principal until a failure triggers another automatic failover or a manual failover is performed.
You can set up this functionality on your own, however. It's a simple process. Create a procedure to check the state and role of your mirror partners and manually fail them back to the original Principal if it is connected and in a synchronized state. Then set up a job to run this procedure every minute. Once the original Principal is back online and fully synchronized, the job will fail the server back within one minute.
The procedure:
Create Procedure dbo.dbm_FailoverMirrorToOriginalPrincipal @DBName sysnameAsDeclare @SQL nvarchar(200)Set NoCount On;/* If database is in the principal role and is in a synchronized state then fail database back to original principal*/If Exists (Select 1 From sys.database_mirroring Where database_id = db_id(@DBName) And mirroring_role = 1 -- Principal partner And mirroring_state = 4) -- Synchronized Begin Set @SQL = 'Alter Database ' + quotename(@DBName) + ' Set Partner Failover;' Exec sp_executesql @SQL; EndSet NoCount Off;
Please Note:
You may wonder why I use dynamic SQL for this procedure rather than just hard coding the database name. If you hard code the database name and try to create the procedure while the database is in the mirror role, it will fail because it will be referencing a database that is offline.
How do I ... Determine Database Growth If I Am Not Tracking It?
If your database has grown considerably and you're not sure when or why it happened, you'll be hard pressed to figure out the answer unless you're tracking changes in database size. Luckily, if you are performing regular full backups, you can get this information from the SQL logs.
When you create a full backup, SQL creates an entry in the SQL Log that looks like the following:
Database backed up. Database: PSP, creation date(time): 2008/12/22(18:25:10), pages dumped: 171, first LSN: 39:41:37, last LSN: 39:59:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'c:\Bak\PSP.bak'}). This is an informational message only. No user action is required.
So we can look for these statements in the SQL logs, parse out the pages dumped, and calculate the size of the used portion of the database.
The Script:
Declare
Question: Why does Database Mirroring Monitor report that my mirror is disconnected?
This question was sent to a discussion list via email. My reply follows.
Sometimes, I have seen a behavior where the Principal was unable to connect to the Mirror. What is the reason for this behavior? Could it be network? I could not find any information that explain this behavior. Any help here would be appreciated.
This does not mean that the principal is disconnected from the mirror. This simply means that the Database Mirroring Monitor has not connected to the mirror yet. This is not an unusual behavior to see when first looking at a mirrored database in the monitor. The monitor connects to the principal and then to the mirror. Usually, this will clear up within a few seconds on its own as it eventually makes the connection. If it does not make the connection on its own within a short time, then the problem exists between the monitor and the mirror.
Question: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup?
This question was sent to me via email. My reply follows.
Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? Databases to be mirrored are currently running on 2005 SQL instances but will be upgraded to 2008 SQL in the near future. I have not tried this, need mirroring setup and was hoping to get a jump on the future upgrade.
Yes, a SQL 2008 machine can act as witness for 2 SQL 2005 machines. When upgrading the systems from SQL Server 2005 to SQL Server 2008, the witness can be upgraded at any time (first, last, or in the middle).
Consider a simple scenario with Asynchronous mirroring:
We are implementing asynchronous [high performance] mirroring without witness. The client application connects to the mirroring session using below connection string:Source={PrincipalServerName};Initial Catalog={DBName};Integrated Security=SSPI;Failover Partner= {MirrorServerName} Now due to some disaster, the Principal Server goes offline and will be offline for let’s say next 48 hours. We notice that client connections fail since primary is offline and a failover has not yet be done. What steps should be taken now to connect the client application to the mirrored database?
I can force the service or break the mirroring session (assuming with possible data loss) and re-setup later when Principal comes online.
Is above statement correct? If yes, what changes do I need do in the connection strings for force service and breaking the mirror? Would connection string in step#2 works with failover partner parameter?
Yes, those are your only options for bringing the mirror online at this point. Forcing the service is preferable. If you force the service, no changes will need to be made to the connection strings because the clients will be able to connect to the failover partner. If you break mirroring, the Failover Partner parameter of the connection string will not be honored because the database is not currently participating in mirroring. You would have to alter the connection string to point at the mirror as the principal. One caveat to this is if you were already running on the original mirror as the current principal and the server you force service on is listed as the principal in the connection string already, no changes will need to be made. As described above. Always yes for forced service, usually no but sometimes yes for breaking the mirror.
The following scripts can be downloaded as text files. You will need to change the file extension to .ps1 in order to execute them. Backup a database Restore a database Scan a server to find a free port Query DNS to get the FQDN of a server
To see some examples of my other forms of writing, please visit my page on WritersCafe.org. It is almost exclusively horror fiction, but I sometimes throw other things in there too from time to time. There's one science fiction story, a couple of poems, and quite a few humor pieces as well.
Look for me in the SQL Q&A section of the August, 2007 issue of TechNet Magazine. August issue of TechNet Magazine's SQL Q&A column