From 0dabf7476e795be1b8515416e455acf1a1c6b91d Mon Sep 17 00:00:00 2001 From: Noah del Angel Date: Mon, 27 Jul 2026 22:08:54 -0500 Subject: [PATCH] perf: Postgres storage tuning for app_attest hot tables Reduce bloat on the three high-churn tables in the app_attest database. - challenges: lower autovacuum_vacuum_scale_factor 0.2 -> 0.05 and raise autovacuum_vacuum_cost_limit to 2000, so autovacuum reclaims the dead rows from the per-request insert+delete churn sooner and faster. - public_keys: set fillfactor=85 (plus scale_factor 0.05) so the per-request counter/updated_at UPDATEs stay hot - mlpa_user_capacity: set fillfactor=70 and raise the autovacuum threshold to 1000 (scale_factor 0) so the single hot row's updates stay HOT on one page and we stop over-vacuuming a one-row table --- ..._tune_autovacuum_and_fillfactor_on_app_.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 alembic/versions/b3ea148a6d0b_tune_autovacuum_and_fillfactor_on_app_.py diff --git a/alembic/versions/b3ea148a6d0b_tune_autovacuum_and_fillfactor_on_app_.py b/alembic/versions/b3ea148a6d0b_tune_autovacuum_and_fillfactor_on_app_.py new file mode 100644 index 00000000..de18aaa2 --- /dev/null +++ b/alembic/versions/b3ea148a6d0b_tune_autovacuum_and_fillfactor_on_app_.py @@ -0,0 +1,71 @@ +"""Postgres storage tuning for app_attest hot tables + +Revision ID: b3ea148a6d0b +Revises: 919c4d382c42 +Create Date: 2026-07-27 + +""" + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "b3ea148a6d0b" +down_revision = "919c4d382c42" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.execute( + """ + ALTER TABLE challenges SET ( + autovacuum_vacuum_scale_factor = 0.05, + autovacuum_vacuum_cost_limit = 2000 + ) + """ + ) + op.execute( + """ + ALTER TABLE public_keys SET ( + fillfactor = 85, + autovacuum_vacuum_scale_factor = 0.05 + ) + """ + ) + op.execute( + """ + ALTER TABLE mlpa_user_capacity SET ( + fillfactor = 70, + autovacuum_vacuum_scale_factor = 0.0, + autovacuum_vacuum_threshold = 1000 + ) + """ + ) + + +def downgrade() -> None: + op.execute( + """ + ALTER TABLE mlpa_user_capacity RESET ( + fillfactor, + autovacuum_vacuum_scale_factor, + autovacuum_vacuum_threshold + ) + """ + ) + op.execute( + """ + ALTER TABLE public_keys RESET ( + fillfactor, + autovacuum_vacuum_scale_factor + ) + """ + ) + op.execute( + """ + ALTER TABLE challenges RESET ( + autovacuum_vacuum_scale_factor, + autovacuum_vacuum_cost_limit + ) + """ + )