Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Retention Period for Queries Executed Expand / Collapse
Author
Message
Posted Monday, October 22, 2012 4:54 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2014 5:21 PM
Points: 3, Visits: 64
Hi Guys,

On Fri. 10/19 I had a process that was in a suspended status because it was blocked by another SPID. Is there any way to determine whether or not that process was executed successfully?

I queried a list of the current process and filtered it by adding a range for dates I wanted in the output - but the history didn't go as far back as I wanted. Is there a way to see what the retention period is for executed queries?

I used the following query:

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
WHERE deqs.last_execution_time
Between '2012-10-17' and '2012-10-22'
ORDER BY deqs.last_execution_time DESC

Can you guys please help me - is this query the correct way to pull a history on executed queries? Also, I have the exact SQL Statement that I'm looking for - is there a way to perhaps search by the query?
Post #1375781
Posted Tuesday, October 23, 2012 3:13 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 3, 2014 8:05 AM
Points: 1,191, Visits: 9,892
sys.dm_exec_query_stats
Returns aggregate performance statistics for cached query plans in SQL Server 2012. The view contains one row per query statement within the cached plan, and the lifetime of the rows are tied to the plan itself. When a plan is removed from the cache, the corresponding rows are eliminated from this view.


There's no set retention. It depends on memory pressure and how many other queries are executed as to when it will get pushed out of the plan cache.
Post #1375922
Posted Tuesday, October 23, 2012 3:21 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053
What you're querying there is not a history of queries executed, it's the plan cache which contains some info on execution history. Plans that aren't cached don't appear in there, it's cleared any time SQL restarts or the database restarts, plans can be removed or replaced for a variety of reasons.

If you need a history of queries executed, set up an extended events or SQL Trace session (warning, it'll be huge volumes of data)



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1375925
Posted Tuesday, October 23, 2012 1:03 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 11, 2014 5:21 PM
Points: 3, Visits: 64
Thank you, HowardW and Gail - you've been very helpful.
Post #1376213
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse