Bài giảng Cơ sở dữ liệu nâng cao Chapter 5 Automating administrative tasks. Những nội dung chính được trình bày trong chương này gồm có Automating administrative tasks in SQL server, SQL server agent, creating maintenance plans.
Trang 1CHAPTER 5
Automating Administrative Tasks
Trang 21 Automating Administrative Tasks in SQL Server
2 SQL Server Agent
3 Creating Maintenance Plans
Trang 31 Overview of Automating Admin Task
• One of the most important advantages of Database
Engine is its capability to automate administrative tasks and hence to reduce costs
• Examples of some important tasks that are performed frequently and therefore could be automated:
• Backing up the database and transaction log
• Transferring data
• Dropping and re-creating index
• Checking data integrity
Trang 42 SQL Server Agent
• Automation Components: There are four basic components
of SQL Server Agent:
• Jobs: Define the work to be done
• Schedules: Define hen the job will be executed
• Alerts: Enables you to set up an automatic response or notification when an event occurs
• Operators: The people who can be notified regarding job status and alerts
Trang 52 SQL Server Agent
• Jobs:
• Jobs are the tasks you wish to execute on a schedule Jobs consist of job steps, which define the individual task to run and what happens if the step fails
• Steps are defined using Transact-SQL or wizards
• When defining job steps, you can specify their order
• Jobs are associated with flexible schedules
Trang 62 SQL Server Agent
• Schedule:
• Each created job can be executed on demand (manually by the user) or by using one or more schedules
• A scheduled job can occur at any of these times
• When SQL Server Agent starts.
• Once, at a specified date and time.
• On a recurring basis.
• When the CPU utilization of your server is idle
Trang 73 SQL Server Agent
• Alert:
• Actions that SQL Server will perform when a
particular event occurs
• Alerts consist of conditions and actions
• Conditions can be specific error codes, error severities or object states like databases files growing to a certain
size
• Actions performed by an alert are notifying a person, or running a job
Trang 83 SQL Server Agent
• Alert:
• SQL Server event
• The SQL Server event alerts are based mainly on error messages
• You might create an alert on error message number 9002 (log file full) or 1105 (out of disk space) message An alert can be fired for any particular database or all databases
• SQL Server performance condition
• Windows Management Instrumentation (WMI) event
Trang 93 SQL Server Agent
• Operator:
• People who will be notified of alerts or job completion
• SQL Server Agent can notify operators through e-mail, pager, or a net send network command
Trang 103 SQL Server Agent
• Multi Server Job:
• SQL Server also supports the ability to create and manage jobs on one server that can be run on multiple SQL Servers This
functionality grants you the ability to administer and control multiple servers at once
• Multi-server jobs are configured by first defining a master server
Trang 113 Maintenance plan
• Maintenance plans are a quick and easy way to automate routine maintenance tasks in SQL Server.
• There are two ways to create maintenance plans:
• Use the Maintenance Plan Wizard
• The manual way: use the Maintenance Plan Designer
Trang 123 Maintenance plan
• Maintenance Plan Wizard:
• Through the Wizard, available tasks to be performed automatically:
• Checking database integrity
• Shrink the database
• Re-organize indexes
• Re-build indexes
• Update statistics
• Clean up history
• Executing a SQL Server Agent job
• Backing up databases using full, differential, or transaction log backups
Trang 133 Maintenance plan
• Maintenance Plan Wizard: Following steps are used to
create plan:
• The first step is to launch the Wizard
• On this page, specify a name and description for the plan and
select the scheduling options
• Select Next to move on to the Select Maintenance Tasks screen to choose the tasks that needs the plan to perform
• If multiple tasks are selected reorder them to run in the order
• Select the reporting options for the plan:
• write a log to a specific location
• Send an e-mail, or both.
• Confirm the selections and click “Finish”
Trang 143 Policy-based Management
• Policy-Based Management allows user to do the following tasks:
• view and configure settings on multiple instances of SQL Server
• apply a configuration change to a group of servers with one
administrative action
• enforce standards on your SQL Server, for example, object naming standards
Trang 153 Policy-based Management
• Key components of Policy-Based Management
• Managed targets:
• Are the objects will be managed with Policy-Based Management
• Instances of SQL Server, databases, tables, indexes, and other
database objects can be targeted for Policy-Based Management Targets are presented in a logical hierarchy
• Facet:
• Are essentially a logical group of properties that apply to a particular target
• For example, the facet Server Information applies to targets of type Server This facet contains many properties including Collation,
IsClustered, and IsSingleUser.
Trang 163 Policy-based Management
• Key components of Policy-Based Management
• Condition:
• Are expressions that represent what states are allowed for a particular target or target set.
• The expression is generally represented by a formula such as facet
property <comparison operator> value
• An example is Table facet, Name LIKE ‘tbl_’ This condition states that
• table names must start with ‘tbl_’
Trang 173 Policy-based Management