fix(node): tune autovacuum on db-sync hot tables for stable query plans#1434
Merged
Merged
Conversation
Lower autovacuum_analyze_scale_factor from the postgres default of 0.1 to 0.01 on the cardano-db-sync tables midnight-node queries (block, tx, tx_out, tx_in, ma_tx_out, datum). The default 10% growth threshold means autoanalyze never fires for big append-heavy tables, leaving the planner on stale statistics and producing extreme worst-case plans (observed >400s queries on otherwise idle preview/preprod DBs) for the cnight-observation lookups. Applied alongside the existing index creation in create_cnight_observation_indexes, idempotent. Refs: #1298 Signed-off-by: Scott Buckel <scott.buckel@shielded.io>
Signed-off-by: Justin Frevert <justinfrevert@gmail.com>
justinfrevert
approved these changes
Apr 28, 2026
justinfrevert
left a comment
Contributor
There was a problem hiding this comment.
Nice improvement! Appreciate the additional testing done as well.
m2ux
pushed a commit
that referenced
this pull request
Apr 28, 2026
…ns (#1434) * fix(node): tune autovacuum on db-sync hot tables for stable query plans Lower autovacuum_analyze_scale_factor from the postgres default of 0.1 to 0.01 on the cardano-db-sync tables midnight-node queries (block, tx, tx_out, tx_in, ma_tx_out, datum). The default 10% growth threshold means autoanalyze never fires for big append-heavy tables, leaving the planner on stale statistics and producing extreme worst-case plans (observed >400s queries on otherwise idle preview/preprod DBs) for the cnight-observation lookups. Applied alongside the existing index creation in create_cnight_observation_indexes, idempotent. Refs: #1298 Signed-off-by: Scott Buckel <scott.buckel@shielded.io> * change file Signed-off-by: Justin Frevert <justinfrevert@gmail.com> --------- Signed-off-by: Scott Buckel <scott.buckel@shielded.io> Signed-off-by: Justin Frevert <justinfrevert@gmail.com> Co-authored-by: Justin Frevert <justinfrevert@gmail.com>
gilescope
pushed a commit
that referenced
this pull request
Apr 29, 2026
…ns (#1434) * fix(node): tune autovacuum on db-sync hot tables for stable query plans Lower autovacuum_analyze_scale_factor from the postgres default of 0.1 to 0.01 on the cardano-db-sync tables midnight-node queries (block, tx, tx_out, tx_in, ma_tx_out, datum). The default 10% growth threshold means autoanalyze never fires for big append-heavy tables, leaving the planner on stale statistics and producing extreme worst-case plans (observed >400s queries on otherwise idle preview/preprod DBs) for the cnight-observation lookups. Applied alongside the existing index creation in create_cnight_observation_indexes, idempotent. Refs: #1298 Signed-off-by: Scott Buckel <scott.buckel@shielded.io> * change file Signed-off-by: Justin Frevert <justinfrevert@gmail.com> --------- Signed-off-by: Scott Buckel <scott.buckel@shielded.io> Signed-off-by: Justin Frevert <justinfrevert@gmail.com> Co-authored-by: Justin Frevert <justinfrevert@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lower autovacuum_analyze_scale_factor from the postgres default of 0.1 to 0.01 on the cardano-db-sync tables midnight-node queries (block, tx, tx_out, tx_in, ma_tx_out, datum). The default 10% growth threshold means autoanalyze never fires for big append-heavy tables, leaving the planner on stale statistics and producing extreme worst-case plans (observed >400s queries on otherwise idle preview/preprod DBs) for the cnight-observation lookups.
Applied alongside the existing index creation in
create_cnight_observation_indexes, idempotent.
Refs: #1298
Overview
🗹 TODO before merging
📌 Submission Checklist
git commit -s) for the DCO🧪 Testing Evidence
Mainnet sync — before vs after autovacuum tuning
Before (default
autovacuum_analyze_scale_factor = 0.1oncexplorer_mainnet, schema otherwise identical, all indexes fromcreate_cnight_observation_indexespresent):beststuck at #27 for many intervals; one query took 432 s.pg_stat_user_tablesshowedtx_outandma_tx_outhad never been autoanalyzed — last_autoanalyze NULL, analyze_count=1 from initial schema load.After (this PR's tuning applied via
ALTER TABLE+ one-shotvacuumdb --analyze-onlyto backfill stats):bestadvanced from #66933 → #72402 in 2 minutes — ~5500 blocks / 120 s ≈ 46 bps sustained vs 0.0 before. Oneslow statementwarning across the entire run, and that one was 2.6 s rather than 400+ s.Tracking
Please describe any additional testing aside from CI:
🔱 Fork Strategy
Links