I am trying to optimize an SQL process using the dmv ([sys].[dm_os_wait_stats]).
Is there any way that we can see the waiting/suspended queries between a time period in the past?. Like want to have records only from 3pm today.
Currently I clean the instance every time before running the process using
DBCC SQLPERF ('sys.dm_os_wait_stats', CLEAR);
GO
I suggest that using monitoring tools such as Idera or Redgate monitor in order to monitor sql server waiting. You can also copy ([sys].[dm_os_wait_stats]) data in other table periodically.
Related
I am developing a custom system for scheduling task & I am following Microsoft SQL Server Agent approach to schedule task.
I have replicated sysschedules table for capturing users scheduling occurrences and timings.
Now I need to know how SQL Server get the Next_run_date and time from this table.
I have found a solution on the internet which are using sysjobhistory table to get the next run date, but in my case, I have an only sysschedules table. So, what is the formula to calculate the next_run_date and time for any job?
Note: I am looking for entire code, concept/algorithm will work for me.
I have a sql job who does some calculation in every 15 minutes.
Now i want to monitor this job. To check if that job is currently running and if yes then its been running for more than 10 minutes.
If it's running for more than 10 minutes then i want to stop/kill this job.
Is there any query available to do it?
Tried
EXEC msdb.dbo.sp_stop_job N'job name'
And it worked!
My best guess is you need SMO (SQL Server Management Objects) to pull this off. In particular take a look at the Job Class.
I'm using microsoft SQL server management studio 2005
I'm trying to run a job at a specific time and that time is stored in a database.
I can't insert the schedule manually because it is up to the user to decide what date and time the job(s) has to be done. php collects the time and date and sends it to a database.
I thought about runing a job every min and in my execution I have an if statement that only activates when the datetime stored in the database is one minute greater or lower than the current datetime. but doing it like this would be inaccurate and very inefficient. would it be possible to create a schedule directly from a query or job?
You can create and modify both jobs and schedules programmatically using SMO or TSQL. That means you can use an external application, a stored procedure or a trigger to create or update a job schedule based on the table data. SMO is probably the best way to go if you want to build an application to manage jobs, but on the other hand it's .NET only.
Is it possible to make Job Schedule, which will occur every less than 10 seconds?
Because Sql server doesn't allow that.
Schedule type is "Recurring" and Occurs "Daily".
Select occurs Daily and run every 10 seconds. Although keep in mind if your job takes longer than the time specified to run, the agent won't invoke it again until the running task completes.
See comments below. The UI tool doesn't allow input for less than 10 seconds. In your case you could schedule two job tasks offset by some number of seconds. The issue then is that the jobs could overlap as they are distinct tasks as far as SQL Agent knows.
I tried do something similar (SQL Server job with prcise timing), but the only reliabile way I found was custom windows service execution SQL statements.
Is it possible to start a query that will take a significant amount of time and monitor progress from the UI via Ajax?
I considered starting the process as a "run once" job that is scheduled to run immediately. I could store the results in a temporary table for quick retrieval once it's complete. I could also log the run time of the report and average that out, to guestimate the running time for the progress bar.
I use Microsoft SQL 2005 at the moment, but I'm willing to other DBMS such as SQL 2008, MySQL, etc if necessary.
One idea, if the long running job populates another table.
You have a 2nd database connection to monitor how many rows are processed out of the source rows, and show a simple "x rows processed" every few second
SELECT COUNT(*) FROM TargetTable WITH (NOLOCK)
If you have a source table too:
SELECT COUNT(*) FROM SourceTable WITH (NOLOCK)
..then you can use "x of y rows processed"
Basically, you have to use a 2nd connection to monitor the first. However, you also need something to measure...