Monday, 23 June 2025

Need to Stop a Running BigQuery Job? Use bq cancel

Want to stop a running BigQuery job before it completes?

Just use the bq cancel command with the job ID: 

bq cancel job_id

Example:

bq cancel bquxjob_5678abcd_00000efghij

 This will immediately stop the execution of that job, whether it's a long-running query or a batch job.

 

How to Find the Job ID?

You can get the job ID from:

 

·      The output of a query run using --location and --job_id_prefix

·      Monitoring tools like the GCP console

·      Logging systems or previous bq query outputs

·      Use bq ls -j to list recent jobs

 

Example

bq ls -j --max_results=5 --project_id=your_project_id
bq ls -j --max_results=5

$bq ls -j --max_results=5
             jobId               Job Type    State      Start Time         Duration     
 ------------------------------ ---------- --------- ----------------- ---------------- 
  bquxjob_ab12cd34_efgh5678901   load       SUCCESS   06 Apr 19:02:17   0:00:03.390000  
  bquxjob_1234abcd_9876efgh543   query      SUCCESS   06 Apr 15:27:28   0:00:00.902000  
  bquxjob_5678efgh_1234abcd876   query      SUCCESS   06 Apr 15:27:09   0:00:05.238000  
  bquxjob_90ab12cd_3456efgh789   query      SUCCESS   06 Apr 15:26:38   0:00:00.975000  
  bquxjob_abcdef12_345678ghij9   query      SUCCESS   06 Apr 15:23:10   0:00:06.462000  

 

Why to Use bq cancel?

  • Save costs by stopping long-running or unoptimized queries
  • Quickly interrupt accidental or test jobs

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment