Alerts being activated prematurely because of restore threshold.

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

awp5379Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
chapmandewConnect With a Mentor Commented:
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
 
chapmandewCommented:
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
 
awp5379Author Commented:
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
 
awp5379Author Commented:
Good suggestion chapmandew!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.