Skip to content

Commit 458bb03

Browse files
committed
Set per-table autovacuum thresholds low
Fixes lightningdevkit#20
1 parent 7263bf5 commit 458bb03

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client)
200200
if schema <= 1 || schema > SCHEMA_VERSION {
201201
panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION);
202202
}
203+
// PostgreSQL (at least v13, but likely later versions as well) handles insert-only tables
204+
// *very* poorly. After some number of inserts, it refuses to rely on indexes, assuming them to
205+
// be possibly-stale, until a VACUUM happens. Thus, we set the vacuum factor really low here,
206+
// pushing PostgreSQL to vacuum often.
207+
// See https://www.cybertec-postgresql.com/en/postgresql-autovacuum-insert-only-tables/
208+
let _ = client.execute("ALTER TABLE channel_updates SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await;
209+
let _ = client.execute("ALTER TABLE channel_announcements SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await;
203210
}
204211

205212
/// EDIT ME

0 commit comments

Comments
 (0)