Tài liệu MASTERING SQL SERVER 2000- P13 pptx

50 378 0
Tài liệu MASTERING SQL SERVER 2000- P13 pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CHAPTER 16 • BASIC ADMINISTRATIVE TASKS 620 13. Click OK on the message that informs you of success and then click Close on the Log Detail screen to complete the Wizard. The Copy Database Wizard is a simple tool that makes a complex task much easier. Summary In this chapter, we talked about how to administer and maintain your databases so that they will always be running in top condition. The first topic to come up was backups; there are many reasons to back up data: natural disaster, hardware malfunction, even people with malicious intent. If you per- form regular backups, you can overcome these problems. There are four types of backups to help you thwart the evils that would claim your data. First, there is the full backup, the basis of all other backups, which makes a copy of the entire database. Next, the differential backup grabs all of the changes made to 2627ch16.qxt 8/22/00 10:58 AM Page 620 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 621 the database since the last full backup. The transaction log backup came next and is very useful for quick backup strategy, point-in-time restores, and clearing the transac- tion log on a periodic basis. Finally, there is the filegroup backup, used to make back- ups of small chunks of very large databases. After a discussion of backups, we hashed out the fine points of index maintenance. It is very important to keep your indexes up to snuff so that data access will always be fast. To keep them in top shape, use DBCC SHOWCONTIG to determine fragmenta- tion and then use CREATE INDEX with the DROP_EXISTING option or DBCC DBREINDEX to reconstruct fragmented indexes. After that, we looked at the importance of monitoring the SQL Server event logs as well as the mechanics of doing so. Finally, we discussed the Copy Database Wizard. Now that you know that you need to perform all of these tasks, probably on a nightly or weekly basis, wouldn’t it be nice if you could have someone else do it for you? In the next chapter, we’ll discuss automation; you will learn how to make SQL Server do a lot of your work for you, including backups. SUMMARY Administering SQL Server PART IV 2627ch16.qxt 8/22/00 10:58 AM Page 621 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. This page intentionally left blank Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 17 Automating Administration FEATURING: Automation Basics 625 Configuring Mail Support 627 Creating Operators 629 Creating Jobs 631 Creating Alerts 647 Using the Database Maintenance Plan Wizard 660 Working with SQL Mail 671 Summary 673 2627ch17.qxd 8/22/00 11:00 AM Page 623 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. T hroughout this book, we have discussed administrative activities that would best be performed during off-hours. These activities include backing up data- bases, creating large databases, reconstructing indexes—the list goes on. Most of these activities will need to be performed on a regular basis, not just once. For example, you will need to back up at frequent intervals. Because most administrators would rather not need to stand at the SQL Server to start the task in question, SQL Server has the built-in capability to automate tasks. The first thing we need to discuss is the basics of how automation works in SQL Server. We’ll explain some of the basic concepts of automation and how the SQLServerAgent service plays a part. After we discuss the basics of automation, we will need to set up and configure e-mail support, because SQL Server is capable of sending you e-mail when there is a problem as long as e-mail is configured properly. Not only that, but SQL Server can receive and process queries via e-mail, and send the result set back in an e-mail to the sender. However, all of this can be done only when e-mail is configured. Next we will configure operators. An operator is a person who is able to receive messages from SQL Server via e-mail, pager, or Net Send. Configuring an operator tells SQL Server whom to contact and when they are available. After we have operators in place, we can start creating jobs, the heart of automa- tion. Jobs are the activities that you need to administer, such as database backups or index reconstruction. We will discuss each part of a job, the steps required to com- plete the job, and the schedules that tell SQL Server when to run the job. We will also go over the process of creating multiserver jobs, which can be created on one server and run on multiple servers over a network. Next we will configure alerts, which are used to warn you of problems or events that have occurred on the server. Not only will we discuss how to configure standard SQL Server alerts, but we will discuss the methods for creating your own user-defined alerts to cover any possible event that may occur on your server. After all of this, we will discuss the Database Maintenance Wizard. This special Wizard is designed to automate all of the standard database maintenance procedures such as backups, index reconstruction, transaction log backup, etc. Finally, we will discuss the uses and configuration of SQL Mail. Using this tool, you can e-mail a query to SQL Server and have it respond with a result set via e-mail. This tool can potentially save you a lot of time and effort with reporting when used properly. We’ll start this chapter with a discussion of the basics of automation. 2627ch17.qxd 8/22/00 11:00 AM Page 624 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 625 Automation Basics Nearly any administrative task you can think of can be automated through SQL Server. True, that may sound like an exaggeration, but look at the things that you can automate: • Any Transact-SQL code • Scripting languages such as VBScript or JavaScript • Operating system commands • Replication tasks (which we’ll learn about in Chapter 27) Some popular tasks to automate using this functionality are as follows: • Database backups • Index reconstruction • Database creation (for very large databases, or VLDBs) • Report generation • Web-page creation (as seen in Chapter 23) Because this functionality is so powerful, it is easy to see why you need to use SQL Server’s automation capabilities. However, before you start to use this functionality, you need to know how it works. At the very heart of SQL Server’s automation capability is the SQLServerAgent ser- vice (also referred to as the agent). In fact, automation and replication are the sole functions of that service. This service uses three subcomponents to accomplish its automation tasks: alerts, operators, and jobs. Alerts: An alert is an error message or event that occurs in SQL Server and is recorded in the Windows NT Application log. Alerts can be sent to users via e-mail, pager, or Net Send. If an error message is not written to the Windows NT application log, an alert will never be fired off. Operators: When an alert is fired, it can be sent to a user. Users who need to receive these messages are known in SQL Server as operators. Operators are used to configure who will receive alerts and when they are available to receive these messages. Jobs: A job is a series of steps that define the task to be automated. It also defines schedules, which dictate when the task is to be executed. Such tasks can be run only one time or on a recurring basis. AUTOMATION BASICS Admninistering SQL Server PART IV 2627ch17.qxd 8/22/00 11:00 AM Page 625 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 17 • AUTOMATING ADMINISTRATION 626 These three components work together to complete the tapestry of administration. Here is an example of what may happen: 1. A user may define a job that is specified to run at a certain time. 2. When the job runs, it fails and thus writes an error message to the Windows NT event log. 3. When the SQLServerAgent service reads the Windows NT event log, the agent finds the error message that the failed job wrote and compares that to the sysalerts table in the MSDB database. 4. When the agent finds a match, it fires an alert. 5. The alert, when fired, can send an e-mail, pager message, or Net Send message to an operator. 6. The alert can also be configured to run another job, designed to repair the prob- lem that caused the alert. For any of this to function, though, the SQLServerAgent service must be properly configured. To start, the agent must be running for automation to work. There are three ways to verify this: First, you can open Enterprise Manager, expand Manage- ment, and notice the SQL Server Agent icon—if it is a red square, the service is stopped; if it is a green arrow, the service is started. You can even start the service by right-clicking the icon and selecting Start. Other methods of checking and changing the state of the service are by using the Service Manager (which can be found in the task tray of the Start bar) or by using the Services applet in the Control Panel. Not only should the agent be running, but it is best to have it log on with a domain account as opposed to a local system account, because using the local system account will not allow you to work with other SQL Servers on your network. This means that you will not be able to perform multiserver jobs (discussed later in this chapter), replication (discussed in Chapter 27), or use SQL Server’s e-mail capabilities. To make sure the agent is logging on with a domain account, you should open the Services applet in Control Panel (if you are using Windows 2000, you will find it in Administrative Tools under Programs on the Start menu), double-click the SQLServer- Agent service, and select a domain account by clicking the ellipsis box next to This Account. Once all of this is in place, you are nearly ready to begin working with automation. First, you should configure SQL Server to be able to send and receive e-mail. 2627ch17.qxd 8/22/00 11:00 AM Page 626 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 627 Configuring Mail Support The services that comprise SQL Server can send and receive e-mail. Specifically, the SQLServerAgent service works with SQLAgentMail, which the agent uses to send e-mail to administrators when an alert has fired. The MSSQLServer service works with SQL Mail, which the service uses to receive queries from users and reply with a result set; it is a lot like executing a query through Query Analyzer, only via e-mail. To configure either of these types of mail, you must have a mail account some- where. Exchange works best because both Exchange and SQL Server are parts of the Microsoft BackOffice family, but it is also possible to use an Internet e-mail account. The first step in making this work is to create a mailbox on the e-mail server to which you will be connecting. If you are using Microsoft Exchange 5.5, this is what you do: 1. Open the Exchange Administrator from the Microsoft Exchange 5.5 group under Programs on the Start menu. 2. From the File menu, select New User. 3. Select the user account that the SQL Server services use to log on as the Primary Account for the mailbox. 4. Fill in the remaining information as appropriate. If you are using Exchange 2000: 1. Open up Active Directory Users and Computers. 2. Right-click the account that the SQL Server services use to log on and select Exchange Tasks. 3. Follow the steps in the subsequent Wizard to Mail-Enable the account. Once you have a mailbox on the server, you need to install Microsoft Outlook so that the server can make a MAPI connection to the server with which it will be work- ing. The process of installing Outlook is a little outside the scope of this book, but it is a relatively easy process driven by a Wizard. After Outlook has been successfully installed, you need to create a mail profile for the SQL Server account: 1. Log on to the SQL Server as the SQL Server services account. 2. Open Outlook. 3. Outlook will come up with an error message stating that it is improperly config- ured. Click OK. CONFIGURING MAIL SUPPORT Admninistering SQL Server PART IV 2627ch17.qxd 8/22/00 11:00 AM Page 627 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. CHAPTER 17 • AUTOMATING ADMINISTRATION 628 4. A dialog box will pop up asking you which mail transports you would like to use. If you have an Exchange server, select it from the list. If not, you can select Internet Mail from the list. 5. If you selected Exchange, a dialog box will appear asking you for the names of the mailbox and e-mail server. Fill both of these in and click OK. 6. If you are using Internet Mail, you will be asked for your Internet mail account information. 7. Outlook will now configure a series of sample messages, and the Microsoft Office Assistant should appear (only if you opted to install it). Click the Start Using Outlook choice. 8. Close Outlook and log off Windows. Once Outlook is installed and you have a mail profile created, you can configure the SQLServerAgent and MSSQLServer services to start using the new profile to send and receive mail: 1. Open Enterprise Manager by selecting it from the SQL Server 2000 group under Programs on the Start menu. 2. Expand your server, then Management. 3. Right-click the SQLServerAgent and select Properties. 4. In the Properties dialog box, select the mail profile that you created while logged in as the SQL Server service account. 2627ch17.qxd 8/22/00 11:00 AM Page 628 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 629 5. Click Test to verify that the mail profile works. 6. Click OK at the bottom of the dialog box, and then click OK when asked to stop and restart the SQLServerAgent service. With a mail profile successfully configured, you can now create operators that will receive e-mail from the SQL Server. Creating Operators Several settings need to be configured for SQL Server to be able to contact you when there are problems. Such settings include whom to contact, when they are available, how those people should be contacted (via e-mail, pager, or Net Send), and of what problems should they be alerted. An operator is the object used in SQL Server to con- figure all of these settings. NOTE Net Send messages are messages that are sent from a source machine to a des- tination machine, where they pop up on a user’s screen as a dialog box over all of the open applications. Suppose, for example, that there are several people in your company who need to be alerted when there is a problem with SQL Server, each of them needing to be alerted for different problems and in various ways. Your database administrator may need to be alerted of any administration issues (for example, a failed backup or full transaction log) via e-mail and pager. Your developers may need to be alerted to pro- gramming issues (for example, deadlocks) via e-mail. Perhaps managers in your com- pany need to know of other issues, such as when a user deletes a customer from a customer database, and they want to be alerted by a Net Send message. These types of users would be handled by creating separate operators for each and configuring the desired settings. Let’s configure an operator here to demonstrate: 1.Open Enterprise Manager by selecting it from the SQL Server 2000 group under Programs on the Start menu. 2. Expand your server, then Management, then the SQLServerAgent. 3. Click the Operators icon and select New Operator from the Action menu. 4. In the Name box, enter Administrator. CREATING OPERATORS Admninistering SQL Server PART IV 2627ch17.qxd 8/22/00 11:00 AM Page 629 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... you will need to have a second instance of SQL Server running on your machine To do this, please refer to Appendix B: “Installing Microsoft SQL Server 2000.” 1 Open Enterprise Manager from the SQL Server 2000 group under Programs on the Start menu 2 Expand your server (not the \SECOND server) , then Management 3 Right-click the SQLServerAgent, and select Multiserver Administration and Make This a Master... AUTOMATING ADMINISTRATION A multiserver job is a job that is created once, on one server, and downloaded to other servers over the network, where the job is run To create multiserver jobs, you must first designate two types of servers: a master and targets The master server (or MSX) is where the multiserver jobs are created and managed The target servers poll the master server at regular intervals for... jobs on the server 6 Click OK when you have made the necessary changes It’s not hard to see the value of creating local jobs on SQL Server, but there is more Multiserver jobs are designed to make automation easier across multiple servers Creating Multiserver Jobs A growing number of companies today have multiple database servers Each of these servers will require jobs; some are unique to the server, but... steps in place, you are ready to tell SQL Server when to start the job Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Admninistering SQL Server 1 In Enterprise Manager, right-click the SQL Server Agent icon under Management and select Properties 2627ch17.qxd 632 8/22/00 11:00 AM Page 632 CHAPTER 17 • AUTOMATING ADMINISTRATION To tell SQL Server when to run a job, you need... After this is complete, expand SQLServerAgent under Management and then expand Jobs Notice that you now have local and multiserver jobs available Now that you have created a master server and enlisted a target server, let’s create a job on the master that will run on the target and notify the MSXOperator (you) when it is complete: 1 Under SQLServerAgent, select Multiserver Jobs and, from the Action... force a server to poll the master if you can’t wait for the polling interval to pass and you need to be able to detect a target (which means that it no longer accepts jobs from the master) All of this is done by following these steps: 1 Right-click the SQLServerAgent in Enterprise Manager on the master server and select Manage Target Servers 2 In the Target Server dialog box, select the \SECOND server. .. In the Name box, type Create Database on Target 3 Under Source, select Target Multiple Servers and click the Change button 643 PA R T IV 4 Under Available Servers, select the \SECOND server, click the Add button (the arrow pointing right), and click OK Admninistering SQL Server 2627ch17.qxd 5 Verify that the target server is listed on the General tab and select the Steps tab 6 On the Steps tab, click... 647 PA R T Admninistering SQL Server IV 6 Click Close to return to Enterprise Manager Now that you know how to create jobs to automate tasks on SQL Server, you are ready to enhance your system even further Let’s look at the process for creating alerts, which can automatically fix errors for you Creating Alerts An alert is fired when an event (usually a problem) occurs on SQL Server; some examples might... the scripting languages have features that SQL Server does not implement For example, you cannot directly access the file structure on the hard disk using Transact -SQL (to create a new text file, for example), but you can with a scripting language Listing all of the advantages of scripting languages goes beyond the scope of this book, but to demonstrate how SQL Server schedules such tasks, let’s create... of multiserver jobs If you configured e-mail support earlier, Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 8/22/00 11:00 AM Page 641 CREATING JOBS enter your own e-mail address as the E-Mail Address and your machine name as the Net Send Address 641 PA R T IV Admninistering SQL Server 2627ch17.qxd 6 In the Select Servers to Enlist dialog, check the box next to servername\SECOND . installed, you need to create a mail profile for the SQL Server account: 1. Log on to the SQL Server as the SQL Server services account. 2. Open Outlook. 3. Outlook. Support The services that comprise SQL Server can send and receive e-mail. Specifically, the SQLServerAgent service works with SQLAgentMail, which the agent

Ngày đăng: 21/01/2014, 08:20

Mục lục

  • CONTENTS

  • Introduction

  • PART I • INTRODUCING SQL SERVER

    • 1 Introduction to SQL Server 2000

      • Tour for DBAs

      • Tour for Developers

      • Tour for Users

      • Summary

      • 2 Overview of Database Concepts

        • Databases

        • Tables

        • Views

        • Stored Procedures

        • Ownership and Security

        • Jobs, Alerts, and Operators

        • Replication

        • Application Programming Interfaces

        • Summary

        • 3 Overview of SQL Server

          • Programs Installed with SQL Server

          • Parts of a Database

          • SQL Server Storage Concepts

          • Summary

          • 4 Database Design and Normalization

            • What Is Normalization?

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan