Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

SQL Server Agent Jobs

Direct answer

SQL Server Agent schedules and runs jobs (backups, maintenance, ETL) with steps, schedules, alerts and operators.

When to use this

Use it when scheduled database jobs fail or do not run.

First 30 seconds

1. Agent running: SELECT status_desc FROM sys.dm_server_services;.

2. History: EXEC msdb.dbo.sp_help_jobhistory @job_name='<job>';.

3. Failed step message.

4. Owner/proxy permissions.

5. Notifications on failure.

Operational verification

schedule → job → steps run as owner/proxy → history

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it when scheduled database jobs fail or do not run.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Check the last run outcome and duration of critical jobs daily. Configure failure notifications to an operator.

Step 2 Checking jobs Verify boundary
EXEC msdb.dbo.sp_help_job @job_name = N'Nightly backup';
SELECT j.name, h.run_date, h.run_time, h.run_status, h.message
FROM msdb.dbo.sysjobhistory h JOIN msdb.dbo.sysjobs j ON j.job_id = h.job_id
WHERE h.step_id = 0 ORDER BY h.run_date DESC, h.run_time DESC;

The SQL Server Agent service must be running (not available in Express). Configure Database Mail and operators for failure notifications; Ola Hallengren's maintenance solution is a common standard for backups and index/statistics jobs.

Step 3 Common failures Narrow the fault

Agent service set to manual start stops all jobs after a reboot. A step writing to a network share fails because the service account lacks access. Express Edition has no Agent.

Key points

Agent service must run (not available in Express). Check job history for step errors and the proxy/credential used. Configure notifications for failures.

Key checks
  • SELECT status_desc FROM sys.dm_server_services; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand

How it works

Agent stores jobs, steps and schedules in msdb. Each step can be T-SQL, PowerShell or an SSIS package and has success and failure actions. Operators and alerts send notifications.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Parts of a job

PartWhat to set
OwnerA dedicated login (or sa), not a person who may leave
StepsT-SQL, PowerShell, CmdExec, SSIS; each with On success / On failure action and retry count
ProxyCredential for non-T-SQL steps that need access outside SQL Server (shares, other servers)
ScheduleShared schedules can drive several jobs
NotificationsOperator e-mail via Database Mail on failure

The Agent service is often installed with manual start; set it to Automatic or every job silently stops after a reboot. On Linux and Azure SQL Managed Instance the feature set differs.

Worked check — failed or overrunning jobs in the last 24 hours

SELECT j.name, h.step_id, h.step_name,
       msdb.dbo.agent_datetime(h.run_date, h.run_time) AS started,
       h.run_duration, h.run_status, LEFT(h.message, 200) AS message
FROM msdb.dbo.sysjobhistory h
JOIN msdb.dbo.sysjobs j ON j.job_id = h.job_id
WHERE h.run_status <> 1
  AND msdb.dbo.agent_datetime(h.run_date, h.run_time) > DATEADD(day, -1, GETDATE())
ORDER BY started DESC;

run_status: 0 failed, 1 succeeded, 2 retry, 3 cancelled. run_duration is encoded as HHMMSS.

Availability groups and failover

Jobs live in msdb, which is not part of an availability group. Create the job on every replica and start each step with a check such as IF sys.fn_hadr_is_primary_replica(N'shop') = 1 so it only does work on the current primary. Logins used by jobs must also exist on every replica.

Keep job history from being truncated too early: the default limits (1000 rows total, 100 per job) can erase the evidence of a failure within hours on a busy server.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Agent jobs owned by personal accounts.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
sql server agent jobssql server agent jobsysjobhistory
Confirmation

Confirm action

Continue?