From a69fc657f2bc392867ee67ad8985ba41f95230eb Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 23 Apr 2024 15:01:56 +0300 Subject: [PATCH] chore(coderd/database): reduce dbpurge load with smaller batches of agent stats (#13049) --- coderd/database/queries.sql.go | 8 ++++---- coderd/database/queries/workspaceagentstats.sql | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 8594436116..41171a7473 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -10132,11 +10132,11 @@ WHERE template_usage_stats ) AND created_at < ( - -- Delete at most in batches of 3 days (with a batch size of 3 days, we - -- can clear out the previous 6 months of data in ~60 iterations) whilst - -- keeping the DB load relatively low. + -- Delete at most in batches of 4 hours (with this batch size, assuming + -- 1 iteration / 10 minutes, we can clear out the previous 6 months of + -- data in 7.5 days) whilst keeping the DB load low. SELECT - COALESCE(MIN(created_at) + '3 days'::interval, NOW()) + COALESCE(MIN(created_at) + '4 hours'::interval, NOW()) FROM workspace_agent_stats ) diff --git a/coderd/database/queries/workspaceagentstats.sql b/coderd/database/queries/workspaceagentstats.sql index 5623fd2cf9..f96140c87c 100644 --- a/coderd/database/queries/workspaceagentstats.sql +++ b/coderd/database/queries/workspaceagentstats.sql @@ -87,11 +87,11 @@ WHERE template_usage_stats ) AND created_at < ( - -- Delete at most in batches of 3 days (with a batch size of 3 days, we - -- can clear out the previous 6 months of data in ~60 iterations) whilst - -- keeping the DB load relatively low. + -- Delete at most in batches of 4 hours (with this batch size, assuming + -- 1 iteration / 10 minutes, we can clear out the previous 6 months of + -- data in 7.5 days) whilst keeping the DB load low. SELECT - COALESCE(MIN(created_at) + '3 days'::interval, NOW()) + COALESCE(MIN(created_at) + '4 hours'::interval, NOW()) FROM workspace_agent_stats );