SQL Server Agent: The Complete DBA Guide to Architecture, Configuration, and Automation

SQL Server Agent: The Complete DBA Guide to Architecture, Configuration, and Automation | SQLYARD

SQL Server Agent: The Complete DBA Guide to Architecture, Configuration, and Automation


SQL Server 2019
SQL Server 2022
SQL Server 2025

SQL Server Agent is the automation engine built into every edition of SQL Server. It runs as a Windows service, executes scheduled jobs, fires alerts on SQL Server events, and notifies operators by email when something needs attention. Understanding how Agent is architected, configured, and secured is foundational DBA knowledge — everything from backups and index maintenance to ETL pipelines and replication depends on Agent running correctly with the right permissions.

This article covers the Agent service itself, every major configuration section, operators and alerts, schedules, job step types, subsystems, proxy accounts, the msdb tables that store all Agent state, and how to query them. For job failure investigation and proactive monitoring, see the companion article SQL Server Agent Jobs: How to Know About Failures Before the Business Does.

1

The SQL Server Agent Service

Beginner

SQL Server Agent runs as a Windows service named SQLSERVERAGENT for the default instance, or SQLAgent$InstanceName for named instances. It is a separate process from the SQL Server Database Engine (MSSQLSERVER) but the two share the same process space for communication. Agent is a sysadmin on the SQL Server instance it manages.

The service is managed through SQL Server Configuration Manager for start, stop, restart, and startup type — not through the Services MMC snap-in, which should not be used for SQL Server services. SSMS is used to manage everything inside Agent: jobs, alerts, operators, proxies, and schedules.

SQL Server Agent must be running for any scheduled job or alert to fire. If Agent is stopped, all scheduled jobs silently do not run. No errors appear in the SQL Server Error Log. No notifications are sent. Backups, index maintenance, replication agents, and SSRS subscriptions all depend on Agent. Set the Agent service startup type to Automatic in SQL Server Configuration Manager on every production instance.

Service Account Requirements

The SQL Server Agent service account must be a member of the sysadmin fixed server role in SQL Server. This is required for Agent to manage jobs, read system tables in msdb, and execute job steps on behalf of other users. The service account must also have these Windows permissions:

  • Log on as a service (SeServiceLogonRight)
  • Replace a process-level token (SeAssignPrimaryTokenPrivilege)
  • Bypass traverse checking (SeChangeNotifyPrivilege)
  • Adjust memory quotas for a process (SeIncreaseQuotaPrivilege)

When the service account is configured through Report Server Configuration Manager or SQL Server setup, these permissions are granted automatically. Do not use the Windows Administrator account or a Domain Admin account as the Agent service account — use a dedicated low-privilege domain account and let the SQL Server setup or Configuration Manager grant exactly the permissions required.

Auto-restart must not be enabled on Failover Cluster Instances. On an FCI, SQL Server Agent jobs running at the time of a failover do not resume after the failover completes. They are logged as started but show no completion or failure entry. Jobs that must not be interrupted should use retry logic at the job step level, not Agent auto-restart.
2

The msdb Database: Agent’s Persistent Store

Beginner

Everything SQL Server Agent knows — every job definition, every schedule, every operator, every alert, every proxy, every execution history record — is stored in the msdb system database. msdb is also used by Database Mail, SSRS (for subscription schedules), and Service Broker.

TableContains
dbo.sysjobsOne row per job: name, owner, enabled flag, notification settings, description
dbo.sysjobstepsOne row per step per job: step name, subsystem, command, success/failure actions, retry settings, output file path
dbo.sysjobhistoryExecution history: one row per step per run plus one summary row per job run. Default retention: 1,000 rows per job, 10,000 rows total.
dbo.sysjobschedulesLinks jobs to their schedules
dbo.sysschedulesSchedule definitions: frequency type, interval, start time, end time
dbo.sysoperatorsOperator definitions: name, email address, pager address, on-duty schedule
dbo.sysalertsAlert definitions: event type, severity, database name, response (job to execute or operator to notify)
dbo.sysproxiesProxy account definitions linked to credentials
dbo.syssubsystemsAvailable subsystems and their DLL paths
dbo.sysjobstepslogsJob step output when written to the database rather than a file
dbo.syscategoriesJob, alert, and operator categories for organization
Back up msdb regularly. Loss of msdb means loss of every job, schedule, operator, alert, and proxy definition. Include msdb in the backup strategy with the same frequency as user databases. A full msdb backup taken nightly gives a recovery point for all Agent configuration.
3

