Technical Article

Average Page Life Expectancy

,

Page Life Expectancy

For those of you not familiar with Page Life Expectancy (PLE), this is the length of time that a database page will stay in the buffer cache without references. Microsoft recommends a minimum target of 300 seconds for PLE, which is roughly (5) minutes. I have to admit that even in my own environment, we rarely see PLE more than (3) to (4) minutes.

I wondered what would the average DBA do in a situation where they do not have the luxury of using a 3rd party monitoring tool to capture (PLE)? In this post I decided to share a useful script that I wrote that will sample the DMV sys.dm_os_performance_counters table to provide an average PLE captured in (1) minute intervals. I hope this query will prove useful for those DBA's that do not have a 3rd party monitoring tool, or find themselves in a situation where they can only rely on a query to give them the results.

/****************************************************************************** 
NOTES: 
 This script provides a sampling of PLE based on (1) minute intervals from 
 sys.dm_os_performance_counters. Originally written on November 11, 2010 
 by Tim Parker.
*******************************************************************************/ 


DECLARE @counter INT --This will be used to iterate the sampling loop for the PLE measure. 

SET @counter = 0 

CREATE TABLE #pleSample
 (
 CaptureTime DATETIME,
 PageLifeExpectancy BIGINT
 ) 

WHILE @counter < 30 --Sampling will run approximately 1 minute. 
 BEGIN 
 --Captures Page Life Expectancy from sys.dm_os_performance_counters 
 INSERT INTO #pleSample
 (
 CaptureTime,
 PageLifeExpectancy 
 )

 SELECT CURRENT_TIMESTAMP,
 cntr_value
 FROM sys.dm_os_performance_counters
 WHERE [object_name] = N'SQLServer:Buffer Manager'
 AND counter_name = N'Page life expectancy'

 SET @counter = @counter + 1 
 WAITFOR DELAY '000:00:02'

 END 


--This query will return the average PLE based on a 1 minute sample. 
SELECT RIGHT(CONVERT(VARCHAR(24), DATEADD(SECOND, AVG(PageLifeExpectancy), 0), 113),12) AS 'Average Page Life Expectancy'
FROM #pleSample 


DROP TABLE #pleSample

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating