From 31a4eb40b2163b3f90439f820af541a7a5e4e970 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sun, 14 Jan 2024 09:33:57 +0200 Subject: [PATCH] Do not suspend compute if autovacuum is active (#6322) ## Problem Se.e https://github.com/orgs/neondatabase/projects/49/views/13?pane=issue&itemId=48282912 ## Summary of changes Do not suspend compute if there are active auto vacuum workers ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist --------- Co-authored-by: Konstantin Knizhnik --- compute_tools/src/monitor.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/compute_tools/src/monitor.rs b/compute_tools/src/monitor.rs index 1a28aab479..f09bd02664 100644 --- a/compute_tools/src/monitor.rs +++ b/compute_tools/src/monitor.rs @@ -137,6 +137,28 @@ fn watch_compute_activity(compute: &ComputeNode) { continue; } } + // + // Do not suspend compute if autovacuum is running + // + let autovacuum_count_query = "select count(*) from pg_stat_activity where backend_type = 'autovacuum worker'"; + match cli.query_one(autovacuum_count_query, &[]) { + Ok(r) => match r.try_get::<&str, i64>("count") { + Ok(num_workers) => { + if num_workers > 0 { + compute.update_last_active(Some(Utc::now())); + continue; + } + } + Err(e) => { + warn!("failed to parse autovacuum workers count: {:?}", e); + continue; + } + }, + Err(e) => { + warn!("failed to get list of autovacuum workers: {:?}", e); + continue; + } + } } Err(e) => { debug!("could not connect to Postgres: {}, retrying", e);