SHOW JOBS

The SHOW JOBS statement lists all of the types of long-running tasks your cluster has performed in the last 12 hours, including:

Considerations

  • The SHOW JOBS statement shows only long-running tasks. For an exhaustive list of jobs running in the cluster, use the SQL Audit Logging (Experimental) feature.
  • For jobs older than 12 hours, query the crdb_internal.jobs table.
  • Jobs are deleted after 14 days. This interval can be changed via the jobs.retention_time cluster setting.

Required privileges

By default, only the root user can execute SHOW JOBS.

Synopsis

SHOWAUTOMATICJOBS

Response

The output of SHOW JOBS lists ongoing jobs first, then completed jobs within the last 12 hours. The list of ongoing jobs is sorted by starting time, whereas the list of completed jobs is sorted by finished time.

The following fields are returned for each job:

FieldDescription
job_idA unique ID to identify each job. This value is used if you want to control jobs (i.e., pause, resume, or cancel it).
job_typeThe type of job. Possible values: SCHEMA CHANGE, BACKUP, RESTORE, IMPORT, and CREATE STATS. For SHOW AUTOMATIC JOBS, the possible value is AUTO CREATE STATS.
descriptionThe statement that started the job, or a textual description of the job.
statementNew in v19.1: When description is a textual description of the job, the statement that started the job is returned in this column. Currently, this field is populated only for the automatic table statistics jobs.
statusThe job's current state. Possible values: pending, running, paused, failed, succeeded, or canceled.
running_statusThe job's detailed running status, which provides visibility into the progress of the dropping or truncating of tables (i.e., DROP TABLE, DROP DATABASE, or TRUNCATE). For dropping or truncating jobs, the detailed running status is determined by the status of the table at the earliest stage of the schema change. The job is completed when the GC TTL expires and both the table data and ID is deleted for each of the tables involved. Possible values: draining names, waiting for GC TTL, RocksDB compaction, or NULL (when the status cannot be determined). For the SHOW AUTOMATIC JOBS statement, the value of this field is NULL.
createdThe TIMESTAMP when the job was created.
startedThe TIMESTAMP when the job began running first.
finishedThe TIMESTAMP when the job was succeeded, failed, or canceled.
modifiedThe TIMESTAMP when the job had anything modified.
fraction_completedThe fraction (between 0.00 and 1.00) of the job that's been completed.
errorIf the job failed, the error generated by the failure.
coordinator_idThe ID of the node running the job.

Examples

Show jobs

  1. > SHOW JOBS;
  1. job_id | job_type | description |...
  2. +---------------+-----------+-------------------------------------------+...
  3. 27536791415282 | RESTORE | RESTORE db.* FROM 'azure://backup/db/tbl' |...

Filter jobs

You can filter jobs by using SHOW JOBS as the data source for a SELECT statement, and then filtering the values with the WHERE clause.

  1. > SELECT * FROM [SHOW JOBS] WHERE job_type = 'RESTORE' AND status IN ('running', 'failed') ORDER BY created DESC;
  1. job_id | job_type | description |...
  2. +---------------+-----------+-------------------------------------------+...
  3. 27536791415282 | RESTORE | RESTORE db.* FROM 'azure://backup/db/tbl' |...

Show automatic jobs

  1. > SHOW AUTOMATIC JOBS;
  1. job_id | job_type | description |...
  2. +--------------------+---------------------+-----------------------------------------------------+...
  3. 438235476849557505 | AUTO CREATE STATS | Table statistics refresh for defaultdb.public.users |...
  4. (1 row)

Filter automatic jobs

You can filter jobs by using SHOW AUTOMATIC JOBS as the data source for a SELECT statement, and then filtering the values with the WHERE clause.

  1. > SELECT * FROM [SHOW AUTOMATIC JOBS] WHERE status = ('succeeded') ORDER BY created DESC;
  1. job_id | job_type | description | ...
  2. +--------------------+---------------------+-----------------------------------------------------+ ...
  3. 438235476849557505 | AUTO CREATE STATS | Table statistics refresh for defaultdb.public.users | ...
  4. (1 row)

See also

Was this page helpful?
YesNo