Skip to content

Commit db14906

Browse files
Merge pull request #461 from erikdarlingdata/feature/purge-processed-staging
Purge processed XE staging rows in retention proc
2 parents 90f0650 + 9d00629 commit db14906

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

install/43_data_retention.sql

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,55 @@ BEGIN
7878
RAISERROR(N'Starting data retention: keeping data newer than %s', 0, 1, @retention_date_string) WITH NOWAIT;
7979
END;
8080

81+
/*
82+
Purge processed XE staging rows early.
83+
After parsers set is_processed = 1 the raw XML is never read again.
84+
Keep a 1-day grace period for re-parsing failures.
85+
*/
86+
DECLARE
87+
@staging_deleted bigint = 0;
88+
89+
IF OBJECT_ID(N'collect.deadlock_xml', N'U') IS NOT NULL
90+
AND EXISTS
91+
(
92+
SELECT
93+
1/0
94+
FROM sys.columns AS c
95+
WHERE c.object_id = OBJECT_ID(N'collect.deadlock_xml')
96+
AND c.name = N'is_processed'
97+
)
98+
BEGIN
99+
DELETE FROM collect.deadlock_xml
100+
WHERE is_processed = 1
101+
AND collection_time < DATEADD(DAY, -1, SYSDATETIME());
102+
103+
SET @staging_deleted += ROWCOUNT_BIG();
104+
END;
105+
106+
IF OBJECT_ID(N'collect.blocked_process_xml', N'U') IS NOT NULL
107+
AND EXISTS
108+
(
109+
SELECT
110+
1/0
111+
FROM sys.columns AS c
112+
WHERE c.object_id = OBJECT_ID(N'collect.blocked_process_xml')
113+
AND c.name = N'is_processed'
114+
)
115+
BEGIN
116+
DELETE FROM collect.blocked_process_xml
117+
WHERE is_processed = 1
118+
AND collection_time < DATEADD(DAY, -1, SYSDATETIME());
119+
120+
SET @staging_deleted += ROWCOUNT_BIG();
121+
END;
122+
123+
IF @debug = 1 AND @staging_deleted > 0
124+
BEGIN
125+
RAISERROR(N'Purged %I64d processed XE staging rows (older than 1 day)', 0, 1, @staging_deleted) WITH NOWAIT;
126+
END;
127+
128+
SET @total_deleted += @staging_deleted;
129+
81130
/*
82131
Create temp table to hold list of tables to clean
83132
*/

0 commit comments

Comments
 (0)