So you’ve built out your AlwaysOn Availability Group, tested it and it is ready for production. Great! Now, how do you handle all those database dependent SQL Agent jobs? As with many things regarding SQL Server there are many ways to handle the failover of these jobs and in this session we will discuss a few ways to handle automatic failover of SQL Server Agent jobs and the pros and cons of each.
2024: Domino Containers - The Next Step. News from the Domino Container commu...
AlwaysOn Availability Group Job Management
1. Job Management in an
AlwaysOn World
How to handle jobs that need to run on the primary replica.
2. About Me…
• Database Administrator at Boulder County
• Twitter: @_KenWilson
• Blog: SQLBama.com
• LinkedIn: https://www.linkedin.com/in/sqlbama
Ken Wilson
5. Job Types
• Active X
• Command Line
• PowerShell
OS
• Command Jobs
• Query JobsAnalysis Services
• Packages
• Maintenance Plans
Integration
Services
• Replication
• T-SQL StatementsSQL Server
6. 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
7.
8. 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
9. 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
10. 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
11. 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
12.
13. To Recap…
• No one right way to manage jobs
• Document, Document, Document
14. References
• Michael Campbell’s Blog Series
http://sqlmag.com/blog/alwayson-availability-groups-and-sql-server-jobs-part-1-
introduction
• SQL Agent Job Types
https://msdn.microsoft.com/en-US/librAry/ms187056.aspx
• Minion Backup
http://minionware.net/backup/
• Ola Halengren
https://ola.hallengren.com/
Hosting T-SQL Tuesday in August so be on the lookout for that.
ActiveX: slated to be removed in future version.
OS Commans: require bat, cmd, com or exe extensions
Powershell: Either text or script to be executed
Analysis Services: Command jobs or Query Jobs
Integration Services packages
Replication: Snapshot job, Distribution job, Merge job, etc.
Replication Executeables
T-SQL Statements
Gotchas: Using the function if you misspell the database name or the database doesn’t exist it will not error it will simply return 0
Because replication jobs run the replication executeables
Who has AlwaysOn in their environment?
Who has alerts setup to alert them of Data Movement and Role changes?
Three alerts you should have: 35264 (Suspended), 35265 (Resumed), 1480 (Role Change)
Michael Campbell’s blog about alerts
Michael Campbell’s blog series has much more in-depth information about adding job steps and alerts