I have a stored procedure with out sys_refcursor return type. My requirement is to get the start and end time of execution of this stored procedure. how can I do that ?
The starttime should capture when procedure was called.
The endtime sould capture when procedure returned the response.
PS:- my requirement is not to print it on console as :-
dbms_output.put_line ('start procedure: ' || to_char(systimestamp, 'HH24:MI:SS.FF6'));
thanks
If you are using MSSQL then you can track with MS SQL Profiler with procedure name filter. and for mysql, you can enable the log from configuration.
Always procedure execution time doesn't help to us for better performance. Need to focus on commit/rollback or connection close time as well.
Related
I would like to measure the execution time of a stored procedure in Oracle. I have learned about the technique of writing an entry in a temporary logging table at the start and the end but am unable to use this technique.
Can you refer me to an open source/free tool with which I'm able to do this?
Thanks!
The answer depends on your environment you are using.
If you are using SQLPlus, you can enable a timer as follows :t
SQL> set timing on
Then, just execute your procedure, like :
SQL> exec my_procedure;
When the procedure will complete, a summary line will be displayed, like :
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.05
From within PL/SQL, you can use dbms_utility.get_time :
DECLARE
start_time pls_integer;
BEGIN
start_time := dbms_utility.get_time;
exec my_procedure;
dbms_output.put_line((dbms_utility.get_time - start_time)/100 || ' seconds');
END;
/
Should output something like :
3 seconds
PL/SQL procedure successfully completed.
See this excellent explanation from Tom Kyte.
Execution of the stored procedure's start /end time can be logged using
DBMS_UTILITY.get_cpu_time or DBMS_UTILITY.get_time
E.g.
CREATE OR REPLACE PROCEDURE test_proc IS
BEGIN
DBMS_OUTPUT.put_line('start time '||DBMS_UTILITY.get_time);
<your statement>
DBMS_OUTPUT.put_line('end time '||DBMS_UTILITY.get_time);
END;
There are of course other ways of finding the execution time using Profiler
Have a look at this as well
If you want to get details that can actually help you diagnose issues, I highly recommend dbms_profiler.
It is easy to use and provides statistics for every line in the pl/sql including number of executions, total time, min and max.
How can I run SQL Server stored procedures one after another in sequence?
I would like the procedure to wait for termination before the next one is executed.
I am using SQL Server 2008
Do you mean like described here?
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/00ab0007-e46f-4047-b758-e0ab1c56e84c
I want to know that is there any way through which I can execute all my stored procedure at a time.
Presently I am executing each stored procedure using exec "Stored Procedure name" command.
And I have more than 200 stored procedure to be executed on my database.
Is there any easy way out to execute all these stored procedure at a single time as it is difficult for me to keep a track of them?
I suggest you write a stored procedure which calls the other ones.
Put all stored procedures inside a stored procedure,
CREATE PROCEDURE CallAllProcedure
AS
BEGIN
CALL Proc1
CALL Proc2
END
Assuming that you are using Query Analyzer, just put a GO in between all those stored proc and run script.
If you want to execute them all in parallel you could create a SQLJob and schedule them all to execute at the same time. Link below is general usage of SQL Jobs.
http://msdn.microsoft.com/en-us/library/ms190268.aspx
you can select all stored procedure names from sys.objects table querying type='P'. After you can use cursor for every stored procedure name to execute. But how about stored procedures with parameters? you must provide parameter values as well to avoid from errors.
You can use Service broker to do this async but I dont think it is a great idea to run 200 stored procs at the same time unless you are sure there will not be any contention on the DB
I want to make my stored procedure re-runnable.
If it started and run partial way and failed because of a reason, it should be re-runnable.
Please suggest some ways to do that.
Thanks !
You can create a JOB and trigger it in the stored procedure.
Specify the retry times and the retry interval on the Step (work) that you want to re-run.
here's a reference on how to start a Job.
http://www.mssqltips.com/sqlservertip/1730/different-ways-to-execute-a-sql-agent-job/
If you just need to execute your stored procedure from beginning after failure, you can catch the failrue (using TRY .. CATCH or ##ERROR) and then redirect the execution to the begin of the stored procedure using GOTO
I have a stored procedure that takes a lot of time to execute. We want it to execute during the night, but it has to check for the current time every now and then, and at a given time it has to stop executing. How do I do that? Please provide me with the code I can use in my stored procedure. We are using Microsoft SQL Server 2005.
You can get the current date:
SELECT GETDATE()
Stop executing:
If #date > GETDATE()
RETURN --Exits procedure
Where #date is the date/time when you want to stop executing
Create Maintenance plan and sprecify start time for it. Create "Execute T-SQL statement task" in this plan and specify execution timeout for it (in seconds).
Why woudl you want to exist a proc that is not finished? Wouldn't you be leaving things in a bad state as far as data integrity or rolling back all the work you just did??
Wouldn't it be a better solution to try to improve the performance of the proc?