Skip to main content

SQL Server: Page Life Expectancy

SQL Server is having severe performance issue during testing, found out the PLE is under 500, one db session hung for 2 hours.

I use the following queries to find out what's going on:

 


Thanks to this link about query the buffer pool

https://simplesqlserver.com/2016/01/04/query-the-buffer-pool/


select * from sys.dm_os_waiting_tasks where wait_type like 'PAGE%'

--select * from sys.dm_os_waiting_tasks 

SELECT TOP 50

qs.execution_count,

AvgPhysicalReads = isnull( qs.total_physical_reads/ qs.execution_count, 0 ),

MinPhysicalReads = qs.min_physical_reads,

MaxPhysicalReads = qs.max_physical_reads,

AvgPhysicalReads_kbsize = isnull( qs.total_physical_reads/ qs.execution_count, 0 ) *8,

MinPhysicalReads_kbsize = qs.min_physical_reads*8,

MaxPhysicalReads_kbsize = qs.max_physical_reads*8,

CreationDateTime = qs.creation_time,

SUBSTRING(qt.[text], qs.statement_start_offset/2, (

 CASE

 WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.[text])) * 2

 ELSE qs.statement_end_offset

 END - qs.statement_start_offset)/2

) AS query_text,

qt.[dbid],

qt.objectid,

tp.query_plan,

tp.query_plan.exist('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/showplan";

/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/QueryPlan/MissingIndexes') missing_index_info

FROM

sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text (qs.[sql_handle]) AS qt

OUTER APPLY sys.dm_exec_query_plan(qs.plan_handle) tp

where datediff(hour,last_execution_time,getdate()) <2

ORDER BY AvgPhysicalReads DESC


--select * from sys.dm_exec_query_stats 

select * from sys.dm_os_performance_counters where counter_name like 'page%' or  counter_name like 'memory%'

IF OBJECT_ID('TempDB..#BufferSummary') IS NOT NULL BEGIN

DROP TABLE #BufferSummary

END


IF OBJECT_ID('TempDB..#BufferPool') IS NOT NULL BEGIN

DROP TABLE #BufferPool

END


CREATE TABLE #BufferPool

(

Cached_MB Int

, Database_Name SysName

, Schema_Name SysName NULL

, Object_Name SysName NULL

, Index_ID Int NULL

, Index_Name SysName NULL

, Used_MB Int NULL

, Used_InRow_MB Int NULL

, Row_Count BigInt NULL

)


SELECT Pages = COUNT(1)

, allocation_unit_id

, database_id

INTO #BufferSummary

FROM sys.dm_os_buffer_descriptors 

GROUP BY allocation_unit_id, database_id 

DECLARE @DateAdded SmallDateTime  

SELECT @DateAdded = GETDATE()  

  

DECLARE @SQL NVarChar(4000)  

SELECT @SQL = ' USE [?]  

INSERT INTO #BufferPool (

Cached_MB 

, Database_Name 

, Schema_Name 

, Object_Name 

, Index_ID 

, Index_Name 

, Used_MB 

, Used_InRow_MB 

, Row_Count 

)  

SELECT sum(bd.Pages)/128 

, DB_Name(bd.database_id)

, Schema_Name(o.schema_id)

, o.name

, p.index_id 

, ix.Name

, i.Used_MB

, i.Used_InRow_MB

, i.Row_Count     

FROM #BufferSummary AS bd 

LEFT JOIN sys.allocation_units au ON bd.allocation_unit_id = au.allocation_unit_id

LEFT JOIN sys.partitions p ON (au.container_id = p.hobt_id AND au.type in (1,3)) OR (au.container_id = p.partition_id and au.type = 2)

LEFT JOIN (

SELECT PS.object_id

, PS.index_id 

, Used_MB = SUM(PS.used_page_count) / 128 

, Used_InRow_MB = SUM(PS.in_row_used_page_count) / 128

, Used_LOB_MB = SUM(PS.lob_used_page_count) / 128

, Reserved_MB = SUM(PS.reserved_page_count) / 128

, Row_Count = SUM(row_count)

FROM sys.dm_db_partition_stats PS

GROUP BY PS.object_id

, PS.index_id

) i ON p.object_id = i.object_id AND p.index_id = i.index_id

LEFT JOIN sys.indexes ix ON i.object_id = ix.object_id AND i.index_id = ix.index_id

LEFT JOIN sys.objects o ON p.object_id = o.object_id

WHERE database_id = db_id()  

GROUP BY bd.database_id   

, o.schema_id

, o.name

, p.index_id

, ix.Name

, i.Used_MB

, i.Used_InRow_MB

, i.Row_Count     

HAVING SUM(bd.pages) > 128  

ORDER BY 1 DESC;'  


EXEC sp_MSforeachdb @SQL

select sum(Cached_MB) SumCache_MB from #BufferPool 

SELECT Cached_MB 

, Pct_of_Cache = CAST(Cached_MB * 100.0 / SUM(Cached_MB) OVER () as Dec(20,3))

, Pct_Index_in_Cache = CAST(Cached_MB * 100.0 / CASE Used_MB WHEN 0 THEN 0.001 ELSE Used_MB END as DEC(20,3))

, Database_Name 

, Schema_Name 

, Object_Name 

, Index_ID 

, Index_Name 

, Used_MB 

, Used_InRow_MB 

, Row_Count 

FROM #BufferPool 

ORDER BY Cached_MB DESC


Comments

Popular posts from this blog

Opatch apply/lsinventory error: oneoff is corrupted or does not exist

I am applying the quarterly patch for 19c RDBMS, I tried using napply but failed, but somehow it corrupted the inventory though nothing applied. further apply and lsinventory command ran into error like this: $ ./OPatch/opatch lsinventory Oracle Interim Patch Installer version 12.2.0.1.21 Copyright (c) 2020, Oracle Corporation.  All rights reserved. Oracle Home       : /u02/app/oracle/19.0.0 Central Inventory : /u01/app/oraInventory    from           : /u02/app/oracle/19.0.0/oraInst.loc OPatch version    : 12.2.0.1.21 OUI version       : 12.2.0.7.0 Log file location : /u02/app/oracle/19.0.0/cfgtoollogs/opatch/opatch2020-09-08_13-35-59PM_1.log Lsinventory Output file location : /u02/app/oracle/19.0.0/cfgtoollogs/opatch/lsinv/lsinventory2020-09-08_13-35-59PM.txt -------------------------------------------------------------------------------- Inventory load failed... OPatch cannot load inventory ...

oracle dba_hist_sysmetric_summary

found this blog is helpful to get CPU and IO statistics on oracle database. http://shob-dbadmin.blogspot.ca/2012/12/how-to-find-total-io-of-database.html courtesy to  Shomil Bansal , below are hist writing, not mine. How to find total IO of the database instance Total IO of database instance is sum of the physical reads, physical writes and redo writes. There are several views to find these values. v$sysmetric  - Reports metric values for only the most current time sample 60 secs. v$sysmetric_summary  - Reports metric values for time sample of 1 hour. v$sysmetric_history  - Reports metric values every 60 sec from the time instance is up. Better way to analyse IO using this view to take deltas between two time periods. dba_hist_sysmetric_history  - All the above views are refreshed when the instance is restarted. This view, part of AWR, stores the historical stats. I have used this view for my report. Query: ====== set lines 350...

rman delete backup without mounting db

######################################################## Description : BIDTST database is accidently dropped before it's RMAN database backups on tapes are removed. so we need to remove the backups without having BIDTST db mounted. The doc retains the error messages which help troubleshooting... Date : June 1, 2011 DBA : Jiulu Sun & Kevin Ma ######################################################## $ rman catalog rman/password@catalog target / Recovery Manager: Release 10.2.0.4.0 - Production on Thu Jun 2 15:26:52 2011 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: DUMMY (not mounted) connected to recovery catalog database RMAN> @generic_config.rman RMAN> configure channel device type sbt parms 'ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin64/tdpo_rman_agcoux043.opt)'; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMA...