Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Author
Message
Posted Wednesday, June 26, 2013 8:18 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 2:25 PM
Points: 72, Visits: 333
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
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, September 25, 2014 10:33 AM
Points: 1,797, Visits: 489
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.

http://sqlserver365.blogspot.co.uk/2012/11/unused-indexes.html

Cheers

Chris


------------------------
I am the master of my fate:
I am the captain of my soul.
------------------------
Blog: http://sqlserver365.blogspot.co.uk/
Twitter: @ckwmcgowan
------------------------

Post #1483687
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse