Solved

Alerts being activated prematurely because of restore threshold.

Posted on 2008-06-17
4
1,536 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
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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
query question 12 32
AD and SQL Server 2016 2 25
SQL View / Qtry 3 8
Substring works but need to tweak it 12 8
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

809 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