方法一:
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案例详细分析:Job任务停止执行 本文通过一次Oracle Job任务异常案例诊断,分析其原因及解决过程,从内部揭示Oracle Job任务调度及内部计时机制。以下是关于Oracle Job任务的知识点: 1. Oracle Job任务的...
Oracle Job是Oracle数据库中的一个强大特性,主要用于在特定时间或间隔执行数据库操作,例如数据备份、维护任务或者定期的数据处理。以下是对Oracle Job使用方法和技巧的详细说明: 一、创建Oracle Job Oracle Job...
Oracle Job 是 Oracle 数据库中的一个特性,用于在预定义的时间间隔自动执行 PL/SQL 块或存储过程。Oracle Job 的使用对于实现定时任务、批处理操作和维护工作至关重要。以下是对 Oracle Job 使用的详细解释: 1. *...
Oracle Job是Oracle数据库中的一种调度工具,用于在指定的时间执行一系列数据库操作,如PL/SQL块、存储过程、包或操作系统命令。Oracle Job是Oracle的DBMS_SCHEDULER或之前版本中的DBMS_JOB包的一部分,它允许数据库...
在 Oracle 中,Job 是一个异步执行的任务,可以根据需要设置执行频率和执行时间。本文将详细介绍 Oracle 中创建 Job 的步骤和相关操作。 一、创建 Job 的准备工作 在创建 Job 之前,需要首先创建一个表来存储 Job ...
除了创建定时任务,DBA还可以通过DBMS_JOB包提供的其他过程来管理任务,例如运行一个指定的job、查看任务的执行结果、删除已经不再需要的job,或者在任务执行过程中修改任务的行为。例如,可以调用dbms_job.run来...
在这个Oracle版本中,你可以找到与Oracle数据库兼容的SQL脚本,用于创建必要的表结构和初始化数据,以便XXL-JOB可以在Oracle数据库上正常运行。 XXL-JOB使用Java语言开发,这使得它能够无缝集成到大多数Java企业...
oracle Job创建、管理、监控,Job运行情况分析,如果创建、删除、停止、修改Job.
在Oracle数据库管理系统中,`Oracle Job`是一种非常实用的功能,主要用于自动化执行某些任务。这些任务可以是存储过程、PL/SQL块或其他数据库操作。通过设置Job,用户能够实现定时执行任务的需求,比如定期清理数据...
Oracle Job管理是Oracle数据库中的一个关键特性,用于自动化执行数据库任务,如定时备份、数据清理或报告生成等。以下是对Oracle Job管理的详细解释: 1. **创建Job**: 在Oracle中,你可以通过创建存储过程来定义...
如果 Job 正在运行,需要先停止才能删除。 - **检查 Job 状态**:使用 `DBMS_JOB.IS_PENDING` 和 `DBMS_JOB.WHAT` 查询 Job 的当前状态和相关信息。 - **修改 Job**:通过 `DBMS_JOB.CHANGE` 更新 Job 的参数,如...
本文将深入解析如何利用Oracle JOB定时器来操作存储过程,包括创建、执行、查询、停止、启动以及删除JOB的全过程,并详细阐述定时器执行时间间隔的设置方法。 ### 创建表和存储过程 首先,为了演示JOB定时器的操作...
1. `job_queue_processes`:这是运行Job时启用的进程数,默认值为2,最小值为0,表示不运行任何Job,最大值为36。可以通过`ALTER SYSTEM SET job_queue_processes`命令进行修改,例如设置为2,然后重启进程。 2. `...
Oracle Job定时任务是Oracle数据库系统中一种强大的自动化功能,它允许管理员或开发人员安排数据库任务在特定的时间点或按照预定义的频率自动执行。Oracle Job主要用于执行PL/SQL块、存储过程、包或其他数据库操作,...
Oracle Job是Oracle数据库中的一个功能强大的调度工具,用于在预设的时间点自动执行数据库任务,如运行存储过程、数据备份、统计分析等。本文将深入探讨Oracle Job的使用与管理技巧。 首先,我们需要了解如何查看和...
Oracle定时任务,也被称为Oracle调度(Oracle Scheduler),是Oracle数据库系统中的一个重要组件,用于安排数据库内的作业自动执行。这些作业可以包括数据备份、清理过期记录、运行统计分析等日常维护任务。Oracle ...
Oracle Job 是 Oracle 数据库中的一个特性,用于在预定义的时间执行数据库操作,如定期备份、统计分析或数据清理等。Job 的使用与管理是数据库管理员(DBA)日常维护工作的重要部分,尤其对于大型企业应用而言,有效...
Oracle系统包中的`dbms_job`是一个非常重要的功能组件,它主要用于在Oracle数据库中安排和管理后台作业(job),使得数据库能够定期执行特定的任务。这对于自动化数据库管理和维护操作至关重要。本文将详细介绍`dbms...
在Oracle数据库中,定时执行存储过程是一项非常实用的功能,尤其适用于需要定期执行的任务,比如数据备份、数据清理、统计汇总等场景。通过设置定时任务,可以有效减轻管理员的工作负担,并确保关键业务流程的自动化...
Oracle数据库中的DBMS_JOB包是用于创建和管理定时任务的重要工具,它允许用户安排数据库执行特定的PL/SQL过程或存储过程。这个包提供了一系列的子程序,用于创建、修改、启动、停止以及监控数据库作业。下面将详细...