Agent Properties: Every Configuration Section Explained

Intermediate

Right-click SQL Server Agent in SSMS Object Explorer and select Properties to open the Agent Properties dialog. It has six pages. Each controls a distinct area of Agent behavior.

General

Shows the Agent service account, error log file path, and startup behavior. The error log file is separate from the SQL Server Error Log and is written to SQLAGENT.OUT in the SQL Server log directory by default. This file captures Agent service start/stop events, job scheduling decisions, and Agent-level errors that do not appear in the SQL Server Error Log. Check it when Agent behaves unexpectedly.

Advanced

Controls SQL Server event forwarding for multi-server environments, idle CPU condition definition (used by schedules that run when CPU is idle), and the shutdown time-out interval that determines how long Agent waits for running jobs to complete before stopping the service.

Alert System

Configures the mail profile Agent uses to send notifications, the fail-safe operator, and token replacement for alert-triggered job steps.

  • Mail session: select the Database Mail profile Agent uses. Must be configured after Database Mail is set up.
  • Fail-safe operator: receives notifications when the primary operator cannot be reached. Always configure a fail-safe operator on production instances.
  • Token replacement: alert tokens ($(A-DBN), $(A-SVR), $(A-ERR), $(A-SEV), $(A-MSG)) are disabled by default for security. Enable only if alert-triggered job steps need access to alert context variables, and only when write access to the Windows Event Log is restricted to trusted accounts.

Job System

Controls the maximum job history rows per job (default 1,000) and the maximum total job history rows across all jobs (default 10,000). On busy servers these defaults cause history to roll over after days. Increase to retain more history, or build a separate history archive table populated by a scheduled job that copies from sysjobhistory before it rolls over.

Connection

Sets the local host server alias Agent uses to connect to SQL Server and the connection timeout. Rarely needs changing from defaults on a standard installation.

History

Duplicates the job history limits from the Job System page. Controls the same two settings from a different UI entry point.

4

Jobs and Job Steps

Beginner

A job is a named, ordered collection of steps that Agent executes. Each step is a discrete action with its own subsystem, command, security context, success action, failure action, and retry configuration. Steps execute sequentially by default, but the success and failure actions on each step can redirect execution to any other step number, creating branching workflows.

Job PropertyWhat It Controls
OwnerThe SQL Server login that owns the job. T-SQL steps run under the owner’s security context. Job owner must have permission to execute all objects the steps reference.
CategoryOrganizational grouping used in SSMS and the Job Activity Monitor. Does not affect execution. Use categories to separate DBA maintenance jobs from application jobs.
EnabledDisabled jobs do not execute on their schedules but can still be run manually.
NotificationsPer-job notification settings: email an operator when the job succeeds, fails, or completes. Uses the Agent mail profile configured in Alert System properties.

Step Success and Failure Actions

ActionBehavior
Go to next stepContinue to the next step number regardless of outcome
Quit job reporting successStop the job and record it as succeeded
Quit job reporting failureStop the job and record it as failed
Go to step NJump to a specific step number — enables branching and error handling workflows
Always set the failure action on the last step to “Quit job reporting failure”. The default failure action on a new step is “Quit job reporting failure” which is correct. The default success action is “Quit job reporting success” which is only correct for single-step jobs. For multi-step jobs, always explicitly set the success action on intermediate steps to “Go to next step” rather than relying on defaults.
5

Job Step Types and Subsystems

Intermediate

Each job step runs through a subsystem. A subsystem is a predefined Agent object representing a type of external process. The subsystem determines what kind of command the step runs and what security context applies. SQL Server Agent enforces subsystem restrictions even when the security principal for a proxy would otherwise have permission to run the task independently.

Subsystem (Step Type)What It RunsProxy Required?
Transact-SQL Script (T-SQL)T-SQL statements against a SQL Server databaseNo. Runs under the job owner’s security context. Use EXECUTE AS to change database user context within the step.
Operating System (CmdExec)Windows executable programs and OS commands via cmd.exeYes, for non-sysadmin job owners. Runs under the Agent service account by default, which is often too broad.
PowerShellPowerShell scripts. From SQL Server 2019, add #NOSQLPS as the first line to prevent auto-loading the deprecated SQLPS module and use the SqlServer module instead.Yes, for non-sysadmin job owners.
SQL Server Integration Services PackageSSIS packages from the SSISDB catalog or file systemYes, for non-sysadmin job owners. The proxy must have access to the SSIS Package Execution subsystem.
SQL Server Analysis Services CommandXMLA commands against an Analysis Services instanceYes, for non-sysadmin job owners.
SQL Server Analysis Services QueryMDX or DMX queries against Analysis ServicesYes, for non-sysadmin job owners.
Replication Distributor, Merge, Queue Reader, Snapshot, TransactionSQL Server replication agent processesManaged by replication configuration; not manually assigned.
T-SQL steps do not support proxy accounts. This is a confirmed platform behavior. T-SQL job steps always run under the job owner’s security context (or under a specified database user via database_user_name in sp_add_jobstep). If a T-SQL step needs to access resources under a different identity, wrap it in an SSIS package or use a CmdExec step calling sqlcmd.exe.
PowerShell and the SQLPS deprecation. The SQLPS module is deprecated. From SQL Server 2019 onward, add #NOSQLPS as the first line of any PowerShell job step to prevent Agent from auto-loading SQLPS. Then explicitly import the SqlServer module: Import-Module SqlServer. This gives access to the current, maintained cmdlets rather than the deprecated SQLPS cmdlets.
6

Schedules

Beginner

A schedule defines when a job runs. Multiple jobs can share a single schedule, and a single job can have multiple schedules. Schedules are stored in msdb.dbo.sysschedules and linked to jobs through msdb.dbo.sysjobschedules.

Schedule TypeWhen the Job Runs
Start automatically when SQL Server Agent startsImmediately when the Agent service starts. Use for jobs that must run on every Agent restart (for example, clearing a processing flag table).
Start whenever the CPUs become idleWhen CPU usage drops below the idle threshold configured in Agent Advanced properties for the duration configured. Useful for resource-intensive maintenance jobs.
One timeOnce at a specific date and time. Useful for one-off maintenance tasks.
RecurringOn a repeating schedule: daily, weekly, monthly, or sub-daily (every N minutes or hours within a time window).

Shared schedules are created at the Agent level rather than inside a specific job. Multiple jobs can be assigned the same shared schedule, so changing the schedule time once propagates to all jobs using it. This is the correct approach for environments where many jobs run at the same time window (for example, all nightly maintenance jobs run at 2:00 AM using one shared schedule).

7

SQL Server Agent Fixed Database Roles

Intermediate

Users who are not members of the sysadmin fixed server role access SQL Server Agent through three fixed database roles in msdb. The roles are concentric: each higher role inherits all permissions of the lower roles.

RolePermissions
SQLAgentUserRole Least privileged. Can create and manage their own local jobs and schedules. Can view their own job history. Cannot view or manage other users’ jobs. Cannot view alerts, operators, or proxies unless explicitly granted.
SQLAgentReaderRole Inherits all SQLAgentUserRole permissions. Can additionally view all local job definitions, schedules, and job history regardless of owner. Cannot modify other users’ jobs.
SQLAgentOperatorRole Most privileged non-sysadmin role. Inherits all SQLAgentReaderRole permissions. Can additionally start, stop, and enable/disable all local jobs and schedules. Can delete job history for any job. Can view operator and proxy properties.
Only sysadmin members can create, modify, or delete proxy accounts. This is a hard permission boundary. SQLAgentOperatorRole members can view proxies and use proxies they have been granted access to, but cannot create new proxies or modify existing ones. Proxy management always requires sysadmin.
8

Proxy Accounts and Credentials

Advanced

A proxy account defines the security context for a non-T-SQL job step. When a step runs under a proxy, Agent impersonates the Windows account stored in the proxy’s credential and executes the step in that account’s security context. This allows job steps to access Windows resources (file shares, network paths, external applications) under a controlled, least-privilege account rather than the broad Agent service account.

The relationship between credentials and proxies is important to understand correctly:

  • A credential is an instance-level object (Security → Credentials in SSMS) that maps a SQL Server object to a Windows account and its password.
  • A proxy is an Agent-level object that links one credential to one or more subsystems, and controls which SQL Server logins can use it in job steps.
  • One credential can back multiple proxies — for example, one proxy for the SSIS subsystem and another for the PowerShell subsystem, both using the same Windows account.
-- Step 1: Create a credential for the proxy's Windows account
USE master;
GO

CREATE CREDENTIAL SSISProxyCredential
WITH IDENTITY = 'DOMAIN\svc_ssis_proxy',
     SECRET   = 'AccountPassword';
GO

-- Step 2: Create the proxy linked to the credential
USE msdb;
GO

EXEC dbo.sp_add_proxy
    @proxy_name       = 'SSIS Execution Proxy',
    @credential_name  = 'SSISProxyCredential',
    @enabled          = 1,
    @description      = 'Proxy for SSIS package execution job steps';
GO

-- Step 3: Grant the proxy access to the SSIS subsystem
-- Subsystem ID 11 = SSIS Package Execution
EXEC dbo.sp_grant_proxy_to_subsystem
    @proxy_name    = 'SSIS Execution Proxy',
    @subsystem_id  = 11;
GO

-- Step 4: Grant a SQL Server login the right to use the proxy in job steps
EXEC dbo.sp_grant_login_to_proxy
    @proxy_name  = 'SSIS Execution Proxy',
    @login_name  = 'DOMAIN\developer_login';
GO
The proxy account’s Windows account needs “Log on as a batch job” permission. This Windows privilege (seBatchLogonRight) must be granted to the domain account used by the proxy. Without it Agent cannot impersonate the account and the job step fails. Grant it through Local Security Policy → Local Policies → User Rights Assignment on the SQL Server host.
-- View all proxies and their associated subsystems
USE msdb;
GO

SELECT
    p.name                      AS proxy_name,
    p.enabled,
    p.description,
    c.name                      AS credential_name,
    s.subsystem_name            AS subsystem
FROM dbo.sysproxies            p
JOIN sys.credentials           c ON p.credential_id    = c.credential_id
JOIN dbo.sysproxysubsystem     ps ON p.proxy_id        = ps.proxy_id
JOIN dbo.syssubsystems         s  ON ps.subsystem_id   = s.subsystem_id
ORDER BY p.name, s.subsystem_name;
GO
9

Operators

Beginner

An operator is an alias for a person or group that receives notifications from SQL Server Agent. Operators are not security principals — they do not grant any permissions. They are contact records used by Agent’s notification system to know where to send alerts and job outcome notifications.

Operator PropertyPurpose
NameUnique name on the instance, maximum 128 characters
Email nameEmail address Agent sends notifications to via Database Mail. This is the primary notification method for modern environments.
Pager addressLegacy. Pager notification will be removed in a future SQL Server version. Do not use in new implementations.
Net send addressLegacy Windows Messenger net send. Will be removed in a future SQL Server version. Do not use in new implementations.
Pager on duty scheduleDefines which days and hours the operator is available to receive pager notifications. Not used for email — email notifications are always sent regardless of schedule.
Pager and net send notifications are deprecated. Microsoft has confirmed that pager and net send notification methods will be removed from SQL Server Agent in a future version. Use email notification via Database Mail exclusively in new implementations.

An operator can be defined as an email distribution list alias rather than an individual address, so an entire DBA team receives notifications without managing individual operator records for each team member.

-- Create an operator via T-SQL
USE msdb;
GO

EXEC dbo.sp_add_operator
    @name                         = N'DBA Team',
    @enabled                      = 1,
    @email_address                = N'dba-alerts@yourcompany.com',
    @weekday_pager_start_time     = 90000,   -- not used; set to satisfy parameter requirement
    @weekday_pager_end_time       = 180000,
    @pager_days                   = 0;
GO
10

Alerts

Intermediate

Alerts monitor SQL Server for specific events and respond automatically — by notifying an operator, executing a job, or both. There are three types of alert conditions.

Alert TypeFires WhenCommon Use
SQL Server event alertA specific error number or severity level is written to the Windows Application Event Log by SQL ServerAlert on severity 16+ errors, specific error numbers (823, 824, 825 for I/O errors), or custom application error numbers above 50000
SQL Server performance condition alertA SQL Server performance counter crosses a thresholdAlert when page life expectancy drops below a threshold, when buffer cache hit ratio falls, or when user connections exceed a limit
WMI event alertA Windows Management Instrumentation event occursLess common; used for OS-level events not captured by SQL Server error logging
Minimum recommended alert set for every production instance. At minimum, create alerts for SQL Server error severities 19 through 25 (fatal errors) and for specific error numbers 823 (I/O error), 824 (logical I/O consistency error), and 825 (read retry). These severities and errors indicate hardware problems, data corruption, or instance-threatening conditions. The SQLYARD article on SQL Server Severity Alerts covers the full setup.
-- Create a severity 25 alert (fatal error) notifying the DBA Team operator
USE msdb;
GO

EXEC dbo.sp_add_alert
    @name                = N'Severity 25 - Fatal Error',
    @message_id          = 0,
    @severity            = 25,
    @enabled             = 1,
    @delay_between_responses = 60,   -- minimum 60 seconds between repeated notifications
    @notification_message = N'A Severity 25 fatal error has occurred. Immediate investigation required.',
    @include_event_description_in = 1;   -- include the error text in the notification
GO

-- Assign the alert to the DBA Team operator via email
EXEC dbo.sp_add_notification
    @alert_name     = N'Severity 25 - Fatal Error',
    @operator_name  = N'DBA Team',
    @notification_method = 1;   -- 1 = email, 2 = pager, 4 = net send
GO
11

Configuring Database Mail for Agent Notifications

Intermediate

SQL Server Agent sends all email notifications through Database Mail. Database Mail must be configured with at least one profile and one SMTP account before Agent can send any notification. The profile name configured in Agent Alert System properties is the profile Agent uses for all notifications.

-- Configure Database Mail (run in the msdb context)
-- Step 1: Enable Database Mail
USE master;
GO
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'Database Mail XPs', 1;
RECONFIGURE;
GO

-- Step 2: Create a Database Mail account
USE msdb;
GO

EXEC dbo.sysmail_add_account_sp
    @account_name            = 'SQL Server Alerts',
    @description             = 'Account for SQL Server Agent alert notifications',
    @email_address           = 'sqlalerts@yourcompany.com',
    @display_name            = 'SQL Server Agent',
    @mailserver_name         = 'smtp.yourcompany.com',
    @port                    = 25,
    @enable_ssl              = 0;
GO

-- Step 3: Create a Database Mail profile
EXEC dbo.sysmail_add_profile_sp
    @profile_name  = 'DBA Alerts',
    @description   = 'Profile for SQL Server Agent notifications';
GO

-- Step 4: Add the account to the profile
EXEC dbo.sysmail_add_profileaccount_sp
    @profile_name   = 'DBA Alerts',
    @account_name   = 'SQL Server Alerts',
    @sequence_number = 1;
GO

-- Step 5: Configure Agent to use this profile
-- In SSMS: right-click SQL Server Agent > Properties > Alert System
-- Set Mail session to 'DBA Alerts' and restart Agent
-- Or via T-SQL (requires Agent restart to take effect):
EXEC msdb.dbo.sp_set_sqlagent_properties
    @email_save_in_sent_folder = 1;
GO
Restart SQL Server Agent after changing the mail profile setting. Changes to the Alert System mail profile in Agent Properties do not take effect until the Agent service is restarted. Schedule the restart during a low-activity window as it cancels any running jobs.
12

Querying msdb for Agent State

Intermediate
-- All jobs with owner, category, schedule count, and enabled status
USE msdb;
GO

SELECT
    j.name                          AS job_name,
    j.enabled                       AS job_enabled,
    SUSER_SNAME(j.owner_sid)        AS job_owner,
    c.name                          AS category,
    COUNT(s.schedule_id)            AS schedule_count,
    j.description
FROM dbo.sysjobs                    j
LEFT JOIN dbo.syscategories         c  ON j.category_id  = c.category_id
LEFT JOIN dbo.sysjobschedules       js ON j.job_id       = js.job_id
LEFT JOIN dbo.sysschedules          s  ON js.schedule_id = s.schedule_id
GROUP BY j.name, j.enabled, j.owner_sid, c.name, j.description
ORDER BY c.name, j.name;
GO
-- Jobs with no schedule (orphaned jobs that will never run automatically)
USE msdb;
GO

SELECT
    j.name          AS job_name,
    j.enabled,
    SUSER_SNAME(j.owner_sid) AS owner
FROM dbo.sysjobs j
WHERE NOT EXISTS (
    SELECT 1
    FROM dbo.sysjobschedules js
    WHERE js.job_id = j.job_id
)
ORDER BY j.name;
GO
-- All operators with their email addresses
USE msdb;
GO

SELECT
    name                AS operator_name,
    enabled,
    email_address,
    last_email_date,
    last_email_time
FROM dbo.sysoperators
ORDER BY name;
GO
-- All alerts with their associated operator notifications
USE msdb;
GO

SELECT
    a.name                          AS alert_name,
    a.enabled                       AS alert_enabled,
    a.severity,
    a.message_id,
    a.event_description_keyword,
    a.last_occurrence_date,
    a.last_occurrence_time,
    a.occurrence_count,
    o.name                          AS notified_operator,
    n.notification_method
FROM dbo.sysalerts                  a
LEFT JOIN dbo.sysnotifications      n ON a.id         = n.alert_id
LEFT JOIN dbo.sysoperators          o ON n.operator_id = o.id
ORDER BY a.name;
GO
13

SQL Server 2025 Agent Changes

Intermediate

SQL Server 2025 introduced one significant change to SQL Server Agent: TDS 8.0 and TLS 1.3 support. Agent now discovers the encryption level configured in SQL Server Configuration Manager (Force Strict Encryption, Force Encryption, or none) and uses the corresponding option when connecting to the SQL Server instance. T-SQL job steps connecting to the local instance use the Agent encryption settings automatically.

TDS 8.0 encryption may affect existing Agent job step connections after upgrading to SQL Server 2025. If the SQL Server 2025 instance is configured with Force Strict Encryption and Agent job steps connect to remote SQL Server instances or linked servers using older drivers, those connections may fail. Validate all job steps that connect to external SQL Server instances after upgrading to SQL Server 2025.

Beyond the encryption change, the core Agent architecture — jobs, steps, schedules, alerts, operators, proxies, subsystems, and msdb storage — is unchanged in SQL Server 2025.

The technical information in this article was verified against Microsoft documentation at the time of publication. SQL Server features, cloud service capabilities, licensing terms, and configuration requirements can change between versions and cumulative updates. Always validate implementation details against current Microsoft Learn documentation before deploying to production. References in this article link directly to the authoritative Microsoft sources.


Discover more from SQLYARD

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from SQLYARD

Subscribe now to keep reading and get access to the full archive.

Continue reading