Вы находитесь на странице: 1из 20

Module 8

Automating SQL Server


Management
Module Overview

• Automating SQL Server Management


• Working with SQL Server Agent
• Managing SQL Server Agent Jobs
• Multiserver Management
Lesson 1: Automating SQL Server Management

• Benefits of Automating SQL Server Management


• Available Options for Automating SQL Server
Management
• Overview of SQL Server Agent
• Demonstration: SQL Server Agent
Benefits of Automating SQL Server Management

• Reduce administrative workload by automating


and scheduling regular tasks

• Execute routine tasks reliably and consistently

• Proactive management:
• Monitor performance
• Recognize and respond
to potential problems
Available Options for Automating SQL Server
Management

• SQL Server Agent


• This is, of course, the one we’ll be concentrating on

• Maintenance Plans

• PowerShell

• System Center Operations Manager


Overview of SQL Server Agent

• Runs as a Windows Service


• By default this is set to be manually started
• Service starts when requested
• Jobs can perform a number of tasks (or steps)
• Schedules can run one or more jobs
• Alerts can be used to respond to system events
• Operators can be notified by jobs or alerts
Lesson 2: Working with SQL Server Agent

• Defining Jobs, Job Types, and Job Categories


• Creating Job Steps
• Scheduling Jobs for Execution
• Scripting Jobs
• Demonstration: Scripting Jobs
Defining Jobs, Job Types, and Job Categories

• Jobs consist of a series of steps

• Job step types include:


• Command-line script, batch or application
• Transact-SQL statement
• PowerShell script
• SQL Server Integration Service (SSIS) and SSAS commands and
queries

• Jobs can be assigned to categories


• Categories can be predefined in the system
• Categories can be user-defined
Creating Job Steps
Scheduling Jobs for Execution

• Recurrence:
• One time
• When SQL Server Agent starts
• Whenever the CPU is idle

• One job can have multiple schedules

• Multiple jobs can share one schedule


Scripting Jobs

• Script a database task to a job


• Create your own!

• Generate scripts for existing jobs


• Copy someone else’s work!
Lesson 3: Managing SQL Server Agent Jobs

• Viewing Job History


• Querying SQL Server Agent-related System Tables
and Views
• Troubleshooting Failed Jobs
• Demonstration: Viewing Job History and Resolving
Failed Jobs
Viewing Job History

• Information about job history is in the msdb


• Viewed using a Transact-SQL query
• Viewed in SSMS using the Log File Viewer
• Or optionally, information can be written to log files

• SSMS also has the Job Activity Monitor that


shows the current job activity, and the schedules
for active jobs
Troubleshooting Failed Jobs

• SQL Server Agent status:


• Is the service account valid?
• Is the msdb database online?
• Job history:
• Job outcome identifies the last step to execute
• Job step outcome identifies why the step failed
• Job execution:
• Is the job enabled?
• Is the job scheduled?
• Is the schedule enabled?
• Access to dependencies:
• Are all dependent objects available?
Lesson 4: Multiserver Management

• Multiserver Management Concepts


• Considerations for Multiserver Management
• Demonstration: Configuring Master and Target
Servers
• Running Jobs on Target Servers
• Automating Multiserver Maintenance
Multiserver Management Concepts
Considerations for Multiserver Management

• The master server service can impact performance

• Each target server can link to only one master server

• Cannot change a target server name while enlisted

• SQL Server Agent and SQL Server services must use


domain accounts
Running Jobs on Target Servers

• Two methods to distribute jobs to target servers


• Using SSMS, choose the target servers on the Target
page
• Using Transact-SQL command: sp_add_jobserver

• If jobs are updated, they need to be pushed to


target servers
• Transact-SQL command: sp_post_msx_operation

• If you modify the steps or schedule of a job,


you must post the change to the targets
Automating Multiserver Maintenance

• Maintenance plans support creating SQL Server


Agent jobs that can run on master and target
servers

• The execution and monitoring is all undertaken


on the master server

• The Maintenance Plan Wizard can create simple


maintenance plans
Lab: Automating SQL Server Management

• Exercise 1: Create a SQL Server Agent Job


• Exercise 2: Test a Job
• Exercise 3: Schedule a Job
• Exercise 4: Configure Master and Target Servers

Logon Information
Virtual machine: 20764C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 75 minutes

Вам также может понравиться