Friday, March 20, 2009

HOW TO: Setup Cluster Failover Alert Email

To be creative, I will try to model my posts into the below format, dragging my lazy bum to finally come back and post.

Why
It is strange a few years as DBA I have not yet seen a de-facto Cluster Alert solution. One can monitor event logs, SQL error logs, but there is no wizard in SQL/Windows Cluster to setup alerts for failover. With help from Google, I used this solution to send me email when a cluster fails over (i.e. SQL Server Agent will fail over too and cause the job to run).

To my surprise, not that it is something I want to happen, it worked and sent me an email Tuesday
I am certain there is a better way, someone please let me know.

Who
DBAs who want to get notified when cluster failed over

How
Prerequisites (I will post on this tomorrow)
- Database Mail profile & account configured
- SQL Server Agent operator created

The job sends an Email to the specified Operator when it runs
JOB RUN: 'Cluster Alert' was run on 3/17/2009 at 4:06:40 PM

DURATION: 0 hours, 0 minutes, 0 seconds
STATUS: Succeeded
MESSAGES: The job succeeded. The Job was invoked by Start Sequence 0. The last step to run was step 1 (Cluster).
When
The job is scheduled to run WHEN SQL Server Agent Starts, which happens when the cluster service fails over

Where
SQL Server 2005/2008

What


USE [msdb]


GO


/****** Object:  Job [Cluster Alert]    Script Date: 03/19/2009 16:27:37 ******/

BEGIN TRANSACTION


DECLARE  @ReturnCode INT


SELECT @ReturnCode = 0


/****** Object:  JobCategory [Database Maintenance]    Script Date: 03/19/2009 16:27:37 ******/

IF NOT EXISTS (SELECT name

               FROM   msdb.dbo.syscategories

               WHERE  name = N'Database Maintenance'

                      AND category_class = 1)

  BEGIN

    EXEC @ReturnCode = msdb.dbo.Sp_add_category

      @class = N'JOB' ,

      @type = N'LOCAL' ,

      @name = N'Database Maintenance'



    IF (@@ERROR <> 0

         OR @ReturnCode <> 0)

      GOTO quitwithrollback

  END


DECLARE  @jobId BINARY(16)


EXEC @ReturnCode = msdb.dbo.Sp_add_job

  @job_name = N'Cluster Alert' ,

  @enabled = 1 ,

  @notify_level_eventlog = 0 ,

  @notify_level_email = 3 ,

  @notify_level_netsend = 0 ,

  @notify_level_page = 0 ,

  @delete_level = 0 ,

  @description = N'No description available.' ,

  @category_name = N'Database Maintenance' ,

  @owner_login_name = N'sa' ,

  @notify_email_operator_name = N'SqlDbas' ,

  @job_id = @jobId OUTPUT


IF (@@ERROR <> 0

     OR @ReturnCode <> 0)

  GOTO quitwithrollback


/****** Object:  Step [Cluster]    Script Date: 03/19/2009 16:27:37 ******/

EXEC @ReturnCode = msdb.dbo.Sp_add_jobstep

  @job_id = @jobId ,

  @step_name = N'Cluster' ,

  @step_id = 1 ,

  @cmdexec_success_code = 0 ,

  @on_success_action = 1 ,

  @on_success_step_id = 0 ,

  @on_fail_action = 2 ,

  @on_fail_step_id = 0 ,

  @retry_attempts = 0 ,

  @retry_interval = 0 ,

  @os_run_priority = 0 ,

  @subsystem = N'TSQL' ,

  @command = N'print ''cluster''' ,

  @database_name = N'master' ,

  @flags = 0


IF (@@ERROR <> 0

     OR @ReturnCode <> 0)

  GOTO quitwithrollback


EXEC @ReturnCode = msdb.dbo.Sp_update_job

  @job_id = @jobId ,

  @start_step_id = 1


IF (@@ERROR <> 0

     OR @ReturnCode <> 0)

  GOTO quitwithrollback


EXEC @ReturnCode = msdb.dbo.Sp_add_jobschedule

  @job_id = @jobId ,

  @name = N'SQLAgentStart' ,

  @enabled = 1 ,

  @freq_type = 64 ,

  @freq_interval = 0 ,

  @freq_subday_type = 0 ,

  @freq_subday_interval = 0 ,

  @freq_relative_interval = 0 ,

  @freq_recurrence_factor = 0 ,

  @active_start_date = 20090309 ,

  @active_end_date = 99991231 ,

  @active_start_time = 0 ,

  @active_end_time = 235959


IF (@@ERROR <> 0

     OR @ReturnCode <> 0)

  GOTO quitwithrollback


EXEC @ReturnCode = msdb.dbo.Sp_add_jobserver

  @job_id = @jobId ,

  @server_name = N'(local)'


IF (@@ERROR <> 0

     OR @ReturnCode <> 0)

  GOTO quitwithrollback





GOTO endsave


QUITWITHROLLBACK:

IF (@@TRANCOUNT > 0)

  ROLLBACK TRANSACTION


ENDSAVE:

GO

Thursday, March 19, 2009

SQL Server Enterprise Policy Management

I came across the Enterprise Policy Management that utilized the SQL 2008 policy and serves a DBA's desire to centralize monitor/govern multiple database servers

Downloaded and set it up yesterday mostly fine, and the last obstacle was addressed today thanks to Lara's help - it really does NOT support "nested/2nd level" Central Management Server group

So far, my 2 test servers are 100% green :-)

Project Description


The Enterprise Policy Management Framework is a reporting solution on the state of the enterprise against a desired state defined in a policy. Extend Policy-Based Management to all SQL Server instances in the enterprise. Centralize and report on the policy evaluation results.

The Enterprise Policy Management Framework (EPM) is a solution to extend SQL Server 2008 Policy-Based Management to all versions of SQL Server in an enterprise, including SQL Server 2000 and SQL Server 2005. The EPM Framework will report the state of specified SQL Server instances against policies that define the defined intent, desired configuration, and deployment standards.

Monday, February 23, 2009

SSMS Tools Pack 1.5 (for SQL Management Studio 2005/2008)

Can't believe I missed it, but new version of my favourte "free" SQL Management Studio add-ins is available, SSMS Tools Pack version 1.5

New/improved features include:
  • Window Connection Coloring (a colored strip indicator that can be docked to any side of the window) - I should compare this to the SQL 2008 Central Management Server, where I set my production servers to be RED status bar for warning purpose
  • Search Table or Database Data
  • Uppercase/Lowercase keywords and Proper Case Database Object Names
  • Sending feedback directly from SSMS.
  • Import and Export options.
  • Delete Query history log files older than user settable age.  


Wednesday, February 18, 2009

FREE e-book - Mastering SQL Server Profiler

I came across this free e-book via Red Gate/SQL Server Central Database Weekly email
It is 283 pages, but looks to be a good read/tool book

Volume 2: Mastering SQL Server Profiler (10MB PDF)

I hope it's okay to list some useful contents I find (below are copied from the contents, copyright by Red Gate):
Contents 1
Getting Started with Profiler 5
The inner workings of Profiler 6
Profiler terminology 7
Getting Started with Profiler 9
Summary 21
Working with Traces and Templates 22
Understanding the Events Selection Options 22
Creating a Custom Trace from Scratch 25
Saving Traces to a SQL Server Table 35
Capturing Analysis Server Traces 37
Creating and Using Trace Templates 40
Summary 50
Profiler GUI Tips and Tricks 52
Summary 72
How to Identify Slow Running Queries 74
Creating a Trace to Identify Slow Running Queries 74
Analyzing the Poorly Performing Queries Identified by Profiler 83
Summary 94
How to Identify and Troubleshoot SQL Server Problems 95
How to Identify Deadlocks 95
How to Identify Blocking Issues 103
How to Identify Excessive Auto Stats Activity 109
How to Identify Excessive Statement Compilations 112
How to Identify Excessive Database File Growth/Shrinkage 118
How to Identify Excessive Table/Index Scans 122
How to Identify Memory Problems 126
Using Profiler to Audit Database Activity 131
Capturing Audit Events 132
Selecting Data Columns 134
Selecting Column Filters 136
Organizing Columns 137
How to Conduct an Audit Trace 138
Summary 140
Using Profiler with the Database Engine Tuning Advisor 141
Features and Benefits of Using the DTA 141 3
How to Create a Trace for Use by the DTA 142
Summary 156
Correlating Profiler with Performance Monitor 157
How to Collect Profiler Data for Correlation Analysis 157
How to Collect Performance Monitor Data for Correlation Analysis 159
How to Capture Profiler Traces and Performance Monitor Logs 170
How to Correlate SQL Server 2005 Profiler Data with Performance Monitor Data 171
How to Analyze Correlated Data 176
Summary 186
How to Capture Profiler Traces Programmatically 187
Summary 200
Profiler Best Practices 201
General Profiler Best Practices 201
Creating Traces 204
Running Traces 205
Analyzing Traces 206
Performance Monitor 207
Database Engine Tuning Advisor 208
Summary 208
Profiler Events and Data Columns Explained 209
Event Categories 209
Profiler Data Columns 274
Summary 281

Friday, February 13, 2009

SQL Server Certification Statistics

Saw this interesting statistics today (source: Greg Low) and wow!

I want to emphasize that I am also a believer in real world experiences over certification though, for myself, and for any future persons I may hire

SQL Server related stats from Microsoft:

MCDBA SQL 2000 152086


MCTS
SQL 2005 41665
SQL 2005 BI 2600

SQL 2008 Dev 336
SQL 2008 BI 134

MCITP
SQL 2005 DBA 6695
SQL 2005 Dev 2925
SQL 2005 BI 1088

SQL 2008 DBA 92
SQL 2008 BI 50

MCM
SQL 2005 18
SQL 2008 2