Search code examples
sql-serverssas

Is it possible to execute DMV queries between certain time periods?


We have a DMV query that executes every 10 mins and inserts usage statistics, like SESSION_CURRENT_DATABASE, SESSION_LAST_COMMAND_STARTTIME, etc.. and supposedly has been running fine for the last 2 years.

Today we were notified by data hyperingestion team that the last records shown were from 6/10. So we found out the job has been stuck for 14 days not executing new statistics since. We've immediately restarted the job and it's been executing successfully since the morning, but basically we've lost the data during this 14 days period. Is there a way for us to execute this DMV query between 6/10-6/24 on the $SYSTEM.DISCOVER to recover these past 14 days of data?

Or all hope's lost?

DMV query:

SELECT [SESSION_ID]
      ,[SESSION_SPID]
      ,[SESSION_CONNECTION_ID]
      ,[SESSION_USER_NAME]
      ,[SESSION_CURRENT_DATABASE]
      ,[SESSION_USED_MEMORY]
      ,[SESSION_PROPERTIES]
      ,[SESSION_START_TIME]
      ,[SESSION_ELAPSED_TIME_MS]
      ,[SESSION_LAST_COMMAND_START_TIME]
      ,[SESSION_LAST_COMMAND_END_TIME]
      ,[SESSION_LAST_COMMAND_ELAPSED_TIME_MS]
      ,[SESSION_IDLE_TIME_MS]
      ,[SESSION_CPU_TIME_MS]
      ,[SESSION_LAST_COMMAND_CPU_TIME_MS]
      ,[SESSION_READS]
      ,[SESSION_WRITES]
      ,[SESSION_READ_KB]
      ,[SESSION_WRITE_KB]
      ,[SESSION_COMMAND_COUNT]
FROM $SYSTEM.DISCOVER_SESSIONS

Solution

  • I wouldn't say it's "gone" unless the instance has been restarted or the db has been detached. For example, the dmv for procedure usage should still have data in it, but you won't be able to specifically recreate what it looked like 10 days ago.

    You can get a rough idea by looking back through the 2 years of data you already have, and get a sense of if there are spikes or consistent usage. Then, grab a snapshot of the DMV today, and extrapolate it back 14 days to get a rough idea of what usage was like.