Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Alerts being activated prematurely because of restore threshold.

Posted on 2008-06-17
4
Medium Priority
?
1,609 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21802140
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
ID: 21802227
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 2000 total points
ID: 21802271
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
ID: 31467924
Good suggestion chapmandew!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

715 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