Categories
Database

How to Fix SQL Server Database Email Engine High CPU Usage Issue?

Home » Database » How to Fix SQL Server Database Email Engine High CPU Usage Issue?

Problem Discription

Today, I noticed that the CPU usage of a monitored SQL Server database instance was abnormal. There was a significant discrepancy between the system’s CPU utilization (O/S CPU Utilization) and the database instance’s CPU utilization (Instance CPU Utilization). Upon logging into the server for inspection, I found that the Database Mail Engine process was consuming 20% of the CPU resources consistently.

Toubleshooting SQL Server Database Email Engine high CPU usage issue

1. I wondered if the database was sending a large number of emails. I had encountered a similar issue before, where a logic bug caused by a developer’s script update led to a rapid increase in email sending, resulting in the Database Mail Engine process consuming a large amount of CPU resources. I checked using the following script and found that at most, around 200 emails were sent within an hour, so I ruled out this possibility.

SELECT CONVERT(VARCHAR(13), send_request_date, 120)
      ,COUNT(*) 
FROM msdb.dbo.sysmail_allitems WITH(NOLOCK)
WHERE send_request_date >= CONVERT(DATETIME, '2020-01-27 00:00:00', 120)
  AND send_request_date <= CONVERT(DATETIME, '2020-03-14 00:00:00', 120)
GROUP BY CONVERT(VARCHAR(13), send_request_date, 120)
ORDER BY CONVERT(VARCHAR(13), send_request_date, 120);

2. I checked the Database Mail error logs and system error logs but did not find any abnormal situations.

3. Could it be a program bug?

The official documentation mentions that in SQL Server 2016, Database Mail can cause high CPU utilization after sending a large number of emails. However, this database instance is SQL Server 2014 (12.0.5000.0). Although I couldn’t find any related information about this bug in SQL Server 2014 in the official documentation, considering Microsoft’s tendencies, it’s very likely to be the same bug. Due to the lack of documentation, it’s possible that this bug hasn’t been discovered in the current version. Therefore, it might not have been fixed yet (I checked all the patch lists and there is no mention of this at all). Additionally, it seems that some users online have encountered similar cases.

How to fix SQL Server Database Email Engine high CPU usage issue?

If it were SQL Server 2016, applying the patch Cumulative Update 2 for SQL Server 2016 SP1 would resolve the issue. However, for SQL Server 2014, the problem can be temporarily resolved by restarting the mail service.

EXEC msdb.dbo.sysmail_stop_sp
 
EXEC msdb.dbo.sysmail_start_sp

By Jaxon Tisdale

I am Jaxon Tisdale. I will share you with my experience in Network, AWS, and databases.

Leave a Reply

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