DQS with AlwaysOn automatic failover

In the last blog post I described how to set up DQS in AlwaysOn.

In this post I will setup automatic failover of the database. The actual failover is handled by SQL server

availability groups, but there are a couple of steps that has to be done manually to be able to connect successfully

to the DQS database after a failover, automatic or manual.

I’m using the document as a guide for this setup:

http://msdn.microsoft.com/en-us/library/jj874055.aspx

The problem is the mapping of SID’s don’t get aligned correctly between the different hosts in the AG.

In manual or planned failover scenario it is easy to just run the following commands database failover has completed:

ALTER AUTHORIZATION ON DATABASE::[DQS_MAIN] TO [##MS_dqs_db_owner_login##]

ALTER AUTHORIZATION ON DATABASE::[DQS_PROJECTS] TO [##MS_dqs_db_owner_login##]

ALTER AUTHORIZATION ON DATABASE::[DQS_STAGING_DATA] TO [##MS_dqs_db_owner_login##]

USE DQS_MAIN

ALTER USER dqs_service WITH LOGIN=[##MS_dqs_service_login##]

USE DQS_PROJECTS

ALTER USER dqs_service WITH LOGIN=[##MS_dqs_service_login##]

In unplanned automatic failover no one is around to run the command, this can solved by creating the following solution:

Create a database on each node, DQSFailoverStatus, and then a table called replica_role

USE DQSFailoverStatus;

CREATE TABLE [dbo].[replica_role]

(

[replica_role] [tinyint] NULL

)

INSERT INTO [dbo].[replica_role] ([replica_role])

(

SELECT [role]

FROM sys.dm_hadr_availability_replica_states

WHERE is_local = 1

);

Create a SQL agent Job on all nodes in the AG:

USE DQSFailoverStatus;

DECLARE @last_role TINYINT;

SET @last_role =

(

SELECT TOP 1 [replica_role]

FROM [dbo].[replica_role]

);

DECLARE @current_role TINYINT;

SET @current_role =

(

SELECT ROLE

FROM sys.dm_hadr_availability_replica_states

WHERE is_local = 1

);

— Last time it was secondary, currently it is primary; run the commands
— to alter the authorization

IF (@last_role = 2 AND @current_role = 1)
BEGIN
ALTER AUTHORIZATION ON DATABASE::[DQS_MAIN] TO [##MS_dqs_db_owner_login##]
ALTER AUTHORIZATION ON DATABASE::[DQS_PROJECTS] TO [##MS_dqs_db_owner_login##]
ALTER AUTHORIZATION ON DATABASE::[DQS_STAGING_DATA] TO [##MS_dqs_db_owner_login##]

USE DQS_MAIN;
ALTER USER dqs_service WITH LOGIN=[##MS_dqs_service_login##]

USE DQS_PROJECTS;
ALTER USER dqs_service WITH LOGIN=[##MS_dqs_service_login##]
END

USE DQSFailoverStatus;
UPDATE dbo.[replica_role] SET [replica_role] = @current_role;

Depending on your SLA requirements setup the agent job to run every 5-15 minutes.

If you have multiple AG’s on you installation the check script has to be modified slightly to recognaize the AG name where you DQS database is running, something like this:

SELECT ROLE
FROM sys.dm_hadr_availability_replica_states states
join sys.dm_hadr_name_id_map map
on states.group_id = map.ag_id
WHERE states.is_local = 1
and map.ag_name =’IT’

Advertisements

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