Thursday, June 17, 2010

MOM - Query System Center Reporting Pruning Info

I created this query to identify how much work was needed to prune the database and what space would be gained. This is my first step to an automated pruning job that would always keep the database within the limits of the disk(s) it sits on.


CODE SNIPPIT:

DECLARE @OldestDate DateTime
DECLARE @NewestDate DateTime
DECLARE @DaysStored INT
SELECT @OldestDate = min(LocalDateTimeGenerated)
,@NewestDate = max(LocalDateTimeGenerated)
,@DaysStored = DATEDIFF(day,@OldestDate,@NewestDate)
FROM dbo.SC_EventFact_Table


--SELECT @OldestDate,@NewestDate,@DaysStored

select t1.*
,t2.TableName
,t3.PropertyName AS [ColumnName]
,t5.rowcnt AS [Rows]
,t5.rowcnt/@DaysStored AS [RowsPerDay]
,t5.reservedMB AS [SizeMB]
,t5.reservedMB/@DaysStored AS [SizeMBPerDay]
,@DaysStored-T1.GroomDays AS [DaystoGroom]
,(@DaysStored-T1.GroomDays)
* (t5.reservedMB/@DaysStored) AS [SizeMBtoGroom]

From dbo.SMC_Meta_WarehouseClassSchema t1
join dbo.SMC_Meta_ClassSchemas t2
on t2.classid = t1.classid
left join dbo.SMC_Meta_ClassProperties t3
on t3.classid = t1.classid
left join dbo.SMC_Meta_WarehouseClassProperty t4
on t4.ClassPropertyID = t3.ClassPropertyID

left join (
select object_name(id) TableName
,max(rowcnt) rowcnt
,sum(reserved)*8/1024 reservedMB
From sysindexes
GROUP BY id
) t5
on t5.TableName = T2.TableName

WHERE t4.IsGroomColumn = 1
order by t5.rowcnt desc

No comments:

Post a Comment