Solved

Alerts being activated prematurely because of restore threshold.

Posted on 2008-06-17
4
1,508 Views
Last Modified: 2012-08-13
I have log shipping setup between two SQL 2005 servers. The logs are backed up and restored on a 12 hour interval. An alert is setup on the restore job that if it fails to send me an email. Once in a while, I'll get an email with the message listed below, but I'll get it 16x. Each time this occurs (maybe 1-2x a month), I review the log shipping history for each job, and each completed successfully. I reviewed the restore job's properties, and the # of retries = 0.

What would cause the email to be sent 16x (each approx. 2 mins apart)?
DATE/TIME:      6/16/2008 7:36:00 PM
 

DESCRIPTION:    The log shipping secondary database Server2.Backup has restore threshold of 1440 minutes and is out of sync. No restore was performed for 1471 minutes. Restored latency is 95 minutes. Check agent log and logshipping monitor information.
 
 

COMMENT:        Log shipping Secondary Server Alert.
 

JOB RUN:        (None)

Open in new window

0
Comment
Question by:awp5379
  • 2
  • 2
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
Is it sending one for each database your shipping?

What results do you get when you run this procedure on your monitor server?

sp_help_log_shipping_monitor
0
 

Author Comment

by:awp5379
Comment Utility
2 records, one for each database that gets shipped. Database #2 is very small and never generates any threshold warnings. Database #1, is pretty large and has tons of daily activity that gets restored. The last_restored_latency was 114. It might be possible that the jobs need to be spread apart a little more (as in backup to copy to restore), but what cause the multiple warning emails?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
Comment Utility
I don't really use the built in alerts for log shipping....here is a proc I wrote that sends alerts and gives me a bit more control over what I see....just put it in a SQL Agent job (make sure you have dbmail setup) and run it whenever you want.
ALTER PROCEDURE sp_LogShippingAlerts

AS

BEGIN

	SET NOCOUNT ON
 

	DECLARE @Msg VARCHAR(MAX)

	DECLARE @dbname varchar(100), @restoretime int, @server varchar(100)

	DECLARE @EmailMessage VARCHAR(1000), @RowCount INT
 

	IF OBJECT_ID('tempdb..#ServerList') IS NOT NULL

	DROP TABLE #ServerList
 

	IF OBJECT_ID('tempdb..#Data') IS NOT NULL

	DROP TABLE #Data
 

	CREATE TABLE #ServerList

	(

		PrimaryServer VARCHAR(50),

		DRServer VARCHAR(50)

	)

	INSERT INTO #ServerList

	(PrimaryServer, DRServer)

	SELECT 'mainserver','backupserver'
 

	CREATE TABLE #Data

	(

		status INT,

		is_primary INT,

		server VARCHAR(255),

		database_name VARCHAR(255),

		time_since_last_backup INT,

		last_backup_file VARCHAR(1000),

		backup_threshold INT,

		is_backup_alert_enabled INT,

		time_since_last_copy INT,

		last_copied_file VARCHAR(1000),

		time_since_last_restore INT,

		last_restored_file VARCHAR(1000),

		last_restored_latency INT,

		restore_threshold INT,

		is_restore_alert_enabled INT

	)
 

	INSERT INTO #Data

	EXECUTE sp_help_log_shipping_monitor
 

	SELECT 

		a.server,

		PrimaryStatus = a.status,

		SecondaryStatus = b.status,

		a.database_name, 

		b.DRServer,

		a.time_since_last_backup,

		a.last_backup_file,

		a.backup_threshold,

		a.is_backup_alert_enabled,

		b.time_since_last_copy,

		b.last_copied_file,

		b.time_since_last_restore,

		b.last_restored_file,

		b.last_restored_latency,

		b.restore_threshold,

		b.is_restore_alert_enabled

	INTO 

		#Temp

	FROM

	(

		SELECT * 

		FROM #Data d

			JOIN #ServerList s ON d.server = s.Primaryserver

		WHERE is_Primary = 1

	) a

	JOIN

	(

		SELECT * 

		FROM #Data d

			JOIN #ServerList s ON d.server = s.DRServer

		WHERE is_Primary = 0

	) b ON a.database_name = b.database_name AND a.Server = b.PrimaryServer

	WHERE 

		(a.Status + b.Status) > 0
 

	SELECT @RowCount = COUNT(*) FROM #Temp
 

	IF @RowCount > 0

	BEGIN
 

		SET @EmailMessage = 'There are ' + CAST(@RowCount AS VARCHAR(5)) + ' database(s) needing attention.'
 

		SET @Msg = '<html><body><table>'

		DECLARE  CursorTemplate CURSOR 

		FAST_FORWARD FOR 	

			SELECT database_name, time_since_last_restore, server FROM #Temp
 

		OPEN CursorTemplate
 

		FETCH NEXT FROM CursorTemplate 

		INTO	@dbname, @restoretime, @server
 

		WHILE (@@FETCH_STATUS = 0)

		BEGIN

			

			SET @Msg = @Msg + '<tr><td>Database ' + @server + '.' + @dbname + ' has not been restored in ' + CAST(@restoretime AS VARCHAR(10)) + ' minutes.</td></tr>'

			FETCH NEXT FROM CursorTemplate 

			INTO	@dbname, @restoretime, @server
 

		END
 

		CLOSE CursorTemplate

		DEALLOCATE CursorTemplate
 

		SET @Msg = @Msg + '</body></html>'
 

		EXEC msdb.dbo.sp_send_dbmail
 

		@recipients=N'emailaddress',

		@body=@Msg, 

		@body_format ='HTML',

		@subject = @EmailMessage,

		@profile_name ='DatabaseMailProfile'

	END

	 

	RETURN(0)
 
 

END

Open in new window

0
 

Author Closing Comment

by:awp5379
Comment Utility
Good suggestion chapmandew!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now