停止删除oracle中正在执行的job

方法一:

Killing the Oracle DBMS_JOB

Take control of Oracle's queue with a step by step approach to getting rid of those pesky DBMS_JOBs.
Let's face it, Oracle's job scheduling facility is a wonderful tool for scheduling Oracle related jobs without having to maintain a cron job on Unix or an AT job in windows. It is also very robust and reliable. It is that very reliability and robustness that gives many of us our problems.
If you have any form of jobs running on your system, you will at one time or another come across the issue of a run-away job that just doesn't seem to want to end. Or maybe you will try and shutdown the database only to find out that it is waiting to complete a job. I would like to offer some help in the management of those job queues when they just don't seem to want to end or go away.
A while back I needed to find information on how to clear the job queue for jobs running with no apparent end in sight. Some had hung, while others just were taking a bad access path to data. I needed to bring down these jobs, do a bit of tuning and then restart the jobs. Well, to my amazement, there wasn't very much information out on the web that gave good insight into this process. Basically the method suggested was to first break the job and then issue an ALTER SYTEM KILL SESSION command. This method does not always work and unfortunately--never on my system, for the jobs I had. I then called Oracle support and basically got the same answer as I found out on the web. They did give me one added piece of information. They said, if the ALTER SYSTEM KILL SESSION didn't work, I was supposed to bounce my database in order to bring down the job queue processes. First of all, this wasn't an option and when I did get the opportunity to bounce the database box, many of the jobs seemed to come right back as strong as ever.
Before writing this article I did another quick search on the topic of killing dbms_jobs and to my amazement there still wasn't much good information out there. This is why I want to share my method, so that you won't be stuck up against the wall with this problem and nowhere to turn, as I was.
Viewing Scheduled dbms_jobs
When looking at what jobs have been scheduled, there is really only one view that you need to go to. The dba_jobs view contains all of the information you need, to see what has been scheduled, when they were last run, and if they are currently running. Use the following simple script to take a look. Bear with me on the sub-select, I will build on this query as we go on in the presentation.

scheduled_dbms_jobs.sql
set linesize 250
col log_user      for a10
col job            for 9999999  head 'Job'
col broken        for a1        head 'B'
col failures      for 99        head "fail"
col last_date      for a18      head 'Last|Date'
col this_date      for a18      head 'This|Date'
col next_date      for a18      head 'Next|Date'
col interval      for 9999.000 head 'Run|Interval'
col what          for a60

select j.log_user,
    j.job,
    j.broken,
    j.failures,
    j.last_date||':'||j.last_sec last_date,
    j.this_date||':'||j.this_sec this_date,
    j.next_date||':'||j.next_sec next_date,
    j.next_date - j.last_date interval,
    j.what
from (select dj.LOG_USER, dj.JOB, dj.BROKEN, dj.FAILURES,
            dj.LAST_DATE, dj.LAST_SEC, dj.THIS_DATE, dj.THIS_SEC,
            dj.NEXT_DATE, dj.NEXT_SEC, dj.INTERVAL, dj.WHAT
        from dba_jobs dj) j;

What Jobs are Actually Running

A simple join to the dba_jobs_running view will give us a good handle on the scheduled jobs that are actually running at this time. This is done by a simple join through the job number. The new column of interest returned here is the sid which is the identifier of the process that is currently executing the job.

running_jobs.sql

set linesize 250
col sid            for 9999    head 'Session|ID'
col log_user        for a10
col job            for 9999999 head 'Job'
col broken          for a1      head 'B'
col failures        for 99      head "fail"
col last_date      for a18      head 'Last|Date'
col this_date      for a18      head 'This|Date'
col next_date      for a18      head 'Next|Date'
col interval        for 9999.000 head 'Run|Interval'
col what            for a60
select j.sid,
        j.log_user,
        j.job,
        j.broken,
        j.failures,
        j.last_date||':'||j.last_sec last_date,
        j.this_date||':'||j.this_sec this_date,
        j.next_date||':'||j.next_sec next_date,
        j.next_date - j.last_date interval,
        j.what
from (select djr.SID,
                  dj.LOG_USER, dj.JOB, dj.BROKEN, dj.FAILURES,
                  dj.LAST_DATE, dj.LAST_SEC, dj.THIS_DATE, dj.THIS_SEC,
                  dj.NEXT_DATE, dj.NEXT_SEC, dj.INTERVAL, dj.WHAT
          from dba_jobs dj, dba_jobs_running djr
        where dj.job = djr.job ) j;

What Sessions are Running the Jobs

Now that we have determined which jobs are currently running, we need to find which Oracle session and operating system process is accessing them. This is done through first joining v$process to v$session by way of paddr and addr which is the address of the processs that owns the sessions, and then joining the results back to the jobs running through the sid value. The new columns returned in our query are spid which is the operating system process identifier and serial# which is the session serial number.

session_jobs.sql

set linesize 250
col sid          for 9999    head 'Session|ID'
col spid                      head 'O/S|Process|ID'
col serial#      for 9999999 head 'Session|Serial#'
col log_user      for a10
col job          for 9999999 head 'Job'
col broken        for a1      head 'B'
col failures      for 99      head "fail"
col last_date    for a18      head 'Last|Date'
col this_date    for a18      head 'This|Date'
col next_date    for a18      head 'Next|Date'
col interval      for 9999.000 head 'Run|Interval'
col what          for a60
select j.sid,
s.spid,
s.serial#,
      j.log_user,
      j.job,
      j.broken,
      j.failures,
      j.last_date||':'||j.last_sec last_date,
      j.this_date||':'||j.this_sec this_date,
      j.next_date||':'||j.next_sec next_date,
      j.next_date - j.last_date interval,
      j.what
from (select djr.SID,
            dj.LOG_USER, dj.JOB, dj.BROKEN, dj.FAILURES,
            dj.LAST_DATE, dj.LAST_SEC, dj.THIS_DATE, dj.THIS_SEC,
            dj.NEXT_DATE, dj.NEXT_SEC, dj.INTERVAL, dj.WHAT
        from dba_jobs dj, dba_jobs_running djr
      where dj.job = djr.job ) j,
    (select p.spid, s.sid, s.serial#
          from v$process p, v$session s
        where p.addr = s.paddr ) s
where j.sid = s.sid;

Now that we have a good handle on how we can look at the jobs and the key columns involved, let's go through the steps needed to bring down a job. The following is a 5 to 11 step process that should solve all of your problems.


Bringing Down a DBMS_JOB

1. Find the Job You Want to Bring Down

In order to do anything you first need to find the job that is giving you a headache. Go ahead and run the running_jobs.sql. This will give you the prime information, job, sid, serial#, and spid, for the following actions in bringing down the job.

2. Mark the DBMS_JOB as Broken

Use the following command for the job that you have to deal with.

SQL> EXEC DBMS_JOB.BROKEN(job#,TRUE);

All this command does is mark the job so that if we get it to stop, it won't start again. Let's make one thing perfectly clear, after executing this command the job is still running.

As a side note, if you are trying to shut down a database with jobs that run throughout the day, they may hinder your attempts to bring down the database cleanly. This is a wonderful command to make sure no jobs are executing during the shutdown process. Just be aware that you will need to mark the jobs as unbroken when the database comes back up, more on that later.

3. Kill the Oracle Session

Since the job is still running and it isn't going to end soon, you will need to kill the Oracle session that is executing the job. Use the following command for to kill the job.

ALTER SYSTEM KILL SESSION 'sid,serial#';

4. Kill the O/S Process

More often than not the previous step will still leave the job attached to the database and still running. When this happens you will need to go out to the operating system level and get rid of the process that has spawned from the running job. In order to do this you must login to the database box and issue the following command, depending on the type of operating system you have.

For Windows, at the DOS Prompt: orakill sid spid

For UNIX at the command line> kill '9 spid

The orakill is an Oracle command, while kill is a Unix command.

5. Check if the Job is Still Running

Re-run the session_jobs.sql script to see if you have gotten rid of the job. If you have there is no reason to go further. Usually steps 1 through 4 will be sufficient to get rid of a job but when the job is running wild you will have to continue with steps 6 through 11 which describes a process for bouncing the job queue process.

6. Determine the Current Number of Job Queue Processes

SQL> col value for a10
SQL> select name,value from v$parameter where name = 'job_queue_processes';

7. Alter the Job Queue to Zero

SQL> ALTER SYSTEM SET job_queue_processes = 0;

This will bring down the entire job queue processes.

8. Validate that No Processes are Using the Job Queue

Re-run the session_jobs.sql script to see if any jobs are still running. Since we have given a hard stop to the job queue and issued the kill commands, you can now wait until no more jobs are running. After all the jobs have quit running, you can do whatever maintenance or tuning you need to do before proceeding.

9. Mark the DBMS_JOB as Not Broken
You can now reset the broken job to not broken so they can run again. Just issue the command.

SQL>EXEC DBMS_JOB.BROKEN(job#,FALSE):

10. Alter the Job Queue to Original Value
Set the job queue to its' original value so that the jobs can run again.

ALTER SYSTEM SET job_queue_processes = original_value;

11. Validate that DBMS_JOB Is Running
To make sure everything is back to normal, re-run the above scripts to validate that jobs are scheduled, not broken, and are executing with the next and last dates columns changing.

Oracle have given us a great tool for scheduling activities within the database. As with many things inside the database, not everything goes as planned, nor are we given adequate tools to fix some of the problems we encounter. With the eleven steps outlined here, hopefully you will have increased your arsenal to handle those run away jobs that have given the best of us a few tense moments.
--------------------------------------------------------------------------------------------------------------------------
注意:第四步 删除操作系统层次的进程或线程操作,Oracle在Linux/Unix中后台进程是以进程方式运作,在Windows系列操作系统中是以线程方式运作。
对于Windows,启动命令提示符:
orakill sid spid
其中sid是数据库实例的名称,而不是前面脚本中查出来的sid。
可以通过一下命令来得到:
select name from v$database;
select instance_name from v$instance;

 

方法二:

1、查看所有job;
select * from dba_jobs;
2、查看正在运行的job;
select * from dba_jobs_running;
3、根据sid查出对应的session;
select SID,SERIAL# from V$Session where SID='&SID';
4、kill对应的session;
alter system kill session '&SID,&SERIAL';
5、将job置为broken;
exec dbms_job.broken('&JOB',true);
6、sysdba用户权限删除job;
delete from dba_jobs where JOB='&JOB';

【Oracle】Oracle JOB常用操作 【代码】Oracle job常用操作。 阅读详情

相关推荐

Oracle停止job的正确方式

Oracle停止job的正确方式 1、改job状态broken由N为Y 2、删除job

tttzzzqqq2018的博客 5690

Killing the Oracle DBMS_JOB

Killing the Oracle DBMS_JOB Take control of Oracle's queue with a step by step approach to getting rid of those pe...

cuicuntu1021的博客 172

【实战指南】从零构建UNet多分类分割数据集:标注、转换与训练全流程

本文提供了一份从零构建UNet多分类分割数据集的完整实战指南。详细介绍了使用Labelme进行图像标注的核心技巧与规范,并通过Python脚本将标注结果转换为模型可用的VOC格式。最后,指导如何修改经典的PyTorch版UNet代码,以适配自定义数据集并进行训练与测试,帮助读者完成从数据准备到模型训练的全流程。

arduino9maker的博客 286

如何停止正在运行的job(解决job不能删除或修改的问题)

正在运行的job 删除或修改是不行的,只能 kill  process  /  kill  session。 --1.先查一下正在运行的job select *from dba_jobs_running; --2.查找到session select a.spid, b.SID, b.SERIAL#   from v$process a, v$session b  where a.add

关注系统性能调优 1万+

手把手实战:RK3588上YOLOv8模型从训练到部署全流程解析

本文详细解析了在RK3588开发板上部署YOLOv8目标检测模型的全流程。从模型训练、正确导出适配的ONNX格式,到使用RKNN-Toolkit2进行模型转换与量化,最后在板卡上完成部署与性能测试。文章提供了完整的代码示例和关键避坑指南,帮助开发者高效实现嵌入式AI应用落地。

weixin_28224217的博客 401

薄膜比拟、开口截面扭转承载力以及风电混塔水平缝张开状态下抗扭承载力推导

风电混塔水平缝张开状态下的抗扭承载力推导,从弹性力学说起

George的博客 872

oracle创建job和删除job

oracle创建job和删除job

secret安静 2万+

从零搭建一个AF架构项目:基于TIA Portal V19和S7-PLCSIM的仿真调试全流程

本文详细介绍了如何在TIA Portal V19环境中从零搭建西门子Automation Framework(AF架构)项目,包括环境准备、硬件组态、核心组件创建、项目架构分层实现以及仿真调试全流程。通过模块化编程和标准化接口设计,AF架构显著提升工业自动化项目的开发效率和维护便利性,特别适合S7-1500系列PLC的应用开发。

weixin_29313547的博客 672

数据泵重启报错ORA-39004: invalid state

停止作业是一定要使用STOP_JOB=IMMEDIATE这个命令,否则数据泵作业的状态为"STOP PENDING"时,表示作业正在等待停止。这意味着在之前的操作中,作业已经被停止,但还没有完全停止。当作业处于"STOP PENDING"时,执行STOP_JOB=IMMEDIATE后,看作业状态,然后执行start_job即可。暂停作业时使用了stop_job命令,state=STOP PENDING。后来处理报错后重新启动job。执行START_JOB报错。

qq_52254886的博客 458

如何在windows电脑上搭建Linux环境(手把手教安装虚拟机软件和使用云服务器)

手把手教学如何搭建Linux环境

纪宁的博客 1万+

CDR学习笔记——02

这篇写一些高级CDR的架构原理。

... 1014

删除oracle Job

删除oracle Job 1.删除所有用户的JOB begin for v in(select job from user_jobs) loop dbms_job.remove(v.job); end loop; commit; end;2.删除指定用户的JOB define USER=&1begin for v in(select job from user_...

weixin_34291004的博客 289

RT-DETR的AIF模块+YOLOv8:融合注意力与特征交互,打造实时检测的科研级进阶方案

从理解AIF模块“细粒度注意力+跨尺度交互”的核心设计,到亲手将其嵌入YOLOv8并验证在复杂场景的表现,再到基于此探索属于自己的科研与工程方向——这个过程能让你深刻理解“注意力机制与CNN融合”在实时检测中的核心价值。现在就开始行动,相信你会在实时目标检测的“智能进化”之路上,走出一条属于自己的技术路径。从实验对比图可见,集成AIF模块的YOLOv8,其mAP(平均精度)在多个阈值下均有提升,尤其是mAP50-95(高IoU阈值下的精度)提升更为显著,充分证明了AIF对细粒度特征的捕捉能力。

m0_64661770的博客 186

oracle job详解

oracle job详解

qq1372540969的博客 869

ABAP CDS 货币与计量单位换算全攻略:CURRENCY_CONVERSION、UNIT_CONVERSION 与 DECIMAL_SHIFT 的工程化实践

本文介绍了SAP ABAP CDS中三种单位/货币换算函数(UNIT_CONVERSION、CURRENCY_CONVERSION、DECIMAL_SHIFT)的实战应用。重点包括:各函数的职责边界与适用场景,参数配置与精度控制策略,以及基于标准表(T006、TCUR*等)的换算规则来源。文章提供可运行的CDS示例,涵盖单位换算(如MI转KM)、货币汇率转换(含小数位处理)及纯小数位调整等典型场景,并强调生产环境中需注意的精度差异与审计风险控制。适用于企业报表、成本核算等需要统一口径的业务场景。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1553

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

创建ORACLE JOB

oracle job简介 主要的使用情景 定时在后台执行相关操作:如每天晚上0点将一张表的数据保存到另一张表中,2:定时备份数据库等 熟化说万事开头难,这里我只简单记述一个创建一个简单的job 步骤如下: 1、创建一张表g_test create table G_TEST ( ID     NUMBER(12), C_DATE DATE ) 2、创建

hualizide的专栏 402

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

oracle 停止正在运行的job

<br /><br />ORACLE如何停止一个JOB<br />1 相关表、视图<br />2 问题描述<br />为同事解决一个因为网络连接情况不佳时,执行一个超长时间的SQL插入操作。<br />既然网络状况不好,就选择了使用一次性使用JOB来完成该插入操作。在JOB执行一段时间后,我发现被插入表有些问题(惭愧,当时也没有先检查检查就做了)。准备停止JOB,因为在JOB运行情况下,我的所有修改都会报系统资源忙的错误。<br />强行KILL SESSION是行不通的,因为过会儿,JOB还会重新启动,如

海盗的成长 1634

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Oracle 如何停止正在运行的 Job

停止链式作业(chain job)时可能需要停止整个链。

文牧之的博客 2661

ORACLE JOB以及如何停止一个正在运行的JOB

niudba的专栏 2078

oracle每日执行job,ORACLE定时执行Job任务

今天改完了全部的bug,就想整个项目哪里有地方可以优化,哪里还存在需要补坑。因为是统计周月数据,便想到了数据库定时Job任务创建。在百度上,找到了一篇好文章,跟大家分享:http://langgufu.iteye.com/blog/1179235另一篇文章是关于ORACLE时间间隔书写:https://blog.youkuaiyun.com/wangjiajiachengcheng/article/detai...

weixin_42295528的博客 1456

Oracle强制停止job

1 温柔的方法 1.查看所有job select * from dba_jobs; 2.查看正在运行的job select * from dba_jobs_running; 3.根据sid查出对应的session select SID,SERIAL# from V$Session where SID='&SID'; 4.kill对应的session alter system kill...

鲨鱼胃的博客 1434

oracle job的创建和删除,oracle job的创建和删除

oracle job的创建declarev_jobnumnumber;begindbms_job.submit(v_jobnum,'lastjob;',sysdate,'last_day(sysdate)+1');COMMIT;end;或者DECLAREjobno numeric;BEGINdbms_job.submit(jobno,'getAndSyncKey;',sysdate,'trun...

weixin_28543661的博客 2019

201920 Oracle 停止job、停止session

最近折腾oracle数据库 发现: select * from dba_jobs_running, 对应的几个job,next time 小于当前日期,所以这几个job一直在运行。 那么,怎么把这几个job给干掉呢? 一、在sql command中,执行: sql> exec dbms_job.broken(1111,TRUE); 将 job 先broken 这个效果,就是让job 不再...

Partner2016的博客 826

如何停止Oracle expdp/impdp job

如果直接ctrl+c“停掉”,此时的“停掉”并不是真正的任务终止,它还在后台运行。这里说明一下正确停止job的操作步骤。如果直接ctrl+c“停掉”,此时的“停掉”并不是真正的任务终止,它还在后台运行。这里说明一下正确停止job的操作步骤。EXPDP_JOB 任务正在运行:EXECUTING。IMPDP_JOB 任务正在运行:EXECUTING。至此,已完全停止 expdp job。至此,已完全停止 impdp 任务。1.执行 expdp 命令。2.查看在运行的作业名称。2.查看在运行的作业名称。

Ruishine的博客 1946

oracle 命令 执行job_Oracle Job定时任务的使用详解

oracle中的job能为你做的就是在你规定的时间格式里执行存储过程,定时执行一个任务 。下面是一个小案例,定时每15分钟向一张表插入一条数据1.创建一张测试表1 --Create table2 create tableA83 (4 a1 VARCHAR2(500)5 )6 tablespace DSP_DATA7 pctfree 108 initrans 19 maxtrans ...

weixin_39989973的博客 1362
上一篇: WindowsXP上VMware下安装RedHat9的上网配置
下一篇: Js(Css)动态引用方法–Js(css)的统一管理
javaRwx
博客等级 码龄20年 0粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值