db: index blocks(height) references - #9450
Open
JssDWt wants to merge 1 commit into
Open
Conversation
Postgres doesn't index the referencing side of a foreign key, so every row deleted from `blocks` scans `transactions`, `channeltxs` and `outputs` in full. Postgres was taking 100% CPU for multiple minutes, causing startup timeouts in systemd. 247aa13 and 50a8e32 added indices for `outputs` and `utxoset` in 2018. `channeltxs` (28feb2e) and `transactions` (0f89653) arrived weeks later without one. `outputs` is only half-covered: `output_height_idx` is (`confirmation_height`, `spend_height`), which doesn't serve a lookup on `spend_height` alone. Changelog-Fixed: db: much faster startup on postgres nodes with large `transactions` or `channeltxs` tables.
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.
Postgres doesn't index the referencing side of a foreign key, so every row deleted from
blocksscanstransactions,channeltxsandoutputsin full. Postgres was taking 100% CPU for multiple minutes, causing startup timeouts in systemd.247aa13 and 50a8e32 added indices for
outputsandutxosetin2018.
channeltxs(28feb2e) andtransactions(0f89653) arrived weeks later without one.outputsis only half-covered:output_height_idxis (confirmation_height,spend_height), which doesn't serve a lookup onspend_heightalone.Changelog-Fixed: db: much faster startup on postgres nodes with large
transactionsorchanneltxstables.Tested on a production node running into the issue described above (fixes it).