What happens to a SQL job if it doesn't finish? - sql

Let's say there's a SQL job that runs a stored procedure every one minute.
What happens, if it takes more than a minute? Does it start the procedure again (having 2 of them running in the same time) or it waits for the previous to finish?

A job can only have the status of running or not, a job that is already running won't start again.

Related

How to stop a SQL Agent job (running on an hourly schedule) to stop executing once it is successful

I have a SQL Agent job that runs on the 7th of each month on an hourly basis. I want to stop it from running further once it is successful.
For example, if the job is successful at 8:00 A.M, I dont want it to run any more untill the 7th of next month. Any scripts would be helpful for this.
I am working on trying to establish this rule through the use of MSDB sys.jobs and an idea that I have is to update the Enabled flag to a 0 once the run is complete. Once the 7th of next month hits, another job on the SQL Agent could go in an update the flag back to a 1 so it can be run. i
I suggest you create a new first job-step and, using the answer provided in the question sql-agent-job-last-run-status, you can check if the last execution succeeded.
You can then cancel the job from executing by using exec msdb.dbo.sp_stop_job
I use this method in an Availability group cluster (to check if SQL Agent is running on the primary for jobs the require it) and abort the job if not. It works well.
How about, create a table with a row for last successful run, populate it on a successful run.
Then first thing in the job, check that table, and if the last successful run is since the 7th, terminate.
Otherwise run the rest of the job.
The solution that I finally deployed was to add a step to the job that would disable it once all preceding steps succeeded. I added another job to the Agent that would go and enable this job on the 1st of each month so that they are ready to be executed. Just throwing this out so that someone else can benefit.

How to log custom errors in scheduled job execution within Toad for Oracle

I have a stored procedure that runs every day, my problem is... if this procedure finds any controlled error, how do I log this into "Aditional Info(Run)/Errors/Output" columns on the run log of my scheduled job (I need to log this in any of this columns if it is possible)?

SELECT hanging with SOS_SCHEDULER_YIELD lastwaittype

I've been experiencing a strange situation with a specific SELECT on SQL Server 2008 Standard.
I have a proc that executes a bunch of commands.
One of the last tasks is to insert the result of a select statement into a table. This proc is executed for each step of a job (with 20 steps) just changing one parameter, store code (the company has 20 stores).
This insert-select command normally executes in 2 minutes, but sometimes, it gets stuck with an SOS_SCHEDULER_YIELD lastwaittype and hangs forever... until I kill the process. After that, if I execute the same command, it executes in the normal 2 minutes.
I noticed that it doesn't matter if the CPU has 99% usage or 1%, or if there are other processes executing at the same time. I didn't find any pattern with these events. It just happens sometimes (almost every day with one or two steps).
Has anyone experienced this? I don't know what to do; I made a job to kill the process and execute it again if it hangs in SOS_SCHEDULER_YIELD for a long time, but I'd like to have a solution.
Thanks.

scheduling SQL jobs one after other

I have two jobs at same time Let say a and b....
I need to run the jobs in a sequence
first =-----a
second=----b
both a and b scheduling times should be different so that I cant use them in single job
when I schedule them they are running parallel I required a sequence of execution.
One job every 30 minutes to do Task A starting 00:15
Other job every 30 minute do Tasks A and then B staring 00:00
If the actual requirement is that two separate activities should not take place at the same time, but that they have completely different scheduling requirements, you may be able to achieve this using an application lock.
This would require that all activity for each job happens within a single stored procedure (or, in some other way, is forced to use a single database session).
At the start of each activity, the code would call sp_getapplock, something like:
EXEC sp_getapplock N'D1852F12-F213-4BD3-A87C-10FB56506EF8',
N'Exclusive',
N'Session'
(Ideally, the lock is released afterwards using sp_releaseapplock)

Does oracle database start new job (from 'Scheduler') before last job (this same) is finished?

What happens if oracle database starts job(from 'Scheduler') before last job(this same) finishes? Does oracle add it to a stack or finally stops?
Oracle is smart enough to know not to start a new job instance before the previous job is finished.
From the Oracle docs:
http://docs.oracle.com/cd/B19306_01/server.102/b14231/scheduse.htm
Setting the Repeat Interval
...
Immediately after a job is started, the repeat_interval is evaluated to determine the next scheduled execution time of the job. It is possible that the next scheduled execution time arrives while the job is still running. A new instance of the job, however, will not be started until the current one completes.