Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL Server Automation (Maintenance Plan)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Automating SQL

Server
Baro Technologies
SQL Server Automation
• Automating common maintenance activities using Maintenance Tasks
• Scheduling jobs to perform maintenance activities using SQL Server Agent
• Securing the jobs you create using SQL Server Agent security
• Configuring SQL Server Agent to meet your needs
• Scheduling jobs across multiple servers using the multiserver admin
capabilities
• Much of the work that a database
administrator (DBA) does is repetitive:
• backing up databases,
• rebuilding indexes,
• checking for file sizes
• disk-space availability.
• Two features in SQL Server come to the
rescue of the DBA:
• Maintenance Plans
• SQL Server Agent.
Maintenance Plans enable you to Backups, database integrity checks,
automate the routine maintenance and index maintenance tasks can be
activities for a database. automated with Maintenance Plans.

The Maintenance Plan Wizard makes it easy to create


Maintenance Plans.

SQL Server Agent enables you to manually create a schedule of


jobs to be run on a SQL Server, further enhancing the ability of the
DBA to automate routine activities.
MAINTENANCE PLANS
• Maintenance Plans are a quick-and-easy way to
automate routine maintenance tasks in SQL Server.
• They are no more than a user interface on top of
regular SQL Server Agent jobs.
• Maintenance Plans are built using SQL Server
Integration Services (SSIS), and these are then run
as a single SSIS job step in a job that maps to the
Maintenance Plan name.
• You can create and maintain Maintenance Plans in
two ways. The quick-and-easy way is to use the
Maintenance Plan Wizard, and the manual way is
to use the Maintenance Plan Designer.
Benefits of Automating SQL Server Management

Reduced administrative workload Proactive management

Automate and Schedule regular tasks Monitor Performance


Recognize and respond to potential
problems
• Database Maintenance is a term we use to describe a set of tasks that are all run with
the intention to improve your database.
• There are routines meant to help performance, free up disk space, check for data
errors, check for hardware faults, update internal statistics, and many other tasks.

• What/HOW do you use to create your maintenance plan?


• Which system database does the job information get stored?
• Would you backup your system databases and WHY?
• How do you know if the job you scheduled fails to run?
Maintenance Plans Task

Backup - All Tables, Full Backup (daily) - if DB is big weekly

Backup – Differential (hourly) - If DB is big daily Dif

Backup - Transaction Logs (every 15 minutes)

Check database integrity (daily) - If it DB is big (1TB +) weekly

Index Optimize (daily)

Update statistics (daily)

Maintenance cleanup (daily)


Scheduling Maintenance Plan

WHAT TO CONSIDER WHEN -TYPE OF ENVIRONMENT ( - CONSULT APPLICATION - SIZE OF THE DATABASE. - WHAT KIND OF
CREATING SCHEDULE AND PROD,QA,DEV) OWNERS (RPO,RTO, ENVIRONMENT ( OLTP,
MAINTENANCE PLAN. RETENTION PLAN) OLAP)
Methods of Creating Maintenance Plan

• Maintenance Plan
• Maintenance Plan Wizard
• T-sql scripts
• Powershell
• Cmdshell
• Ola Halengreen (Maintainacesoultion.sql)
• https://ola.hallengren.com/
SQL Server Agent

• It is a Microsoft Windows service that executes scheduled administrative


tasks, which are called jobs in SQL Server.
Benefits of SQL Server Agent
• SQL Server Agent uses SQL Server to store job information.
• Jobs contain one or more job steps. =>Each step contains its own task
• SQL Server Agent can run a job on a schedule, in response to a specific
event, or on demand.
• If the job encounters a problem, SQL Server Agent can record the event
and notify you.
SQL Server Agent Components

• SQL Server Agent consists of four basic components:


• Jobs—Defines the work to be done.
• Schedules—Defines when the job will be executed.
• Operators—Lists the people who can be notified for job statuses and alerts.
• Alerts—Enables you to set up an automatic response or notification when an event
occurs.
Jobs

• A job is a specified series of actions that SQL Server Agent performs.


• Use jobs to define an administrative task that can be run one or more times
and monitored for success or failure.
• A job can run on one local server or on multiple remote servers.
• Each action in a job is a job step=>Job steps are managed as part of a
job.=>Each job step runs in a specific security context.
Schedules

• A schedule specifies when a job runs.


• A schedule can define the following conditions for the time when a job
runs:
I. Whenever SQL Server Agent starts.
II. Whenever CPU utilization of the computer is at a level you've defined as idle.
III. One time, at a specific date and time.
IV. On a recurring schedule.
Alerts
• An alert is an automatic response to a specific event.
• For example,
An event can be a job that starts or system resources that reach a specific threshold.
• An alert can respond to one of the following conditions:
❖ SQL Server events
❖ SQL Server performance conditions
❖ Microsoft Windows Management Instrumentation (WMI) events on the computer where
SQL Server Agent is running
• An alert can perform the following actions:
❖ Notify one or more operators
❖ Run a job
Operators
• An operator defines contact information for an individual responsible for
the maintenance of one or more instances of SQL Server.
• SQL Server can notify operators of alerts through...
• E-mail
• Pager (through e-mail)
• net send
❖ To send notifications to operators by using e-mail or pagers, you must
configure SQL Server Agent to use Database Mail.
❖ You can define an operator as the alias for a group of individuals.
Job Activity Monitor
• Use this page to view the current activity of SQL Server Agent jobs.
• Click Filter to limit the jobs displayed.
• The Agent Job Activity grid is read-only.
• Select the column headers to sort the grid.
• To modify a job, double-click the job to open the Job Properties dialog box.
• Right-click a job in the grid to start it running all job steps, start at a
particular job step, disable or enable the job, refresh the job, delete the job,
view the history of the job, or view the properties of the job.
• Click Refresh to update the grid with current information.
Managing SQL Server Agent Jobs

• Viewing Job History


• Querying SQL Server Agent-related System Tables and Views
• Troubleshooting Failed Jobs
• SQL Server Agent keeps history information in msdb
• Job history can be queried directly or viewed through SSMS
• Job Activity monitor shows current live information
• Retention of history can be configured based on time or size

You might also like