FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

db: index `blocks(height)` references by JssDWt · Pull Request #9450 · ElementsProject/lightning · GitHub

db: index blocks(height) references - #9450

Open
JssDWt wants to merge 1 commit into
ElementsProject:masterfrom
JssDWt:jssdwt-missing-indices
Open

db: index blocks(height) references#9450
JssDWt wants to merge 1 commit into
ElementsProject:masterfrom
JssDWt:jssdwt-missing-indices

Conversation

JssDWt commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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.

Tested on a production node running into the issue described above (fixes it).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL