From: Matt Corallo Date: Tue, 8 Nov 2022 00:53:41 +0000 (+0000) Subject: Set per-table autovacuum thresholds low X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=458bb038baf4092b3eea0e2da62e50247af35cdb;p=rapid-gossip-sync-server Set per-table autovacuum thresholds low Fixes #20 --- diff --git a/src/config.rs b/src/config.rs index 92d33c1..9741753 100644 --- a/src/config.rs +++ b/src/config.rs @@ -200,6 +200,13 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client) if schema <= 1 || schema > SCHEMA_VERSION { panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION); } + // PostgreSQL (at least v13, but likely later versions as well) handles insert-only tables + // *very* poorly. After some number of inserts, it refuses to rely on indexes, assuming them to + // be possibly-stale, until a VACUUM happens. Thus, we set the vacuum factor really low here, + // pushing PostgreSQL to vacuum often. + // See https://www.cybertec-postgresql.com/en/postgresql-autovacuum-insert-only-tables/ + let _ = client.execute("ALTER TABLE channel_updates SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await; + let _ = client.execute("ALTER TABLE channel_announcements SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await; } /// EDIT ME