-6

I want to monitor the transaction logs of a database and send some kind of alert once a threshold is reached.

How can I do this?

James O'Gorman
  • 5,329
  • 2
  • 24
  • 28
Fhd.ashraf
  • 113
  • 1
  • 2

1 Answers1

1

The MS SQL DBA approach:

Take a look at this tutorial about how to send mail from SQL server 2008 and configure your server accordingly.

Use the DBCC SQLPERF(logspace) function to retreive the data for your transaction log size and usage and run sp_send_dbmail to send the alert to your desired mail address. Schedule using the SQL agent or via a scheduled task calling sqlcmd to run periodically.

The sysadmin approach:

Use your favorite / currently employed monitoring system to watch the file / folder size and set thresholds for alerts.

The proper approach:

Do not let your transaction log files grow excessively in the first place. Database or log backups will truncate the log upon completion, so run them regularly. Or change to the simple recovery model if you do not need point-in-time restores.

the-wabbit
  • 40,737
  • 13
  • 111
  • 174
  • Hmm... the "proper approach" could've been less snarky. Sometimes, someone leaves a transaction open and then the log doesn't clear after a log backup. So having an alert is still a good idea. – Ben Thul Jan 30 '12 at 03:52
  • @BenThul I've added it as an afterthought, as the problem of databases simply not taken care of and either not backed up (since they are deemed unimportant) or backed up through a VSS copy without truncating the logs (since this is a common and simple approach) is significantly more common than the one of large or indefinitely open transactions. – the-wabbit Jan 30 '12 at 07:31