Remote server to Run SQL JOBS on Always ON Availability groups

I am planning to have AlwaysON Availability Groups setup between Server 1 and Server 2

Server 1 -->Publisher-->2014 SQL Enterprise edition-->Windows Std 2012 --> Always on Primary Replica

Server 2 -->Publisher(when DR happens)-->2014 SQL Enterprise edition-->Windows Std 2012 --> Secondary  Primary

Server 4 as Subscriber

Server X  as Remote Distributor ..

as of now , In the event of Disaster happens on Node 1  i will have to manage JOBS on Node 2  (backups, Maintenance, replication, day-day other Jobs)..

Is there a way i can call all jobs to run from a remote server which executes on Active NODE(which ever is active)? so that in the event of disaster happens on node1, when  node 2 becomes online and  i don't have to do anything with SQL Agent or jobs on Node 2?  Please provide any suggestion 

September 14th, 2015 5:50pm

Hi coolguy123SQL,

There is no need to call all jobs to run from a remote server in your scenario.

To make SQL Server Agent jobs work properly after a failover, you can add logic at the beginning of each relevant job to make the job execute only on the primary database.

Firstly , for backup jobs, you can use the sys.fn_hadr_is_preferred_backup_replica function to identify whether the local replica is the preferred one for backups. Please note that backup jobs created using the Maintenance Plan Wizard natively use this function. For more details about SQL Server AlwaysOn and backups, please review this blog.

Secondly, when you
configure original publisher redirect to the AlwaysOn Availability Group listener name, it will ensure that the subscribers can reconnect to the publisher after a failover of the AlwaysOn Availability Group and replication will continue working. For more details, please review Expanding AlwaysOn Availability Groups with Replication Publishers and Expanding AlwaysOn Availability Groups with Replication Subscribers.

For other jobs, you can add some conditional logic to test for if the current instance acts as Primary replica. For more details, please review this similar thread.

if (select

        ars.role_desc

    from sys.dm_hadr_availability_replica_states ars

    inner join sys.availability_groups ag

    on ars.group_id = ag.group_id

    where ag.name = 'YourAvailabilityGroupName'

    and ars.is_local = 1) = 'PRIMARY'

begin

    -- this server is the primary replica, do something here

end

else

begin

    -- this server is not the primary replica, (optional) do something here

end

Reference:
https://msdn.microsoft.com/en-us/library/hh270282.aspx?f=255&MSPPError=-2147217396



Thanks,
Lydia

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 10:22pm