June 26, 2013 at 8:18 am
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.
August 13, 2013 at 6:15 am
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
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply