|
| 1 | +--- |
| 2 | +title: "jobs.job_executions (Azure Elastic Jobs) (Transact-SQL)" |
| 3 | +description: "The jobs.job_executions system view contains information about Azure Elastic job execution history." |
| 4 | +author: WilliamDAssafMSFT |
| 5 | +ms.author: wiassaf |
| 6 | +ms.date: 11/03/2023 |
| 7 | +ms.service: sql-database |
| 8 | +ms.subservice: system-objects |
| 9 | +ms.topic: "reference" |
| 10 | +f1_keywords: |
| 11 | + - "JOBS.JOB_EXECUTIONS" |
| 12 | + - "JOB_EXECUTIONS" |
| 13 | +helpviewer_keywords: |
| 14 | + - "job_executions catalog view" |
| 15 | + - "jobs.job_executions catalog view" |
| 16 | +dev_langs: |
| 17 | + - "TSQL" |
| 18 | +monikerRange: "=azuresqldb-current" |
| 19 | +--- |
| 20 | +# jobs.job_executions (Azure Elastic Jobs) (Transact-SQL) |
| 21 | + |
| 22 | +[!INCLUDE [Azure SQL Database](../../includes/applies-to-version/asdb.md)] |
| 23 | + |
| 24 | +Contains job execution status and history for jobs in the [Azure Elastic Jobs service for Azure SQL Database](/azure/azure-sql/database/elastic-jobs-overview?view=azuresql-db&preserve-view=true). |
| 25 | + |
| 26 | +|Column name | Data type | Description | |
| 27 | +|---------|---------|---------| |
| 28 | +|**job_execution_id** | uniqueidentifier | Unique ID of an instance of a job execution. |
| 29 | +|**job_name** | nvarchar(128) | Name of the job. |
| 30 | +|**job_id** | uniqueidentifier | Unique ID of the job. |
| 31 | +|**job_version** | int | Version of the job (automatically updated each time the job is modified). |
| 32 | +|**step_id** |int | Unique (for this job) identifier for the step. `NULL` indicates this execution is the parent job execution. |
| 33 | +|**is_active** | bit | Indicates whether information is active or inactive. `1` indicates active jobs, and `0` indicates inactive. |
| 34 | +|**lifecycle** | nvarchar(50) | Value indicating the status of the job. See [Lifecycle](#lifecycle) table for possible values. | |
| 35 | +|**create_time**| datetime2(7) | Date and time the job was created. |
| 36 | +|**start_time** | datetime2(7) | Date and time the job started execution. `NULL` if the job has not yet been executed. |
| 37 | +|**end_time** | datetime2(7) | Date and time the job finished execution. `NULL` if the job has not yet been executed or has not yet completed execution. |
| 38 | +|**current_attempts** | int | Number of times the step was retried. Parent job is `0`, child job executions will be `1` or greater, based on the execution policy. |
| 39 | +|**current_attempt_start_time** | datetime2(7) | Date and time the job started execution. `NULL` indicates this execution is the parent job execution. |
| 40 | +|**next_attempt_start_time** | datetime2(7) | Date and time the job will start next execution. `NULL` indicates this execution is the parent job execution. |
| 41 | +|**last_message** | nvarchar(max) | Job or step history message. |
| 42 | +|**target_type** | nvarchar(128) | Type of target database or collection of databases including all databases in a server, all databases in an elastic pool or a database. Valid values for `target_type` are `SqlServer`, `SqlElasticPool`, or `SqlDatabase`. `NULL` indicates this execution is the parent job execution. |
| 43 | +|**target_id** | uniqueidentifier | Unique ID of the target group member. `NULL` indicates this execution is the parent job execution. |
| 44 | +|**target_group_name** | nvarchar(128) | Name of the target group. `NULL` indicates this execution is the parent job execution. |
| 45 | +|**target_server_name** | nvarchar(256) | Name of the server contained in the target group. Specified only if `target_type` is `SqlServer`. `NULL` indicates this execution is the parent job execution. |
| 46 | +|**target_database_name** | nvarchar(128) | Name of the database contained in the target group. Specified only when `target_type` is `SqlDatabase`. `NULL` indicates this execution is the parent job execution. |
| 47 | + |
| 48 | +<a id="lifecycle"></a> |
| 49 | + |
| 50 | +The following table lists the possible job execution states in `lifecycle`: |
| 51 | + |
| 52 | +|State|Description| |
| 53 | +|:---|:---| |
| 54 | +|**Created** | The job execution was just created and is not yet in progress.| |
| 55 | +|**InProgress** | The job execution is currently in progress.| |
| 56 | +|**WaitingForRetry** | The job execution wasn't able to complete its action and is waiting to retry.| |
| 57 | +|**Succeeded** | The job execution has completed successfully.| |
| 58 | +|**SucceededWithSkipped** | The job execution has completed successfully, but some of its children were skipped.| |
| 59 | +|**Failed** | The job execution has failed and exhausted its retries.| |
| 60 | +|**TimedOut** | The job execution has timed out.| |
| 61 | +|**Canceled** | The job execution was canceled.| |
| 62 | +|**Skipped** | The job execution was skipped because another execution of the same job step was already running on the same target.| |
| 63 | +|**WaitingForChildJobExecutions** | The job execution is waiting for its child executions to complete.| |
| 64 | + |
| 65 | +## Permissions |
| 66 | + |
| 67 | +Members of the *jobs_reader* role can SELECT from this view. For more information, see [Elastic jobs in Azure SQL Database (preview)](/azure/azure-sql/database/elastic-jobs-overview?view=azuresql-db&preserve-view=true#elastic-job-database-permissions). |
| 68 | + |
| 69 | +## Remarks |
| 70 | + |
| 71 | +All times in elastic jobs are in the UTC time zone. |
| 72 | + |
| 73 | +## Examples |
| 74 | + |
| 75 | + |
| 76 | +### Monitor job execution status |
| 77 | + |
| 78 | +The following example shows how to view execution status details for all jobs. |
| 79 | + |
| 80 | +Connect to the `job_database` and run the following command: |
| 81 | + |
| 82 | +```sql |
| 83 | +--Connect to the job database specified when creating the job agent |
| 84 | + |
| 85 | +--View top-level execution status for the job named 'ResultsPoolJob' |
| 86 | +SELECT * FROM jobs.job_executions |
| 87 | +WHERE job_name = 'ResultsPoolsJob' and step_id IS NULL |
| 88 | +ORDER BY start_time DESC; |
| 89 | + |
| 90 | +--View all top-level execution status for all jobs |
| 91 | +SELECT * FROM jobs.job_executions WHERE step_id IS NULL |
| 92 | +ORDER BY start_time DESC; |
| 93 | + |
| 94 | +--View all execution statuses for job named 'ResultsPoolsJob' |
| 95 | +SELECT * FROM jobs.job_executions |
| 96 | +WHERE job_name = 'ResultsPoolsJob' |
| 97 | +ORDER BY start_time DESC; |
| 98 | + |
| 99 | +-- View all active executions |
| 100 | +SELECT * FROM jobs.job_executions |
| 101 | +WHERE is_active = 1 |
| 102 | +ORDER BY start_time DESC; |
| 103 | +``` |
| 104 | + |
| 105 | +### Run a job and monitor status |
| 106 | + |
| 107 | +The following example shows how to start an elastic job immediately as a manual, unplanned action. |
| 108 | + |
| 109 | +Connect to the `job_database` and run the following command: |
| 110 | + |
| 111 | +```sql |
| 112 | +--Connect to the job database specified when creating the job agent |
| 113 | + |
| 114 | +-- Execute the latest version of a job and receive the execution id |
| 115 | +DECLARE @je uniqueidentifier; |
| 116 | +EXEC jobs.sp_start_job 'CreateTableTest', @job_execution_id = @je output; |
| 117 | +SELECT @je; |
| 118 | + |
| 119 | +-- Monitor progress |
| 120 | + |
| 121 | +SELECT * FROM jobs.job_executions WHERE job_execution_id = @je; |
| 122 | +``` |
| 123 | + |
| 124 | +## Related content |
| 125 | + |
| 126 | +- [Elastic jobs in Azure SQL Database (preview)](/azure/azure-sql/database/elastic-jobs-overview?view=azuresql-db&preserve-view=true) |
| 127 | +- [Create, configure, and manage elastic jobs (preview)](/azure/azure-sql/database/elastic-jobs-tutorial?view=azuresql-db&preserve-view=true) |
| 128 | +- [Create and manage elastic jobs by using T-SQL (preview)](/azure/azure-sql/database/elastic-jobs-tsql-create-manage?view=azuresql-db&preserve-view=true) |
0 commit comments