SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


A job or alert to check for a witness


A job or alert to check for a witness

Author
Message
lmacdonald
lmacdonald
Old Hand
Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)

Group: General Forum Members
Points: 326 Visits: 538
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.
chris.mcgowan
chris.mcgowan
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1895 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.

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
------------------------


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search