Every Windows Server running IIS and SQL Server eventually gets the same advice: add exclusions to Microsoft Defender. The advice is correct in direction and usually wrong in execution — most shops paste a list of paths from a blog post written for a different workload, never measure the before and after, and end up with a permanent security gap they cannot justify at the next audit. This article covers what is genuinely worth excluding, how to measure whether it helped, and where the trade-off actually sits.
Why Defender costs anything at all on a database host
Defender scans on file open and on close, and it inspects process behaviour. That is cheap for a web server serving a thousand static files an hour and expensive for a system writing hundreds of small files per second. SQL Server does exactly that: data file writes, log writes, checkpoint activity, and tempdb churn all generate file-system events. IIS adds request logging and ASP.NET compilation output. Both patterns look, to a signature engine, like a program rapidly rewriting files — which is precisely the behaviour a scanner is designed to watch.
So the question is not “does Defender cost CPU” — it does — but “is the cost large enough to justify a permanent hole in your antivirus coverage”. That is a measurement question, and it has a measurable answer.
Measure before you exclude anything
Get a baseline with the current configuration. You need three numbers: total CPU time consumed by MsMpEng.exe, disk read and write volume attributable to scans, and the application’s own throughput or latency. Capture them over the same time window, at the same load, before and after any change.
# CPU time and working set of the scan engine, sampled every 5 seconds for 10 minutes
Get-Counter "\Process(MsMpEng)\% Processor Time", "\Process(MsMpEng)\Working Set - Private" `
-SampleInterval 5 -MaxSamples 120 |
Export-Counter -Path C:\perf\defender_before.blg -Force
# Which paths are generating the most scan events
Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" -MaxEvents 5000 |
Where-Object Id -in 1116,1117 |
Group-Object { $_.Properties[5].Value } | Sort-Object Count -Descending | Select-Object -First 20
# SQL Server: is IO actually a problem, or are you guessing?
SELECT DB_NAME(database_id) AS db, file_id, io_stall_read_ms, io_stall_write_ms,
num_of_reads, num_of_writes
FROM sys.dm_io_virtual_file_stats(NULL, NULL)
ORDER BY io_stall_write_ms DESC;
If MsMpEng.exe is using under 3% of a core on average and the SQL stall numbers are in the low milliseconds, exclusions are not your problem and you should stop here. Above roughly 10% sustained CPU, or with visible io_stall spikes that correlate with the Defender event log, exclusions are worth the trade-off.
What is worth excluding
| Target | Why | Risk if excluded |
|---|---|---|
| SQL data, log, and backup directories | Constant large sequential writes and reads; scanning them is pure overhead and adds latency to every checkpoint | Low for execution, moderate for malicious file storage in a backup share |
| tempdb files | Extreme write churn, transient by definition | Very low |
| IIS log directory | Append-only text files written per request | Very low |
ASP.NET temp files (Temporary ASP.NET Files) | Compiler output regenerated constantly | Very low |
w3wp.exe and sqlservr.exe process objects | Removes per-process behavioural scanning | Moderate to high — this is where real payloads run |
The pattern to notice is that path exclusions are cheap and process exclusions are not. Excluding a directory full of SQL data files removes scanning from files that are never executed. Excluding w3wp.exe removes scanning from everything your web application does, which is exactly the surface an attacker targets after a web shell lands. Take the path exclusions; think hard about the process ones.
# Path exclusions only — no process-level holes
Add-MpPreference -ExclusionPath "D:\SQL\Data","D:\SQL\Log","D:\SQL\Backup","C:\inetpub\logs\LogFiles"
Add-MpPreference -ExclusionPath "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"
Add-MpPreference -ExclusionExtension "ldf","mdf","ndf","bak","trn"
# Verify it took, and see what is actually configured
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath
Get-MpComputerStatus | Select-Object RealTimeProtectionEnabled, AntivirusEnabled, AMEngineVersion
Compensate for what you gave up
Path exclusions mean a malicious file can sit in D:\SQL\Backup undetected. That is acceptable only if something else catches it. Three controls do most of the work: restrict who can write to the excluded directories (SYSTEM and the SQL service account, nobody else), keep attack surface reduction rules enabled on the server, and ensure the weekly full scan still covers everything you excluded from real-time scanning.
- ACLs first. An excluded directory writable by
Everyoneis an incident waiting to happen. Tighten it before you add the exclusion. - Keep ASR rules on. Behaviour-based rules do not depend on file scanning and remain effective on excluded paths.
- Schedule a weekly full scan outside business hours so excluded areas still get periodic coverage.
- Document every exclusion with the reason and the date, in version control, next to the server build script.
Monitoring Defender without the CPU cost
Cloud-delivered protection and automatic sample submission improve detection but add outbound traffic and some latency on first-seen files. On a VPS with metered bandwidth, check the volume before enabling submission on every binary your build pipeline produces. For production database hosts, keep cloud protection on and submission on for detected items only; that gives you the intelligence benefit without uploading routine build artefacts.
Schedule scans rather than letting them run at random. A quick scan daily and a full scan weekly, both outside your traffic peak, is easier to reason about than the defaults Windows picks. If you are provisioning a new host and want the security baseline set correctly from the first boot, the Windows Server hosting plans here ship with a clean image you can configure before it takes production traffic.
The trade-off, stated plainly
Excluding SQL directories, tempdb, IIS logs, and ASP.NET compile output typically recovers a meaningful slice of scan CPU and reduces write latency on database hosts, at the cost of reduced real-time coverage in areas that should never contain executables. Excluding w3wp.exe or sqlservr.exe trades a larger hole for a smaller gain. Measure first, exclude paths not processes, tighten ACLs on anything you exclude, and review the list quarterly — the exclusions that made sense on last year’s workload may be pure risk this year.

