Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automating SQL Server Management

Similar presentations


Presentation on theme: "Automating SQL Server Management"— Presentation transcript:

1 Automating SQL Server Management
Module 8 The 20764A-MIA-SQL virtual machine used in the lab for this module includes software services that can take a while to start. For the best experience, have students start the 20764A-MIA-DC and 20764A-MIA- SQL virtual machines at the beginning of the module so that the services are ready before they start the lab. Automating SQL Server Management

2 Multi-Server Management
Module Overview 8: Automating SQL Server Management Multi-Server Management

3 Lesson 1: Automating SQL Server Management
Demonstration: SQL Server Agent

4 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 Talk the students through the benefits of automation, using the examples and scenarios in the student notes.

5 Available Options for Automating SQL Server Management
SQL Server Agent Maintenance Plans PowerShell System Center Operations Manager Explain that there are many ways to automate the management of SQL Server. In this module, you will be focusing on SQL Server Agent as the primary method of automation.

6 Overview of SQL Server Agent
8: Automating SQL Server Management Runs as a Windows Service By default this is set to be manually started Jobs are able to perform a number of tasks Schedules can be defined to run one or more jobs Alerts can be used to respond to system events Operators can be notified by jobs or alerts

7 Demonstration: SQL Server Agent
8: Automating SQL Server Management In this demonstration, you will see how to: Create a simple job, and step Run a job, and review the output SQL Server Agent should be running in the virtual machines by default; if you are unable to expand it, click Refresh in the Object Explorer. Preparation Steps Start the 20764A-MIA-DC and 20764A-MIA-SQL virtual machines. Demonstration Steps Create a Job Ensure that the 20764A-MIA-DC and 20764A-MIA-SQL virtual machines are running, and then log on to 20764A-MIA-SQL as AdventureWorks\Student with the password Pa$$w0rd. In Windows Explorer, navigate to D:\Demofiles\Mod08, right-click Setup.cmd, and then click Run as administrator. In the User Account Control dialog box, click Yes. On the taskbar, click Microsoft SQL Server Management Studio. In the Connect to Server dialog box, in Server name box, type MIA-SQL and then click Connect. In Object Explorer, expand SQL Server Agent, and then expand Jobs. Note that there are existing jobs on the server. Right-click the Jobs folder, click New Job. In the New Job dialog box, in the Name box, type Manual AdventureWorks Backup, and in the Category list, select Database Maintenance. On the Steps page, click New. In the New Job Step dialog box, in the Step name box, type Backup AdventureWorks, and in the Database list, select AdventureWorks. (More notes on the next slide)

8 Lesson 2: Working with SQL Server Agent
8: Automating SQL Server Management Demonstration: Scripting Jobs

9 Defining Jobs, Job Types, and Job Categories
8: Automating SQL Server Management Jobs consist of a series of steps Job step types include: Command-line script, batch of commands or application Transact-SQL statement PowerShell script SSIS and SSAS commands and queries Jobs can be assigned to categories Explain that a job is a specified series of operations performed sequentially by SQL Server Agent. Talk through the job step types on the slide, and then the code sample in the student manual.

10 Write to Application Log
Creating Job Steps 8: Automating SQL Server Management Backup Database Transfer Data Execute App Success Job Succeeded Notify Operator Job Failed Write to Application Log Failed Job Started Explain how a job consists of individual steps that can be of different types. Review the arguments in the table and show the same properties of a job step in SSMS. Discuss the graphic shown on the slide associated with this topic, noting the different actions taken, depending on the step outcome.

11 Scheduling Jobs for Execution
20764A Scheduling Jobs for Execution 8: Automating SQL Server Management 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 Explain the different types of schedules and point out that they can be shared. Use the graphic on the slide to explain that one job may have more than one schedule. Point out that only one instance of a job can run at any one time.

12 Script a database task to a job Generate scripts for existing jobs
Scripting Jobs 8: Automating SQL Server Management Script a database task to a job Generate scripts for existing jobs

13 Demonstration: Scripting Jobs
8: Automating SQL Server Management In this demonstration, you will see how to: Script a task to a job Generate scripts for existing jobs Preparation Steps Complete the previous demonstration. Demonstration Steps Script a Task to a Job In SSMS, in Object Explorer, expand Databases, right-click AdventureWorks, point to Tasks, and then click Back Up. In the Back Up Database - AdventureWorks dialog box, in the Destination section, click the existing backup destination, and then click Remove. Click Add and in the Select Backup Destination dialog box, in the File name box, type D:\Demofiles\Mod08\Backups\AdventureWorksScript.bak, and then click OK. In the Back Up Database - AdventureWorks dialog box, on the toolbar, in the Script drop-down list, select Script Action to Job. In the New Job dialog box, on the General page, note the default name for the job (Back Up Database - AdventureWorks). On the Steps page, note that the job includes one Transact-SQL step named 1. On the Schedules page, click New. In the New Job Schedule dialog box, in the Name box, type Week Days. In the Frequency section, select Monday, Tuesday, Wednesday, Thursday, and Friday, and then click OK. In the New Job dialog box, click OK. In the Back Up Database - AdventureWorks dialog box, click Cancel so that the job is saved, but not yet run. Verify that the job appears in the Jobs folder in Object Explorer. (More notes on the next slide)

14 Lesson 3: Managing SQL Server Agent Jobs
8: Automating SQL Server Management Demonstration: Viewing Job History and Resolving Failed Jobs

15 20764A Viewing Job History 8: Automating SQL Server Management Information about job history is written to tables in the msdb database Can be viewed via a Transact-SQL query Can be viewed in SSMS by using the Log File Viewer Optionally the 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 Explain that SQL Server Agent keeps track of job and job step outcomes in system tables in msdb and that writing to the Windows Application and SQL Server log files is an optional extra. Mention that querying the system tables will be discussed in the next topic. Explain that students can configure the retention policy, based on time or size, in the property window of SQL Server Agent.

16 Querying SQL Server Agent-related System Tables and Views
8: Automating SQL Server Management Configuration and history information is stored in msdb.dbo schema Use history tables to automate collection of job history over several systems The dbo.sysjobhistory table contains a row for each job with a step_id = 0. This contains the result for the whole job Talk students through the example in the student manual, and briefly show the SQL Server Agent Tables (Transact-SQL) page online to detail the variety of tables available. Be sure to point out that the step_id <> 0 limits the result set to the job steps only.

17 Troubleshooting Failed Jobs
8: Automating SQL Server Management 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? Talk the students through the key troubleshooting steps for job issues.

18 Demonstration: Viewing Job History and Resolving Failed Jobs
8: Automating SQL Server Management In this demonstration, you will see how to: Run jobs Troubleshoot a failed job Preparation Steps Complete the previous demonstrations. Demonstration Steps Run Jobs In SQL Server Management Studio, in Object Explorer, right-click Back Up Database – AdventureWorks, and then click Start Job at Step. When the job has completed successfully, click Close. In Object Explorer, right-click Check AdventureWorks DB, and then click Start Job at Step. Note that this job does not start automatically because it has more than one job step. In the Start Job on 'MIA-SQL' dialog box, in the Start execution at step table, click 1, and then click Start. Note that the job fails, and then click Close. Troubleshoot a Failed Job In Object Explorer, right-click Back Up Database – AdventureWorks, and then click View History. In the Log File Viewer - MIA-SQL dialog box, expand the date for the most recent instance of the job, note that all steps succeeded, and then click Close. In Object Explorer, right-click Check AdventureWorks DB, and then click View History. In the Log File Viewer - MIA-SQL dialog box, expand the date for the most recent failed instance of the job, and note that the step 3 failed. Select the step that failed, and in the pane at the bottom of the dialog box, view the message that was returned. You may have to scroll to the bottom. Then click Close. In Object Explorer, double-click Check AdventureWorks DB. In the Job Properties - Check AdventureWorks DB dialog box, on the Steps page, in the Job step list table, select step 3, and then click Edit. (More notes on the next slide)

19 Lesson 4: Multi-Server Management
8: Automating SQL Server Management Automating Multi-Server Maintenance Question Which of the following statements is false? ( )Option 1: A master server can have multiple target servers. ( )Option 2: A high-load master server won’t have any adverse performance impact by having a number of target servers. ( )Option 3: Each target server can only connect to a single master server. ( )Option 4: Changing the name of a target server requires it to be registered with the master server. Answer (√) Option -2: A high-load master server won’t have any adverse performance impact by having a number of target servers.

20 Multi-Server Management Concepts
8: Automating SQL Server Management Master server (MSX) Holds central copy of job definitions Distributes jobs to target servers Receives messages and alerts from target servers Target servers (TSX) Assigned to one master server Connect to master server to update schedules of jobs Downloads new jobs from master server

21 Considerations for Multi-Server Management
8: Automating SQL Server 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

22 Demonstration: Configuring Master and Target Servers
8: Automating SQL Server Management In this demonstration, you will see how to: Use the Master Server Wizard Use Transact-SQL to register target servers Emphasize that, to use Transact-SQL to register target servers, the command must be run on the target server’s database engine. Preparation Steps Complete the previous demonstrations. Demonstration Steps Use the Master Server Wizard In SQL Server Management Studio, in Object Explorer, under MIA-SQL, right-click SQL Server Agent, point to Multi Server Administration, and then click Make this a Master. In the Master Server Wizard – MIA-SQL dialog box, on the Welcome to the Master Server Wizard page, click Next. On the Master Server Operator page, in the address box, type and then click Next. On the Target Servers page, expand Database Engine, expand Local Server Groups. Click mia-sql\sql2, click the >, and then click Next. In the Checking Server Compatibility dialog box, click Close. On the Master Server Login Credentials page, click Next. On the Complete the Wizard page, click Finish. When configuration is complete, click Close. Use Transact-SQL to Register a Target Server In Object Explorer, on the toolbar, click Connect, and then click Database Engine. In the Connect to Server dialog box, in the Server name list, select MIA-SQL\SQL3, and then click Connect. In Object Explorer, under MIA-SQL\SQL3, expand Databases, expand System Databases, right- click msdb, and then click New Query. (More notes on the next slide)

23 Running Jobs on Target Servers
8: Automating SQL Server Management 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 Emphasize that if you modify the steps or schedule for a job, you have to post the change to the download list.

24 Automating Multi-Server Maintenance
8: Automating SQL Server Management 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

25 Lab: Automating SQL Server Management
Exercise 4: Configure Master and Target Servers Exercise 1: Create a SQL Server Agent Job The HumanResources database must be backed up every day. Additionally, after the backup has been created, the backup file must be copied to a folder, which is automatically replicated to a cloud service for offsite storage of various backup files. Exercise 2: Test a Job You plan to test the new backup job before you schedule it to execute in a production environment. Through the process of testing, you identify a defect in the job. You must resolve the defect and ensure the backup is copied to the correct folder location. Exercise 3: Schedule a Job You have created a job to back up the HumanResources database. Now you must schedule the job to run automatically each day. Exercise 4: Configure Master and Target Servers You have been tasked with backing up all the system databases within your company. You have decided to utilize the ability to create a maintenance plan and run this plan across all the company’s servers. Logon Information Virtual machine: 20764A-MIA-SQL User name: ADVENTUREWORKS\Student Password: Pa$$w0rd Estimated Time: 75 minutes

26 20764A Lab Scenario 8: Automating SQL Server Management You are a database administrator (DBA) at Adventure Works Cycles, with responsibility for databases on the MIA-SQL instance of SQL Server. Routine tasks that must be performed on this instance have previously been performed manually, but you now plan to automate these tasks using SQL Server Agent.

27 Module Review and Takeaways
8: Automating SQL Server Management Best Practice Best Practice: When using a large number of target servers, avoid defining your master server on a production server because the target server traffic may impact performance on the production server.


Download ppt "Automating SQL Server Management"

Similar presentations


Ads by Google