Clock, server and a task list, representing Windows Task Scheduler jobs affecting SQL Server

Review Windows Task Scheduler: Hidden Jobs Behind Periodic SQL Server Slowdowns

How scheduled tasks on a database server cause slowdowns at the same time every day, how to list them with PowerShell, and how to move database work into SQL Server Agent.

January 12, 2022

A slowdown that lasts a few minutes at the same time every day, with no explanation on the SQL Server side, is often the trace of another job running on the server itself. Tasks in Windows Task Scheduler (file copy scripts, old backup tools, antivirus scans, disk maintenance, a reporting program someone set up once and forgot) share the same CPU, memory and disk as SQL Server. Because they don’t show up in SQL Server’s own tools, they’re usually the last thing anyone thinks of.

This article shows how to list scheduled tasks on a database server, how to correlate them with performance drops and how to sort them out.

SQL Server Performance Consulting

Unexplained slowdowns at certain times?

Aryasoft reviews SQL Server together with the server it runs on, and finds the source of periodic slowdowns.

Get Support

Symptoms

  • A slowdown that recurs at the same time every day or every week.
  • No heavy query or Agent job running in SQL Server at that time.
  • Disk latency or CPU usage rises at that time, but SQL Server’s share doesn’t.
  • PAGEIOLATCH or WRITELOG waits rise in certain periods.

Listing Scheduled Tasks

Windows’ own maintenance tasks live under the \Microsoft\ folder. The ones to look at are the tasks added later:

# Enabled non-Microsoft tasks with their last and next run times
Get-ScheduledTask |
    Where-Object { $_.State -ne 'Disabled' -and $_.TaskPath -notlike '\Microsoft\*' } |
    ForEach-Object {
        $info = Get-ScheduledTaskInfo -TaskName $_.TaskName -TaskPath $_.TaskPath
        [pscustomobject]@{
            Task    = $_.TaskPath + $_.TaskName
            RunAs   = $_.Principal.UserId
            Command = ($_.Actions | ForEach-Object { $_.Execute + ' ' + $_.Arguments }) -join '; '
            LastRun = $info.LastRunTime
            NextRun = $info.NextRunTime
        }
    } | Sort-Object NextRun | Format-Table -AutoSize

Compare the tasks’ run times with the times the slowdown occurs. Which account a task runs as (RunAs) matters too: a task of unknown ownership running as a local or domain administrator is also a security risk.

Common Culprits

  • File-level backups and copies: scripts that copy SQL Server data and log files or the backup folder. Copying files SQL Server holds open both creates load and doesn’t produce a consistent backup.
  • Antivirus scans: if SQL Server files and folders aren’t in the exclusion list, a full scan touches the data files too.
  • Disk defragmentation and maintenance: can create unnecessary I/O on SAN or virtual disks; review it with the storage team.
  • Old reporting and integration scripts: programs that query the database through sqlcmd or PowerShell that nobody uses any more.
  • Update and inventory tools: scan and update tasks set to run during business hours.

Warning

Backing up database files (mdf, ndf, ldf) by copying them doesn’t produce a consistent backup; restoring from files copied while SQL Server was running is often impossible. Database backups should always be taken with the BACKUP command or with a backup solution integrated with SQL Server.

What to Do

  1. Identify the owner and purpose of every task; disable tasks with no owner and no known purpose.
  2. Move database-related work into SQL Server Agent, so its history, notifications and schedules are managed in one place. See our SQL Server Agent guide.
  3. Move the tasks that must stay to times that don’t collide with SQL Server’s maintenance windows.
  4. Define antivirus exclusions for SQL Server.
  5. Add the task list to the server documentation and review it regularly in health checks.

Tip

When investigating slowdowns that recur at certain times, record SQL Server’s wait statistics and disk latency in a table periodically. A baseline showing what changed at which hour reveals within a few days whether the problem comes from inside SQL Server or outside it.

Checklist

  • All non-Microsoft scheduled tasks are listed.
  • Every task’s owner, purpose and run-as account are known.
  • Database work has been moved to Agent.
  • Remaining tasks don’t collide with maintenance windows.
  • Databases aren’t backed up by copying files.
Yes. Scheduled tasks share the same CPU, memory and disk; they’re a common cause of slowdowns that recur at certain times.
With Get-ScheduledTask and Get-ScheduledTaskInfo in PowerShell; focus on enabled tasks outside the \Microsoft\ folder.
In SQL Server Agent. Agent provides history, notifications and error handling in one place.
No. Copying the files of a running SQL Server doesn’t produce a consistent backup; use the BACKUP command or a backup solution integrated with SQL Server.

SQL Server Performance Consulting

See the whole server

Aryasoft’s senior DBA team reviews SQL Server together with the server it runs on, and finds and fixes periodic slowdowns caused by scheduled tasks, antivirus and other software.

4.7/5