AlwaysOn Availability Group Job Management

16
Job Management in an AlwaysOn World How to handle jobs that need to run on the primary replica.

Transcript of AlwaysOn Availability Group Job Management

Page 1: AlwaysOn Availability Group Job Management

Job Management in an AlwaysOn WorldHow to handle jobs that need to run on the primary replica.

Page 2: AlwaysOn Availability Group Job Management

About Me…• Database Administrator at Boulder County

• Twitter: @_KenWilson

• Blog: SQLBama.com

• LinkedIn: https://www.linkedin.com/in/sqlbama

Ken Wilson

Page 3: AlwaysOn Availability Group Job Management

Agenda• Types of Jobs

• Job Failover Options

Page 4: AlwaysOn Availability Group Job Management
Page 5: AlwaysOn Availability Group Job Management

Job Types• Active X• Command Line• PowerShell

OS

• Command Jobs• Query JobsAnalysis Services

• Packages• Maintenance Plans

Integration Services

• Replication• T-SQL StatementsSQL Server

Page 6: AlwaysOn Availability Group Job Management

So What Are My Options• Add a job step

• Add a job server

• Move logic out of SQL Agent

• Use Alerts to enable/disable jobs

Page 7: AlwaysOn Availability Group Job Management
Page 8: AlwaysOn Availability Group Job Management

Adding a Job Step• Add top level job step.

• Use logic to detect primary

• Continue Processing

• Exit Gracefully

• Possible Issues Detection could be tricky

In 2012 you need to come up with the logic yourself

In 2014 and newer you can use the system function sys.fn_hadr_is_primary_replica

Misleading Error Log

• Active X• Command Line• PowerShell

OS

• Command Jobs• Query Jobs

Analysis Services

• Packages• Maintenance Plans

Integration Services

• Replication• T-SQL StatementsSQL Server

Page 9: AlwaysOn Availability Group Job Management

Add Job Server• Build a separate SQL Server

• Configure Job Server for Multi-Server Administration

• Point Jobs at target servers

• Possible Issues Initial Setup Cost

• Active X• Command Line• PowerShell

OS

• Command Jobs• Query Jobs

Analysis Services

• Packages• Maintenance Plans

Integration Services

• Replication• T-SQL StatementsSQL Server

Page 10: AlwaysOn Availability Group Job Management

Moving Logic• Move primary detection logic out of the

SQL Agent Job Works well with T-SQL Statements and

OS job types Examples: Ola Hallengren’s Maintenance

Solution and MidnightDBA’s Minion Backup Solution

• Possible Issues Need access to code Replication job types may be difficult to

setup.

• Active X• Command Line• PowerShell

OS

• Command Jobs• Query Jobs

Analysis Services

• Packages• Maintenance Plans

Integration Services

• Replication• T-SQL StatementsSQL Server

Page 11: AlwaysOn Availability Group Job Management

Using Alerts• Setup Alert on 1480 (AlwaysOn Role

Change)

• Setup Job to enable/disable other jobs

• Use the response of the alert to execute the disable/enable job.

• Possible Issues Initial Setup a little more involved False positives are possible

• Active X• Command Line• PowerShell

OS

• Command Jobs• Query Jobs

Analysis Services

• Packages• Maintenance Plans

Integration Services

• Replication• T-SQL StatementsSQL Server

Page 12: AlwaysOn Availability Group Job Management
Page 13: AlwaysOn Availability Group Job Management

To Recap…• No one right way to manage jobs

• Document, Document, Document

Page 15: AlwaysOn Availability Group Job Management

Questions?

Page 16: AlwaysOn Availability Group Job Management