27
Microsoft SQL 2008 Hardware Requirements Requirement 32-Bit 64-Bit Processor Pentium 3 or Higher Itanium, Opteron, Athelon or Xeon/Pentium with EM64T support Processor Speed 1Ghz or Higher 1.6GHz or Higher Memory 512MB 512MB Supported Operating Systems SQL Server 2008 is supported on 32-bit and 64-bit versions of Microsoft Windows. The 64-bit version of SQL Server can install only to a 64-bit version of Windows. The 32-bit version of SQL Server can be installed to either a 32-bit version of Windows or to a 64-bit version of Windows with Windows on Windows (WOW) enabled. The operating systems supported for all editions of SQL Server are : Windows Server 2008 Standard or higher Windows Server 2003 Standard SP2 or higher The operating systems supported for SQL Server Developer, Evaluation, and Express are: Windows XP Professional SP2 or higher Windows Vista Home Basic or higher SQL Server Express is also supported on: Windows XP Home Edition SP2 or higher Windows XP Home Reduced Media Edition Windows XP Tablet Edition SP2 or higher Windows XP Media Center 2002 SP2 or higher Windows XP Professional Reduced Media Edition Windows XP Professional Embedded Edition Feature Pack 2007 SP2 Windows XP Professional Embedded Edition for Point of Service SP2 Windows Server 2003 Small Business Server Standard Edition R2 or higher Tip: SQL Server 2008 is not supported on Windows Server 2008 Server Core. Windows Server 2008 Server Core is not supported because the .NET Framework is not supported on Server Core. SQL Server 2008 relies on .NET Framework capabilities to support FILESTREAM, SPATIAL, and DATE data types, along with several additional features.

SQL 2008 Maintaining and Implementing

  • Upload
    kensci

  • View
    60

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SQL 2008 Maintaining and Implementing

Microsoft SQL 2008 Hardware Requirements Requirement 32-Bit 64-Bit Processor Pentium 3 or Higher Itanium, Opteron, Athelon

or Xeon/Pentium with EM64T support

Processor Speed 1Ghz or Higher 1.6GHz or Higher

Memory 512MB 512MB

Supported Operating Systems SQL Server 2008 is supported on 32-bit and 64-bit versions of Microsoft Windows. The 64-bit version of SQL Server can install only to a 64-bit version of Windows. The 32-bit version of SQL Server can be installed to either a 32-bit version of Windows or to a 64-bit version of Windows with Windows on Windows (WOW) enabled. The operating systems supported for all editions of SQL Server are :

• Windows Server 2008 Standard or higher

• Windows Server 2003 Standard SP2 or higher The operating systems supported for SQL Server Developer, Evaluation, and Express are:

• Windows XP Professional SP2 or higher

• Windows Vista Home Basic or higher SQL Server Express is also supported on:

• Windows XP Home Edition SP2 or higher

• Windows XP Home Reduced Media Edition

• Windows XP Tablet Edition SP2 or higher

• Windows XP Media Center 2002 SP2 or higher

• Windows XP Professional Reduced Media Edition

• Windows XP Professional Embedded Edition Feature Pack 2007 SP2

• Windows XP Professional Embedded Edition for Point of Service SP2

• Windows Server 2003 Small Business Server Standard Edition R2 or higher

Tip: SQL Server 2008 is not supported on Windows Server 2008 Server Core. Windows Server 2008 Server Core is not supported because the .NET Framework is not supported on Server Core. SQL Server 2008 relies on .NET Framework capabilities to support FILESTREAM, SPATIAL, and DATE data types, along with several additional features.

Page 2: SQL 2008 Maintaining and Implementing

Software Requirements SQL Server 2008 requires .NET Framework 3.5. Although the installation routine installs the required versions of the .NET Framework, you need to have Windows Installer 4.5 on the computer prior to the installation of SQL Server.

IMPORTANT .NET FRAMEWORK NET Framework 2.0 includes Windows Installer 3.1, so if you have .NET Framework 2.0 already installed, you meet the minimum requirements. However, to minimize the amount of time required for installation, it is recommended that you install all versions of the .NET Framework through version 3.5 on the machine prior to installing SQL Server.

The SQL Server setup routine also requires: Microsoft Data Access Components (MDAC) 2.8 SP1 or higher Shared Memory, Named Pipes, or TCP/IP networking support Internet Explorer 6 SP1 or higher

SQL Server Editions SQL Server 2008 is available in the following editions:

• Enterprise: Designed for the largest organizations and those needing to leverage the full power of the SQL Server 2008 platform.

• Standard: Designed for small and midsized organizations that do not need all the capabilities available in SQL Server 2008 Enterprise.

• Workgroup: Suitable for small departmental projects with a limited set of features.

• Express: A freely redistributable version of SQL Server that is designed to handle the needs of embedded applications as well as the basic data storage needs for server-based applications, such as Web applications with a small number of users.

• Compact: Designed as an embedded database.

• Developer: Designed for use by developers in creating SQL Server applications. SQL Server 2008 Developer has all the features and capabilities as SQL Server 2008 Enterprise, except that it is not allowed to be used in a production environment.

• Evaluation: Designed to allow organizations to evaluate SQL Server 2008. SQL Server 2008 Evaluation has all the features and capabilities as SQL Server 2008 Enterprise, except that it is not allowed.

Page 3: SQL 2008 Maintaining and Implementing

The Developer Edition of SQL Server is designed for developers to create new SQL Server applications. The Evaluation Edition of SQL Server is designed to allow organizations to evaluate the features available in SQL Server. Both the Developer and Evaluation editions contain the same functionality as the Enterprise Edition of SQL Server; the only exception being that the Developer and Evaluation editions are not licensed to run in a production environment. For the purposes of this book, we will discuss only the editions that can be deployed into production environments: Express, Workgroup, Standard, and Enterprise.

Service Accounts All the core SQL Server components run as services. To configure each component properly, you need to create several service accounts prior to installation. You need dedicated service accounts for the following components:

• Database Engine

• SQL Server Agent The service account that is utilized for each SQL Server service not only allows SQL Server to provide data and scheduling services to applications but also defines a security boundary. The SQL Server engine requires access to many resources on a computer, such as memory, processors, disk space, and networking. However, the SQL Server service is still running within the security framework provided by Windows. SQL Server is able to access only the Windows resources for which the service account has been granted permissions.

Collation Sequences Collation sequences control how SQL Server treats character data for storage, retrieval, sorting, and comparison operations. SQL Server 2008 allows you to specify a collation sequence to support any language currently used around the world.

Authentication Modes One of the instance configuration options you need to set during installation is the authentication mode that SQL Server uses to control the types of logins allowed. You can set the authentication mode for SQL Server to either:

• Windows Only (integrated security)

• Windows and SQL Server (mixed mode)

Page 4: SQL 2008 Maintaining and Implementing

When SQL Server is configured with Windows-only authentication, you can use only Windows accounts to log in to the SQL Server instance. When SQL Server is configured in mixed mode, you can use either Windows accounts or SQL Server–created accounts to log in to the SQL Server instance.

SQL Server Instances SQL Server instances define the container for all operations you perform within SQL Server. Each instance contains its own set of databases, security credentials, configuration settings, Windows services, and other SQL Server objects. SQL Server 2008 supports the installation of up to 50 instances on SQL Server on a single machine. You can install one instance as the default instance along with up to 49 additional named instances, or you can install 50 named instances with no default. When you connect to a default instance of SQL Server, you use the name of the machine to which the instance is installed. When connecting to a named instance, you use the combination of the machine name and instance name, such as <machinename>\<instancename>. The primary reasons for installing more than one instance of SQL Server on a single machine are:

• You need instances for quality assurance testing or development.

• You need to support multiple service pack or patch levels.

• You have different groups of administrators who are allowed to access only a subset of databases within your organization.

• You need to support multiple sets of SQL Server configuration options.

SQL Server Configuration Manager Shown in Figure 1-1, SQL Server Configuration Manager is responsible for managing SQL Server services and protocols. The primary tasks that you will perform are

• Starting, stopping, pausing, and restarting a service

• Changing service accounts and service account passwords

• Managing the start-up mode of a service

• Confi guring service start-up parameters

Page 5: SQL 2008 Maintaining and Implementing

Lesson Summary

• The SQL Server engine and SQL Server Agent run as services and need to have service accounts created with the appropriate Windows permissions to be able to access needed Windows resources.

• SQL Server can be confi gured to run under either the Windows Only or the Windows

• And SQL Server authentication mode.

• The collation sequence controls how SQL Server stores and manages character-based data.

• SQL Server supports up to 50 instances installed on a single machine; however, only the Enterprise Edition has multi-instance support.

Database Mail Database Mail was added in SQL Server 2005 as a replacement to SQL Mail. The reasons for the replacement were very simple:

• Remove the dependency on Microsoft Mail Application Programming Interface (MAPI)

• Simplify configuration and management

• Provide a fast, reliable way to send mail messages On a periodic basis, a background task that is managed by SQL Server Agent executes. When the mail send process executes, all messages within the send queue that have not yet been forwarded are picked up and sent using the appropriate mail profile. You can secure access to a mail profile to restrict the user’s ability to send mail through a given profile. When a profile is created, you can configure the profile to be either a public or private profile. A public profile can be accessed by any user with the ability to send mail. A private profile can be accessed only by those users who have been granted access to the mail profile explicitly.

Sending Mail Database Mail utilizes the services of SQL Server Agent to send messages as a background process. If SQL Server Agent is not running, messages will accumulate in a queue within the Msdb database.

Page 6: SQL 2008 Maintaining and Implementing

License Structure There are three types of instances:

• Processor license: Requires a single license for each CPU

• Server Plus device client CALs: Requires a license for a computer and a CAL for each client device to connect with SQL server

• Server Plus user CALs: Requires a license for the computer and CAL for each user who will connect with the database.

Upgrading of SQL server Microsoft SQL server 2008 Upgrade Advisor is a tool you can use to prepare for upgrades to SQL Server 2008. Upgrade Advisor analyzes installed SQL Server 2000 or SQL Server 2005 components and then generates a report that identfies issues that you should address before or after upgrading to SQL Server 2008

Installation Process There are two main phases

• Component update: Checks for components such as .NET 3.5 and Windows Installer 4.5.

• SQL MSI setup file:

What is System Configuration Checker?

• SCC checks for conditions that prevents a successful Installation.

• Windows Management Instrumentation (WMI) service must be available else it will block the setup.

• Software Requirements

• Hardware Requirements

• Security Requirements

• System State Requirements

Page 7: SQL 2008 Maintaining and Implementing

Installing Components

• SQL Server Database Engine|: Core database engine, replication, search and tools for managing data

• Analysis Services: Services and tools for online analytical processing and data mining

• Reporting Services: Server and client components for generating and distributing reports

• Integration Services: Tools and components for transferring data

• Notification Services: Platform for applications that send notifications

• Management tools: Tools to access, configure, manage and administer SQL Server components.

What is SQL Management Studio? The majority of administration is done from the SQL management Studio.

• Object Explorer is a graphical pane in SQL Server Management Studio that you can use for server configuration as well as for database management and development.

• Query Editing for script-based management and development

What is Sqlcmd?

• Sqlcmd is a powerful command-line tool that can be used to manage an SQL server enterprise. It can be used interactively or with scripting techniques to automate administration.

• You can use the SQLcmd even when the SQL server hangs or otherwise unavailable.

SQL Server 2008 With Windows Powershell

• Powershell language support complex logic then Transact-SQL. This helps you to manage to build more robust scripts.

• The SQLServer cmdlets support actions such as running a sqlcmd script containing T-SQL or XQuery statements.

• THE Sqlpl utility starts a POwershell session with the SQL Server Powershell provider and cmdlets loaded and registered.

Page 8: SQL 2008 Maintaining and Implementing

Files and Filegroups SQL Server uses two different types of files:

• Data File - Data files store long term data on disks within a database.

• Transaction Log File - Transaction Log files are responsible for storing all transactions that are executed against a database.

Filegroups SQL Server provides a logical structure between the database and the data file on disk. Filegroups can contain one or more data file but the same data file cannot have more then one filegroup. SQL Server uses proportional fill algorithm to ensure that all data files within that filegroup reach the maximum defined capacity at the same time. (For Example:, if you had a data file that was 10 gigabytes (GB) and a data file that was 1GB, SQL Server writes then rows to the 10GB file for every row that is written to the 1GB file.

What are the types of files? SQL Server has three different file extensions: .mdf – The Primary file – It stores the system objects. .ndf – Secondary file – Stores user data. .ldf – Stores every change within the database. Used for recovery within database.

Filestream Data The Filestream feature allows you to associate files with a database. The files are stored in a folder on the operating system, but are linked directly into a database where the files can be backed up, restored, full-text0indexed and combined with other structured data. Filestream stores BLOB (Binary large Objects) this will enchance the performance of the database and you can set a path of you choice. The file extension for the filestream is .hdr.

Tempdb database In addition to temporary objects, SQL Server uses tempdb for worktables used in grouping/sorting operations, worktables to support cursors, the version store supporting snapshot isolation level, and overflow for table variables. You can also cause index build operations to use space in tempdb.

Page 9: SQL 2008 Maintaining and Implementing

How data is stored? Data on disk is stored using multiple files on the SQL Server drive arrays. Pages in a SQL Server data filesd are numbered sequentially, starting with zero for the first page in the data file. Each data files in a database has a unique file ID number. To uniquely identify a page in a database, both the data file ID and the page number are required. Every data file has 8 pages of 8KB each page. In SQL server, the locations of all the files in a database are recorded in the primary file of the database and in the master database. The SQL Server Database Engine uses the file location information from the master database most of the time.

How the Transaction Logs Works?

1. Data modification is sent by application 2. Data pages are located in or read into, the buffer cache and then modified. 3. Modification is record in transaction log on disk. 4. Checkpoint writes committed transactions to database.

If there is a system failure, the transaction log might be required to bring your database back to a consistent state.

Considerations for Capacity Planning It is important to estimate the maximum size of the database, indexes, transaction log and tempdb, through a predicted growth module. SQL Server automatically expands a database according to growth parameters that were defined when the database was created. If a database has already exhausted the space allocated to it, and it cannot grow automatically, Error 1105 is raised. To specify a maximum size for the file, use the MAXSIZE parameter of the ALTER DATABASE statement, or use the Restrict filegrowth (MB) option when you use the properties dialog box in SQL Server management Studio.

Expanding a database By Default, SQL Server automatically expands a database according to growth parameters defined when the database was created. If a database has already exhausted the space allocated to it and it cannot grow automatically, Error 1105 is raised. When you create a database and allow automatic growth, you should specify the maximum size to which each file is permitted to grow. When you expand a database, you should specify the maximum size to which the file is permitted to grow.

Page 10: SQL 2008 Maintaining and Implementing

Shrinking a database Each file within a database can be reduced to remove unused pages. Both data and transaction log files can be reduced or shrunk. Files are always shrunk from the end.

What is a schema? A schema is a collection of database objects that are owned by a single user and form a single namespace. A name space is a set of objects that cannot hace duplicate names.

Configuration Servers Configuration servers are used to store policies that can then be deployed to other SQL Servers. All configuration servers and subordinate servers must be registered by using windows Authentication.

Introducing Policy-Based Management Microsoft SQL Server provides a policy-based system for managing one or more instance of SQl Server. The Policy-based system provide tools for performance monitoring, troubleshooting and tuning that enable administrators to more efficiently manage their databases and SQL server instances. Policy-Based Management consists of three components:

• Policy Management

• Policy Administrators who create policies

• Explicit administration

Components of Policy-based Management Policy-Based Management allows you to define what can or cannot be done on the server. PBM is a system for managing one or more instances of Microsoft SQL Server 2008. When SQL policy administrators use PBM, they use SQL Server Management Studio to create policies to manage entities on the server, such as the instance of SQL Server, database or other SQL Server objects. Targets: Entitles that are managed by policy-Based Management. Policies: A condition and the expected behavior. Conditions: A Boolean expression that specifies a set of allowed states. Facets: A set of properties that model behavior or characteristics.

Page 11: SQL 2008 Maintaining and Implementing

Implementing Policy-Based Management Policies are created and managed with the Management Studio The process includes the following steps:

• Select a Management facet that contains the properties to be configured

• Define a condition that specifies the management facet

• Define a policy that contains the condition, additional conditions that the filter for the target sets, and the evaluation mode.

• Check whether an instance of SQL Server is in compliance with the Policy.

Further Reading: http://www.simple-talk.com/sql/database-administration/policy-based-

management/

• Policies are created from a predefined set of facets and they are created and managed by using the SQL Server Management Studio.

• Each Facet contains a subgroup of SQL Server 2008 configuration settings and other events that you can control.

• The execution modes that apply to a policy are determined by the characteristics of the PBM facet that is used by the policy.

• For failed policies, Object Explorer indicates a critical health warning as a red icon next to the target and the nodes that are higher in the object Explorer tree.

• When PBM policies are executed in one of the three automated evaluation modes, if a policy violation occurs, a message is written to the event log.

• To be notified when this message is written to the event log, you can create an alert to detect the message and perform an action.

Disaster Recovery Different Types of backup Full Backups – A full backup of database includes the data files and part of the transaction log. Differential backups – A differential base is a full backup of read/write data. A differential backup only the data that has been changed since the differential base.

Page 12: SQL 2008 Maintaining and Implementing

Partial Backup – A partial backup is similar to a full backup, but a partial backup does not contain all of the filegroups. Transaction log backups – Transaction log backups record any database changes. Tail-log Backups – SQL Server requires that you take a tail-log backup before you start to restore a database. File or Filegroup Backups – The Files in a database can be backed up and restored individually. Copy-only Backups – Unlike other backups, a copy-only backup does not impact the overall backup and restore procedures for the database.

What is a full Database Backup Strategy?

• A full database backup contains all the data in the database.

• If the database fails, you can restore the most recent full backup to recover the database to the same state it was in when that backup was taken.

• Your database size and how frequently the data is modified determine together the time and resources that are involved in implementing a full database backup strategy.

What is a database and transaction log backup strategy?

• When you implement a database and transaction log backup strategy, you can restore a database from the most recent full database backup and then apply all of the transaction log backups that were created since the last full database.

• A tail-log backup prevents work loss and keeps the log chain intact. When you are recovering a database to the point of a failure, the tail-log backup is the last backup of interest in the recovery plan.

Page 13: SQL 2008 Maintaining and Implementing

What is a differential backup strategy?

• A differential backup strategy involves performing regular full database backups with intervening differential backups.

• A differential base is a full backup of red/write data. A differential backup contains only data that has changed since the differential base.

• To recover the database in the event of a disaster, you must restore the most recent full database backup, followed by the most recent differential backup and then restore each transaction log since the last differential backup in order.

What is file or file group Backup Strategy? Involves backing up individual files or filegroups on a regular basis.

What are Recovery Models? SQL Server has three different types of database recovery models: Full – You can use the full recovery model when full recovery from damaged media is the highest priority.

• Everything is available.

• Transactional log files are maintained

• No work is lost due to a lost or damaged data file

• Can recover to an arbitrary point in time

• Normally no work loss exposure ( If the “tail” of the log is damaged, changed since the most recent log backup must be redone)

When do you use a full recovery model?

• You must be able to recover all the data

• If the database contains multiple filegroups, and you want a piecemeal restore of read/write secondary filegroups

• You must be able to recover to the point of failure

• You are willing to incur the administrative costs of transaction log backups

• You are willing to incur a performance “hit”

Page 14: SQL 2008 Maintaining and Implementing

Bulk-Logged – Similar to the full recovery mode, the bulk-logged recovery model uses both database and log backups to re-create a database. You don’t have a specific point in time to backup.

• Logs are maintained, but not individual transactions

• Supports high-performance bulk copy operations

• Reduces log space for most bulk operations

• If the log is damaged or bulk-logged operations occurred since the most recent log backup, changes since the last backup must be redone.

• Can recover to the end of any backup

• If a log backup contains any bulk-logged operations, you cannot restore to a point-in-time within that log backup; you can restore only the whole log backup

When do you use Bulk-Logged recovery model?

• You are running large-scale bulk operations, and you do not require point-in-time recovery of the database.

• You must run periodic bulk operations

• You want to conserve disk space by using minimal logging

• As soon as a set of bulk operations finishes, immediately switch back to the full recovery model.

Simple – You typically use the simple recovery model for small databases or databases in which data changes infrequently

• No log backups

• Automatically reclaims log space to keep space requirements small, essentially eliminating the need to manage the transaction log space.

• Changes since the most recent backup are unprotected. In the event of a disaster, those changes must be redone.

• Can recover only to the end of a backup. When to use simple recovery model?

• Point of failure recovery is unnecessary

• You are willing to lose all the updates between a failure and the previous backup or differential backup

Data Usage Patterns

• Frequently changing data?

• Are some tables modified more frequently?

• Critical Production periods? (When is then peak of data increase?)

• Risky updates or erros?

Page 15: SQL 2008 Maintaining and Implementing

Best Practices

• Carefully consider your business needs

• Test you backups

• Offsite storage

• Secure location

System databases what to backup?

• Master – backup after creating or modifying any database

• Model – determines default for all new databases

• Msdb – Use the full recovery mode

• Tempdb – cannot be backed up since a new tempdb is created everytime the SQL server is stopped/started.

Different types of system databases Master – Tracks any changes such as modifications to logon accounts, creating new databases and what databases are available in you instance. Model – Is a template database. For example: you need to have the same users to access multiple databases. Template database will make work easier and faster by creating a template with those user accounts so that you don’t have to set the users for every database. Tempdb – temporary database. Is unique among other databases. Every time SQL server is restarted a new tempdb is created. Msdb – is used by SQL server agents service. It is used to create jobs that can automate administrative tasks such as notifications just in case a job has failed. ReportServer/ ReportServerDB – They are automatically created when you install the reporting services. Distribution – this database is used for replication purposes.

Page 16: SQL 2008 Maintaining and Implementing

SQL Server Security Landscape

• Limiting access to the database and within the database

• Network access security

• Creating secure database applications (CLR Integration)

• Place servers in a secure location

Managing User Access

• Managing logins and users

• Server and database roles

• Database permissions

• Schemas Manage users directly or through applications and through SQL Server services. There are two different types of logins which you have to setup. The security folder lets you configure users that can have access to the server (Server- Level Roles), whilst the database security folder you can configure users that needs to have access to that particular database (Database-level roles) Schemas Schemas are about grouping objects together to be managed more effectively. Schemas are groups for objects. (For example: You want to group Sales tables, Hr tables and put permissions on that schema so that only the employees in that particular department can access those tables). A schema is also the container that owns all object in a database. Creating schema syntax: CREATE SCHEMA <schema name> AUTHORIZATION <owner name> Best practices configuring SQL server 2008

1. Use the NTFS file system 2. Use RAID fro critical data files 3. Disable unnecessary protocols 4. Run SQL Server services with the lowest possible permissions 5. Associate SQL Server services with low privileged. 6. Rename and assign a strong password to rhe sa account 7. If possible change the sa username to another name 8. Only turn on what you need 9. Use Windows authentication

Page 17: SQL 2008 Maintaining and Implementing

SQL Profiler/ SQL Trace (T-SQL)

• The relationship to give a GUI to the same type of results that the SQL trace can produce with T-SQL.

• Shows how SQL Server resolves queries internally

• Allows administrators to see Transact-SQl statements and how the server access the return result sets.

• You can:

• Create a trace that is based on a reusable template

• Watch the trace results as the trace runs

• Store the trace results in a table or file

• Replay your trace results When to use SQL Profiler and SQL Trace?

• Trend Analysis

• Replaying Captured events

• Ad hoc monitoring

• Graphical interface

• Using within custom application

Windows System Monitor

• It tracks resource usage across the board. It is not a specific to SQL.

• a.k.a Permofrance Monitor.

• Collects counts and rates rather than data about the events (e.g. CPU activity,)

• You can set threshold on specific counters to generate alerts to notify the operators

• SQL Server Profiler monitors Database Engine events.

• System Monitor monitors resource usage associated with server processes

When to use Windows Systems Monitor?

• Trend analysis

• Generating alerts

• Graphical Interface

Page 18: SQL 2008 Maintaining and Implementing

Activity Monitor

• Overview section: graphical display section

• Processes section: shows user activities

• Resource waits – wait state information

• Data file I/O section: Gives data and log files I/O information

• Recent Expensive queries – most expensive queries When to use activity monitor?

• Ad hoc monitor

• Graphical interface

Transact – SQL

• Sp_who – it gives you about the current SQL users and the processes they are running and the statements they are currently running

• Sp_who2 – gives you more detailed information then sp_who

• Sp_lock – what objects are locked

• Sp_spaceused – display of the current amount

• sp_monitor – will display statistics such as CPU usage, I/O usage and the amount of I/O used since the last time you ran sp_monitor.

• Sp_help – gives you the list of stored procedures When to use Transact-SQL?

• Ad hoc monitoring

• Using within custom application.

Windows Logs

• SQL services stop/start

• Audits (success/failures)

• Errors When to use Windows logs?

• Ad hoc monitoring

• Graphical interface

• Default Trace

Page 19: SQL 2008 Maintaining and Implementing

The SQL Server “Black Box”

• Exec sp_configure ‘default trace enabled’, 0 � to turn the feature off

• Reconfingure with override

• Exec sp_configure ‘show advanced options’, 1 � to turn the feature on

• Reconfingure with override

Dynamic management Views

• Under System views folder

• Sys.dm_... � (dynamic management views )

• Views to underlying data

• Provides stable interface

SQL Server Agent

• A Windows Service

• Executes scheduled administrative tasks

• Scedules, events or user events

• Everything is saved in msdb database Configuration of SQL Server Agent

• Create an account

• Needs to be sysadmin role on SQL server

• In windows:

• Domain account

• Adjust memory quotas for a process

• Act as part of the operating system

• Bypass traverse checking

• Log on as a batch job

• Log on as service

• Replace a process level token

Page 20: SQL 2008 Maintaining and Implementing

Roles in SQl Server Agent SQLAgentUser Role

• Is the least privileged

• Have permission on only local jobs and jobs schedules that they own

• Cannot use multiserver jobs (master and target server jobs)

• They cannot change job ownership

• Can view a list of available proxies only in the Job Step Properties

• Can view only the jobs node in SQL Server Management Studio Object Explorer is visible to members of the SQLAgentUserRoles

SQLAgentReaderRole

• Inclues SQLAgentUserRole

• Can view the list of available multiserver jobs, their properties and history

• Can view all jobs and job schedules and their properties

• Cannot change the job ownership

• Can view only the jobs node in SQL Server Management Studio Object Explorer is visible to members of the SQLAgentReaderRole

SQLAgentOperatorRole

• The most privileged role

• It includes all the permissions of SQLAgentUserRole and SQLAgentReaderRole

• Can view properties for operators and proxies

• Enumerate available proxies and alerts of the server

• Can have additional permissions on local jobs and schedules

• They can execute, stop or start local jobs

• They can delete job history for any local jobs on the server.

• Can enable and disable local jobs and schedules on the server

• Cannot change job ownership to gain access to jobs that they do not already own.

The roles are used to view and execute jobs they own and create job steps that run as an existing proxy account Server Role: Sysadmin – Create, modify and delete proxy accounts. Create jobs steps that do not specify a proxy

Page 21: SQL 2008 Maintaining and Implementing

Subsystem

• A set of functionality available to SQL Server Agent

• A predefined object that represents a set of functionality available to a SQL Server Agent proxy

Proxy

• Job steps that execute T-SQL do not use SQL Server Agent proxies/

• An SQL Server Agent proxy defines the security context for a job step

• A proxy provides SQL Server Agent with access to the security credentials for a Microsoft Windows user.

High Availability SQL Server failover clustering

• Built on top of Windows Server failover clusters

• Supports an entire instance of SQL Server

• One or more nodes or servers and two or more shared disks

• Appear as a single SQL Server instance

• An application can connect by referencing the failover cluster instance name

• A non-disk hardware failure, operating system failure, or planned operating system upgrade

• A failover cluster does not protect against disk failure

• SQL Enterprise, SQL Server Developer (not for production purposes. It is only used for testing) and SQL Server Standard

SQL Server Database Mirroring

• A Software Solution

• Almost instantaneous failover

• A single standby database (Not ideal if the environment is huge)

• Principle server and mirror server so that when the principle server fails the system will failover on the mirror server

• Limited access, mainly used for mirroring

• You have to update every update constantly on the mirrored server

Page 22: SQL 2008 Maintaining and Implementing

SQL Server Log Shipping

• One or more warm standby databases

• How often does it happen? Updates secondary database at set intervals from log backup and restores

• You must manually applying any un-restored log backs before a failover can occur

• Logs are backed up to an alternative location and then used to restore to other instances.

• Log shipping can support multiple standby databases

• Log shipping allows you to automatically send transaction log backups from a primary database on a primary server instance to one or more secondary databases on separate secondary server instances. The transaction log backups are applied to each of the secondary databases individually. An optional third server instance, known as the monitor server, records the history and status of backup and restore operations and, optionally, raises alerts if these operations fail to occur as scheduled.

SQL Server Replication

• Replication uses a publish-subscribe model. This lets a primary server, referred to as the Publisher, distribute data to one or more secondary servers, or Subscribers.

• Publisher-subscriber model

• Can distribute data to one or more secondary server or subscribers

• Support data filtering and partitioning

• Replication enables real-time availability and scalability across these servers.

• Subscribers are online and available

• Replication is supported in all editions of SQL Server. Replication publishing is not available with SQL Server Express or SQL Server Compact 3.5 SP2.

Performing Data Management Tasks Importing and Exporting to:-

• SQL Server

• Flat files

• Microsoft Office Access

• Microsoft Office Excel

Page 23: SQL 2008 Maintaining and Implementing

Permissions for importing and exporting

• Ensure you have access to connect to the source and destination

• Ensure that you have access to read from the source database and write to the destination

• Ensure that you have sufficient to create a new database and table or file

• Basic permissions that you need are on CREATE DATABASE or CREATE TABLE

• Ensure you have write permissions to the msdb database or to the files system

Maintaining Indexes Index types

• Clustered – you put the data in order (You order the data for example by surname)

• Non-Clustered – the data that you input is not ordered

• Partitioned indexes – you break your data in partitions (E.g. you have records and you order the data by month. Partitioning indexes lets you organize that data by month)

• You can disabling and enabling indexes (ideally indexes are disabled in a clustered environment)

• Rebuilding indexes - Used when you want to enable again the indexes after some data has been inputted and you want to index all that data.

• Full text indexing - supports word searches in character string data

• Spatial – supports searching against the geometry data type

• XML – Supports searching against the XML data type Clustered vs Nonclustered Clustered

• Sort and store the data rows in the table or view

• There can be only one clustered index per table

• The only time the data rows in a table are stored in sorted order is when the table contains a clustered index

• The table is called a clustered table Non-clustered

• Have a structure separate from the data rows

• Contain the key values and pointers to the data row that contains the key value

Page 24: SQL 2008 Maintaining and Implementing

Full-text indexing

• Always on in SQL Server 2008 databases

• Auto on/Off at the table level

Replication What is replication? It is about distributing data and objects to other servers/sites You will have multiple copies of the database - Data redundancy Users will have faster access since servers will be distributed across the world or town which will be closer to the offices. Transactional Replication You have one central server which will distribute the database to other servers and those servers will eventually update only the central server. This is known as two-way replication. When the central server will be the on server that will be distributing the database to remote sites it is called transactional replication (one way replication). Incremental type depending on the environment Merge Replication

• Distributed applications where changes happen on both ends frequently.

• Server to client replication - When users make use of POS systems and mobile devices. It is when the database server is distributing data directly to the clients.

• It is a two way replication Snapshot Replication

• Snapshot is included automatically in the Merge replication and in the transactional replication.

• Provides your initial data since you need a snapshot when you will start a database in a new branch/office

• It is like you take a point in time recovery and you send it out to other servers.

Page 25: SQL 2008 Maintaining and Implementing

The SQL Server Roles when it comes to replication

• Publisher – The one that is actually creating the data. The one that is the owner of the data. The one that sends data out. The source of the data.

• Distributer – Manages the data that is being sent out

• Subscriber – the person that is receiving the data that is being sent out by the publisher

How data is replicated? The publisher will create a publication and is sent to the distributor. The distributor then pushes that publication to the subscribers. The Pieces that makes the replication model Article – the smallest unit in your database which consists of data and objects A group of articles form a publication which then eventually be sent out. The subscribers will eventually get a particular publication depending on the subscription. Subscribers are can subscribe to multiple subscriptions. What goes in the article?

• Tables

• Views

• Jobs

• Stored procedures

• Plus other objects The players that make this happen

• SQL Server Agent – The boss because it is the one driving process that makes the process automatically

• Snapshot Agent – It is used in all forms of replication. Is the starting point of all replications

• Log reader agent – used in transactional replication and extracts and sends transactions from the publisher’s log

• Distributation agent is the dispatcher is to off load the tasks from the publisher. Manages how the publications are sent to subscribers

• Merge Agent – Used for merge replication All agents have their own system accounts for security reasons

Page 26: SQL 2008 Maintaining and Implementing

Publication

• A collection of articles from one database

• Management mechanism (To manage better who and what can be accessed)

Subscription

• A request for a copy of the publicvation

• Defines what publications will be transfered

• Where and when and how often the publication will be sent out.

• Two flavors: push or pull

SQL Server 2008 Data Compression ROW Compression – Stores fixed length data in variable length storage format PAGE Compression – Minimizing the data redundancy. It removes redundant data and points you to that records so that there won’t be any redundancy in the database. Looks for unused space. What can be compressed?

• Tables

• Index

• Partition

• Data Partitions

• Use a partition function to segregate table data along arbitrary boundaries

• Convert a non-partitioned table to a partitioned table

• Convert a partitioned table to a non-partitioned table

• Transfer data by adding, moving or removing partitions Row compression T-SQL CREAT TABLE T1(c1 int,c2 nvarchar(50)) WITH (DATA_COMPRESSION = ROW); Page Compression CREATE TABLE T2(c1 int, c2 Nvarchar(50)) WITH (DATA_COMPRESSION = PAGE

Page 27: SQL 2008 Maintaining and Implementing

Compressing backups

• Windows I/O performance counters

• Device Throughput Bytes/sec counter - SQlServer: Backup Device Object

• Backup/Restore Throughput/sec counter - SQLServer: Database object

• Use Resource Governor How to know the compressed ratio? SELECT backup_size/compressed_backup_size FROM msdb..backupset; Factors:

• Data type - depends the data type will result into a better compression

• The consistency of the data among rows on a page (Data redundancy help compression)

• Encrypted data compress significantly less

• Is the database compressed?