1. Trang chủ
  2. » Công Nghệ Thông Tin

SQL Server Tacklebox- P7 pdf

5 267 0

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

THÔNG TIN TÀI LIỆU

Nội dung

1 – Eating SQL Server installations for breakfast 30 + 'Server Name: ' + ISNULL(@serverName, 'No Server Given') + CHAR(13) + 'Login Name: ' + ISNULL(@loginName, 'No LOGIN Given') + CHAR(13) + 'User Name: ' + ISNULL(@username, 'No User Name Given') + CHAR(13) + 'DB Name: ' + ISNULL(@databaseName, 'No Database Given') + CHAR(13) + 'Object Name: ' + ISNULL(@objectName, 'No Object Given') + CHAR(13) + 'Object Type: ' + ISNULL(@objectType, 'No Type Given') + CHAR(13) + ' '; EXEC msdb sp_send_dbmail @profile_name='Admin Profile', @recipients='<yourmail@yourmail.com>, @subject='DDL Alteration Trigger', @body=@emailBody GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ENABLE TRIGGER [AuditDatabaseDDL] ON ALL SERVER GO Change Model Database Recovery Option from Full to Simple This will prevent unmitigated log file growth. ALTER Database Model SET RECOVERY SIMPLE Turn configurations back off sp_configure 'xp_cmdshell', 0 reconfigure sp_configure 'Show Advanced Options', 0 Reconfigure 1 – Eating SQL Server installations for breakfast 31 End Script PRINT 'All Done Add Server to DBA Repository for further documentation' Listing 1.2: The SQL Server automated configuration script. Using the above script you will, in about 3 seconds, have configured many options that might have taken 30 minutes to do manually. Without such a script it is very easy to miss an important configuration such as setting the model database to "simple" recovery mode. This script is a mere sampling of what you can control and automate, prior to releasing the server into the wild. As we proceed through the rest of the book, I will demonstrate many more scripts that can be used to make your life easier, freeing up more of your time to write or extend your own scripts and then give them back to me so I can use them. Ha! Bon Appétit Just because your server installation is now complete, and is stepping out into the real world to be eaten alive by various applications, it is by no means out of your hands. No, now you have the task of protecting it. Every day. The first step toward that goal is to make sure you monitor, maintain and document the server during the course of its life. Documenting will be the focus of Chapter 2, where I will introduce you to the DBA Repository, a tool that incorporates the combined reporting and data migration strengths of SQL Server Reporting Services and SQL Server Integration Services. It is within the DBA Repository that you will truly come to know your servers. 32 CHAPTER 2: THE SQL SERVER LANDSCAPE I started my DBA career working for a small software development company, where I had a handful of SQL Servers to administer. As in many small companies, the term "DBA" was interpreted rather loosely. I was also, as required, a Windows server administrator, network engineer, developer, and technical support representative. I divided my day equally between these tasks and only actually spent a fifth of my professional time managing the SQL infrastructure. When I moved on to a much larger organization, I found that my first days, as a DBA managing nearly 100 SQL Servers, were daunting, to the say the least. I was astounded by the lack of documentation! Some fragmented efforts had been made to pull together information about the SQL infrastructure, but it was sparse. As a result, my first week found me manually and hastily clicking through server property windows, perusing SQL Server error logs, pouring over reams of stored procedure code, sifting through SQL Agent job failures on each server, and generally just floundering about picking up whatever tidbits of information I could. I recall feeling very tired that first weekend and, to add insult to injury, also as though I had accomplished very little. With the wonderful benefit of hindsight that I have while writing this book, I can say that what I really needed in those early weeks was a "documentation tool" that would have allowed me to automate the collection of all of the essential information about every server under my control, and have it stored in a single, central location, for reporting. Over the course of this chapter, I'll describe how I built just such a documentation tool. First, I'll describe the information that I felt I needed to have about each of the servers under my control and the scripts to retrieve this information for each server. I'll then move on to discuss the various ways of automating this data collection process over all of your servers. Finally, I'll demonstrate how I actually achieved it, using SSIS and a central DBA Repository database. NOTE The material in this chapter describing how to build a DBA Repository using SSIS and SSRS is adapted with permission from my article "Use SSRS and SSIS to Create a DBA Repository," which originally appeared in SQL Server Magazine, February 2008, copyright Penton Media, Inc. 2 – The SQL Server landscape 33 What information is required? Before I could even begin to build a documentation tool for my SQL Servers, I had to answer one very important question: what information did I need to gather in order to help me do my job better as a DBA? I am sure that many such lists have been compiled, by numerous DBAs. My list encompasses the categories of information that I saw as pertinent, and was as follows: • Server Information (Server name, SQL Server version, collation information, and so on) • Database Management (Primarily to monitor data and log file growth) • Database Backups (Have backups run successfully? Which databases are in Full recovery mode versus Simple or Bulk-Logged? Are we doing regular log backups of Full recovery databases?) • Security (Who has access to do what?) • SQL Agent Jobs (Which could include those that run your database backups). Over the following sections, I'll present a series of queries (I like that expression – a series of queries) that I used to collect the required information in each category. Server information I needed to retrieve a number of useful pieces of server information for each of my servers, such as: • The server name • The physical location of the server • The SQL Server version, level and edition • Security mode – Either Windows (Integrated) or Mixed mode • SQL Server collation. Listing 2.1 shows the script I developed to return this information (at least most of it) for a given server. SELECT CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, CONVERT(CHAR(100), SERVERPROPERTY('ProductVersion')) AS ProductVersion, CONVERT(CHAR(100), SERVERPROPERTY('ProductLevel')) AS ProductLevel, CONVERT(CHAR(100), SERVERPROPERTY('ResourceLastUpdateDateTime')) AS ResourceLastUpdateDateTime, 2 – The SQL Server landscape 34 CONVERT(CHAR(100), SERVERPROPERTY('ResourceVersion')) AS ResourceVersion, CASE WHEN SERVERPROPERTY('IsIntegratedSecurityOnly') = 1 THEN 'Integrated security' WHEN SERVERPROPERTY('IsIntegratedSecurityOnly') = 0 THEN 'Not Integrated security' END AS IsIntegratedSecurityOnly, CASE WHEN SERVERPROPERTY('EngineEdition') = 1 THEN 'Personal Edition' WHEN SERVERPROPERTY('EngineEdition') = 2 THEN 'Standard Edition' WHEN SERVERPROPERTY('EngineEdition') = 3 THEN 'Enterprise Edition' WHEN SERVERPROPERTY('EngineEdition') = 4 THEN 'Express Edition' END AS EngineEdition, CONVERT(CHAR(100), SERVERPROPERTY('InstanceName')) AS InstanceName, CONVERT(CHAR(100), SERVERPROPERTY('ComputerNamePhysicalNetBIOS')) AS ComputerNamePhysicalNetBIOS, CONVERT(CHAR(100), SERVERPROPERTY('LicenseType')) AS LicenseType, CONVERT(CHAR(100), SERVERPROPERTY('NumLicenses')) AS NumLicenses, CONVERT(CHAR(100), SERVERPROPERTY('BuildClrVersion')) AS BuildClrVersion, CONVERT(CHAR(100), SERVERPROPERTY('Collation')) AS Collation, CONVERT(CHAR(100), SERVERPROPERTY('CollationID')) AS CollationID, CONVERT(CHAR(100), SERVERPROPERTY('ComparisonStyle')) AS ComparisonStyle, CASE WHEN CONVERT(CHAR(100), SERVERPROPERTY('EditionID')) = -1253826760 THEN 'Desktop Edition' WHEN SERVERPROPERTY('EditionID') = -1592396055 THEN 'Express Edition' WHEN SERVERPROPERTY('EditionID') = -1534726760 THEN 'Standard Edition' WHEN SERVERPROPERTY('EditionID') = 1333529388 THEN 'Workgroup Edition' WHEN SERVERPROPERTY('EditionID') = 1804890536 THEN 'Enterprise Edition' WHEN SERVERPROPERTY('EditionID') = -323382091 THEN 'Personal Edition' WHEN SERVERPROPERTY('EditionID') = -2117995310 THEN 'Developer Edition' WHEN SERVERPROPERTY('EditionID') = 610778273 THEN 'Enterprise Evaluation Edition' WHEN SERVERPROPERTY('EditionID') = 1044790755 THEN 'Windows Embedded SQL' . strengths of SQL Server Reporting Services and SQL Server Integration Services. It is within the DBA Repository that you will truly come to know your servers. 32 CHAPTER 2: THE SQL SERVER LANDSCAPE . Server information I needed to retrieve a number of useful pieces of server information for each of my servers, such as: • The server name • The physical location of the server • The SQL. 1 – Eating SQL Server installations for breakfast 30 + &apos ;Server Name: ' + ISNULL(@serverName, 'No Server Given') + CHAR(13) + 'Login

Ngày đăng: 04/07/2014, 23:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

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

TÀI LIỆU LIÊN QUAN