Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

A job or alert to check for a witness Expand / Collapse
Posted Wednesday, June 26, 2013 8:18 AM


Group: General Forum Members
Last Login: Friday, December 2, 2016 1:08 PM
Points: 109, Visits: 510
We have alerts for when a witness has lost it's connection. However there have been times when we are reviewing our mirror setup and find some databases with disconnected witnesses. I have come up with this query to check if there are any db's that have a disconnected witness.

SELECT DB_NAME(database_id)
FROM sys.database_mirroring
WHERE mirroring_guid is not null and mirroring_witness_state != '1'

If it returns any amount of rows then their are databases without witnesses that should have one. My boss wanted me to have something that could check if a witness has been disconnected for a certain amount of time, but I don't see any date fields in the mirroring tables.

So I just want to run this code every few hours and if it does return any amount of rows then I want it to send an email alert, otherwise if it returns nothing, do nothing. I was thinking about using an IF statement that would send an email if any rows where returned with the sp_dbmail but that feature isn't on by default and I don't want to go turning on advanced features on all our servers. Appreciate any tips, thanks.
Post #1467692
Posted Tuesday, August 13, 2013 6:15 AM


Group: General Forum Members
Last Login: Friday, July 24, 2015 7:19 AM
Points: 1,797, Visits: 524
I can't think of a reason why you wouldn't want to make use of database mail. I enable database mail on all the servers in our estate as part of the initial setup so I can send a number of reports and alerts for various events. Enabling and configuring database mail is not service impacting as no service restart is required so is entirely safe to do in production.

Your ideal of using an IF statement and sp_send_dbmail is exactly how I achieve this combined with a SQL Agent job to run on schedule. I have several posts on my blog that do this the one below is for unused indexes, feel free to amend the script to suit.



I am the master of my fate:
I am the captain of my soul.
Twitter: @ckwmcgowan

Post #1483687
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse