Skip to content

Commit 4493dde

Browse files
authored
Merge pull request #3633 from BrentOzarULTD/3632_sp_BlitzCache_readable_secondaries
#3632 sp_BlitzCache readable replicas
2 parents 638e200 + b6ca85e commit 4493dde

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Other common parameters include:
180180
* @ExportToExcel = 1 - turn this on, and it doesn't return XML fields that would hinder you from copy/pasting the data into Excel.
181181
* @ExpertMode = 1 - turn this on, and you get more columns with more data. Doesn't take longer to run though.
182182
* @IgnoreSystemDBs = 0 - if you want to show queries in master/model/msdb. By default we hide these. Additionally hides queries from databases named `dbadmin`, `dbmaintenance`, and `dbatools`.
183+
* @IgnoreReadableReplicaDBs = 0 - if you want to analyze the plan cache on an Availability Group readable replica. You will also have to connect to the replica using ApplicationIntent = ReadOnly, since SQL Server itself will abort queries that try to do work in readable secondaries.
183184
* @MinimumExecutionCount = 0 - in servers like data warehouses where lots of queries only run a few times, you can set a floor number for examination.
184185

185186
[*Back to top*](#header1)

sp_BlitzCache.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ ALTER PROCEDURE dbo.sp_BlitzCache
256256
@DurationFilter DECIMAL(38,4) = NULL ,
257257
@HideSummary BIT = 0 ,
258258
@IgnoreSystemDBs BIT = 1 ,
259+
@IgnoreReadableReplicaDBs BIT = 1 ,
259260
@OnlyQueryHashes VARCHAR(MAX) = NULL ,
260261
@IgnoreQueryHashes VARCHAR(MAX) = NULL ,
261262
@OnlySqlHandles VARCHAR(MAX) = NULL ,
@@ -1405,7 +1406,7 @@ CREATE TABLE #plan_usage
14051406
);
14061407

14071408

1408-
IF EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
1409+
IF @IgnoreReadableReplicaDBs = 1 AND EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
14091410
BEGIN
14101411
RAISERROR('Checking for Read intent databases to exclude',0,0) WITH NOWAIT;
14111412

@@ -1824,7 +1825,7 @@ IF @VersionShowsAirQuoteActualPlans = 1
18241825

18251826
SET @body += N' WHERE 1 = 1 ' + @nl ;
18261827

1827-
IF EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
1828+
IF @IgnoreReadableReplicaDBs = 1 AND EXISTS (SELECT * FROM sys.all_objects o WHERE o.name = 'dm_hadr_database_replica_states')
18281829
BEGIN
18291830
RAISERROR(N'Ignoring readable secondaries databases by default', 0, 1) WITH NOWAIT;
18301831
SET @body += N' AND CAST(xpa.value AS INT) NOT IN (SELECT database_id FROM #ReadableDBs)' + @nl ;

0 commit comments

Comments
 (0)