What is SQL Server Agent?
This Windows service executes scheduled jobs in SQL Server.
What is SQL Server Agent?
SQL Server Agent Definition
SQL Server is a popular relational database management system (RDBMS) developed by Microsoft. It uses Structured Query Language (SQL), making storing, retrieving, manipulating, and analyzing data much easier. But what is SQL Server Agent? In short, it’s a component of SQL Server designed to help streamline routine tasks, saving you time and energy.
With SQL Server Agent, you can automate and schedule tasks in SQL Server like database backups, log file deletion, data processing, query execution, job execution, reporting, and much more. Once you apply rules and schedules to a job, SQL Server Agent can execute it at the right time, giving you more flexibility to concentrate on other essential tasks. Then, you can view history to see if an execution was successfully carried out or failed. Should a job fail, you can manually restart it. Additionally, SQL Server Agent can notify the necessary personnel whenever certain predefined conditions are met, allowing your team to action faster if anything goes wrong.
Essentially, SQL Server Agent can help you automate routine tasks, optimize database performance, and ensure your SQL Server environments operate smoothly, freeing your database administrators to concentrate on other tasks.
SQL Server Agent Jobs
Regardless of which method you choose to run your SQL Server Agent jobs, your job will have one or more job steps, each with a specific set of instructions. Common examples of job steps include:
- PowerShell scripts
- Microsoft ActiveX scripts
- Transact-SQL statements
- Executable programs
- Operating system commands
- Replication tasks
- Integration Services packages
- Analysis Services tasks
SQL Server Agent will execute the first step then move on to the next, based on whether the first step succeeded or failed. This will continue until all the steps have been executed and the job is completed, or a step fails. It will also provide information on whether your job succeeds or fails.
It’s also worth noting that each step in a job will run within a specific security context. To set the security context for job steps that use T-SQL, you can use the EXECUTE AS statement. You can use a proxy account to set security contexts for other job types.
SQL Sentry’s Event Calendar can provide a visual representation of all your scheduled jobs as well as average runtime, actual runtime, and job success or failure. Additionally, Event Calendar offers powerful filtering capabilities and custom event views so you can quickly find what you’re looking for.
Accessing SQL Server Agent
To enable SQL Server Agent, you’ll want to ensure that it is running as a service and configured to use the credentials of an account that has the SysAdmin fixed server role in SQL Server. The credentials should have several permissions, including log on as a service, replacing a process-level token, bypass traverse checking, and adjust memory quotas for a process.
After setting this up, you can click Run before typing the command services.msc and hitting OK. This will prompt the Services window to appear. You can then scroll down to find the SQL Server Agent INSTANCE NAME service. Since the Agent is disabled by default, you’ll see blank status, signifying that SQL Service is not running. Right-click, then choose Start from the menu to get SQL Server Agent up and running. Now, instead of seeing a blank space, you’ll see Running.
SQL Server Agent Components
While jobs are an important component of SQL Server Agent, they aren’t the only type of component. Other notable aspects include:
- Schedules: When you create a schedule for your job, it will specify when the job runs and automatically executes based on your chosen date and time. You can also schedule recurring jobs on an hourly, daily, weekly, or even monthly basis. Plus, you can create a schedule, so a job only runs on specific days of the week, when SQL Server Agent starts, or when a computer’s CPU utilization becomes idle (as predefined by you.) Note: Multiple jobs can run on the same schedule, and you can apply several schedules to the same job.
- Alerts: Alerts will occur automatically in response to a specific event regarding SQL Server performance or events and Microsoft Windows Management Instrumentation (MWMI) events. Examples of events include when a job starts, or a specific threshold is crossed. Once an event occurs, an alert can notify the necessary operators and even run a job.
- Operators: In SQL Server Agent, the contact information for the person in charge of maintaining the instance(s) is called an operator. Some organizations assign operator responsibilities to one person, while other organizations have multiple services and choose to have several people share operator responsibilities. It’s also possible to use an operator as an overarching alias for a group of people that can receive electronic notifications. Regardless of how many people have operator responsibilities, an SQL Server Agent operator won’t contain any security information. It will notify operators via:
- Pager: To send notifications to operators by pager, you’ll need to configure SQL Server Agent to use Database Mail. Not only will you need to enable Database Mail and create a Database Mail account for your SQL Server Agent account, but you’ll also need to create a Database Mail profile, add it to the DatabaseMailUserRole database role in your msdb database, and set this new profile as the default one for the msdb database.
- Then, you’ll need to handle security permissions and head to Object Explorer. Here, you can expand an SQL Server instance, right-click on SQL Server Agent, and select Properties, Alert System, then Enable Mail Profile. Next, select Database Mail in the Mail System list and choose a mail profile for Database Mail in the Mail Profile list before restarting the Agent.
- Email: Likewise, if you want to send notifications to operators via email, you’ll need to configure SQL Server Agent to use Database Mail.
- Net Send: If you’d like to send notifications using net send, you’ll need to start the Windows Messenger service.
- Proxies: Proxies are used to manage security context, can be created by members in sysadmin fixed server roles, and can be used in multiple job steps. Job owners using logins associated with a proxy can also create job steps that use that specific proxy.
Each proxy will correspond to a security credential and can be associated with a set of logins and a set of subsystems. However, a proxy won’t work with job steps that aren’t associated with it. Additionally, SQLAgentUserRole, SQLAgentOperatorRole, and SQLAgentReaderRole need to be granted specific access to use proxies.
- Notifications: You can also set up email notifications if you want to receive notifications when a job fails. By enabling notifications, you can more easily stay on top of job failures and take action when necessary.
What is SQL Server Agent?
SQL Server Agent Definition
SQL Server is a popular relational database management system (RDBMS) developed by Microsoft. It uses Structured Query Language (SQL), making storing, retrieving, manipulating, and analyzing data much easier. But what is SQL Server Agent? In short, it’s a component of SQL Server designed to help streamline routine tasks, saving you time and energy.
With SQL Server Agent, you can automate and schedule tasks in SQL Server like database backups, log file deletion, data processing, query execution, job execution, reporting, and much more. Once you apply rules and schedules to a job, SQL Server Agent can execute it at the right time, giving you more flexibility to concentrate on other essential tasks. Then, you can view history to see if an execution was successfully carried out or failed. Should a job fail, you can manually restart it. Additionally, SQL Server Agent can notify the necessary personnel whenever certain predefined conditions are met, allowing your team to action faster if anything goes wrong.
Essentially, SQL Server Agent can help you automate routine tasks, optimize database performance, and ensure your SQL Server environments operate smoothly, freeing your database administrators to concentrate on other tasks.
SQL Server Agent Jobs
An SQL Server Agent job is a series of actionst the Agent will perform on your behalf. You can run a job on a local server or several remote servers and configure it to run once, on a recurring schedule (or several), or only when specific events occur, or alerts are issued. You can also run jobs by executing the sp_start_job stored procedure.Regardless of which method you choose to run your SQL Server Agent jobs, your job will have one or more job steps, each with a specific set of instructions. Common examples of job steps include:
- PowerShell scripts
- Microsoft ActiveX scripts
- Transact-SQL statements
- Executable programs
- Operating system commands
- Replication tasks
- Integration Services packages
- Analysis Services tasks
SQL Server Agent will execute the first step then move on to the next, based on whether the first step succeeded or failed. This will continue until all the steps have been executed and the job is completed, or a step fails. It will also provide information on whether your job succeeds or fails.
It’s also worth noting that each step in a job will run within a specific security context. To set the security context for job steps that use T-SQL, you can use the EXECUTE AS statement. You can use a proxy account to set security contexts for other job types.
SQL Sentry’s Event Calendar can provide a visual representation of all your scheduled jobs as well as average runtime, actual runtime, and job success or failure. Additionally, Event Calendar offers powerful filtering capabilities and custom event views so you can quickly find what you’re looking for.
Accessing SQL Server Agent
By default, SQL Server Agent is disabled and requires manual service startup, but the process to enable it is relatively simple.To enable SQL Server Agent, you’ll want to ensure that it is running as a service and configured to use the credentials of an account that has the SysAdmin fixed server role in SQL Server. The credentials should have several permissions, including log on as a service, replacing a process-level token, bypass traverse checking, and adjust memory quotas for a process.
After setting this up, you can click Run before typing the command services.msc and hitting OK. This will prompt the Services window to appear. You can then scroll down to find the SQL Server Agent INSTANCE NAME service. Since the Agent is disabled by default, you’ll see blank status, signifying that SQL Service is not running. Right-click, then choose Start from the menu to get SQL Server Agent up and running. Now, instead of seeing a blank space, you’ll see Running.
SQL Server Agent Components
While jobs are an important component of SQL Server Agent, they aren’t the only type of component. Other notable aspects include:
- Schedules: When you create a schedule for your job, it will specify when the job runs and automatically executes based on your chosen date and time. You can also schedule recurring jobs on an hourly, daily, weekly, or even monthly basis. Plus, you can create a schedule, so a job only runs on specific days of the week, when SQL Server Agent starts, or when a computer’s CPU utilization becomes idle (as predefined by you.) Note: Multiple jobs can run on the same schedule, and you can apply several schedules to the same job.
- Alerts: Alerts will occur automatically in response to a specific event regarding SQL Server performance or events and Microsoft Windows Management Instrumentation (MWMI) events. Examples of events include when a job starts, or a specific threshold is crossed. Once an event occurs, an alert can notify the necessary operators and even run a job.
- Operators: In SQL Server Agent, the contact information for the person in charge of maintaining the instance(s) is called an operator. Some organizations assign operator responsibilities to one person, while other organizations have multiple services and choose to have several people share operator responsibilities. It’s also possible to use an operator as an overarching alias for a group of people that can receive electronic notifications. Regardless of how many people have operator responsibilities, an SQL Server Agent operator won’t contain any security information. It will notify operators via:
- Pager: To send notifications to operators by pager, you’ll need to configure SQL Server Agent to use Database Mail. Not only will you need to enable Database Mail and create a Database Mail account for your SQL Server Agent account, but you’ll also need to create a Database Mail profile, add it to the DatabaseMailUserRole database role in your msdb database, and set this new profile as the default one for the msdb database.
- Then, you’ll need to handle security permissions and head to Object Explorer. Here, you can expand an SQL Server instance, right-click on SQL Server Agent, and select Properties, Alert System, then Enable Mail Profile. Next, select Database Mail in the Mail System list and choose a mail profile for Database Mail in the Mail Profile list before restarting the Agent.
- Email: Likewise, if you want to send notifications to operators via email, you’ll need to configure SQL Server Agent to use Database Mail.
- Net Send: If you’d like to send notifications using net send, you’ll need to start the Windows Messenger service.
- Proxies: Proxies are used to manage security context, can be created by members in sysadmin fixed server roles, and can be used in multiple job steps. Job owners using logins associated with a proxy can also create job steps that use that specific proxy.
Each proxy will correspond to a security credential and can be associated with a set of logins and a set of subsystems. However, a proxy won’t work with job steps that aren’t associated with it. Additionally, SQLAgentUserRole, SQLAgentOperatorRole, and SQLAgentReaderRole need to be granted specific access to use proxies.
- Notifications: You can also set up email notifications if you want to receive notifications when a job fails. By enabling notifications, you can more easily stay on top of job failures and take action when necessary.
SolarWinds SQL Sentry provides database performance monitoring for only the Microsoft SQL Server and platform.
View More Resources
What is Database Performance Tuning?
It's the process of ensuring smooth and optimal database performance by using varied techniques, tools, and best practices.
View IT GlossaryWhat is a Database Query?
In everyday language, a query is simply a request for information. Similarly, the meaning of a query in database management is a request for data. If you need to access, manipulate, delete, or retrieve data from your relational database, you’ll need a database query written using a specific syntax.
View IT GlossaryWhat is Database Management System (DBMS)?
Database performance management system is designed to help admins more easily troubleshoot and resolve DBMS performance issues by monitoring performance and providing root-cause analysis of your database using multi-dimensional views to answer the who, what, when, where, and why of performance issues.
View IT GlossaryWhat is a Database Schema?
A database schema refers to the logical and visual configuration of the entire relational database.
View IT Glossary