Sunday , December 22 2024

SQL Server Database Mail History Cleanup and Prevent msdb Database From Growing

If you are using SQL Server Database Mail, your msdb database can grow undesirably. We can use the msdb.dbo.sysmail_delete_mailitems_sp procedure to clear Database Mail History.

Query Database Mail History

We can see the database mail history with the help of the script below.

Database Mail History Cleanup

There are two procedure to cleanup database mail history.

  • sysmail_delete_mailitems_sp
  • sysmail_delete_log_sp

sysmail_delete_mailitems_sp

You can delete database mail messages by using this system stored procedure.

Delete All Mail Messages

Delete Mail Messages Before a Certain Date

Delete Mail Messages With a Certains Status

You can delete database mail logs by using this system stored procedure.

Delete All Mail Logs

Delete Mail Logs Before a Certain Date

Delete Mail Logs With a Certains Event Type

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *