How to find the start time of query in the database

  • I am creating a stored procedure to identify, and kill a long running Business Objects query in the SQL Server database. I am able to identify the BO SQL iin the database with the BO user id, and also able to check the status "RUNNABLE" in sys_processes table, but last_batch column keeps updating timestamp for EACH REQUEST sent to the DB for the same BO query. Hence, I am unable to identify the start time, and to find out how long the BO SQL has been running. Does anyone know, how can I accomplish this ?

  • What version of SQL Server are running?

  • Check this article. See if this helps.

    http://www.sqlservercentral.com/scripts/T-SQL/66830/

  • For 2005/2008, take a look at sys.dm_exec_syessions. It will give you a basic breakdown of information for the connections in the system, including start times on the last batch. For more detailed information, take a look at sys.dm_exec_requests. That will give you very specific information about what a process is waiting for, what it's doing, what statement it's on within the batch, etc. In some cases, not all, not even most, it will also show a percent complete, but don't rely on that value in any way. It may or may not be accurate and useful.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • SQL 2005

  • This SP gets the start time of the running SQL from system table dm_exec_* and system function dm_exec_sql.

    My understanding is ->One SQL sends multiple requests to the db, the start time in dm_* tables all point to the start time of EACH REQUEST, thus at a given point of time, I am unable to determine when the SQL started.

  • My understanding is ->One SQL sends multiple requests to the db, the start time in dm_exec_* tables all point to the start time of EACH REQUEST, thus at a given point of time, I am unable to determine when the SQL started.

  • When you say SQL, do you mean an individual SQL statement? One that is currently running? I'm not entirely sure, but you may not be able to drill down to that level without capturing statements in a trace. That's one way of doing it, but you would already have to have the trace in place. You couldn't turn it on in a moment's notice.

    I'll have to test the DMV to see if it records a statement or a batch start time.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • I mean the Report SQL which is running in the db. I am trying to identify the start time of the report SQL.

  • I'm not trying to be obtuse, I just don't understand what you are referring to. Do you mean queries coming from Reporting Services?

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • Do you mean to say that report sql is being repeatedly executed (maybe from diff connections) and you want to find out when this whole thing started ?

    "Keep Trying"

  • I just validated it, you can get the start time for a statement within a batch by querying sys.dm_exec_sessions. I posted a blog entry on it here[/url].

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply