Restore indexes in parallel during pg2pg schema snapshot - #1144
Conversation
tier |
CoverageTotal: 61.3% (+0.1% vs Coverage in packages changed by this PR:
|
8d3ac48 to
53d5822
Compare
c64763b to
8354fcb
Compare
8354fcb to
4657a70
Compare
xata-bot
left a comment
There was a problem hiding this comment.
✅ Approved by the pgstream review agent.
The change is well-scoped, defaults preserve the exact prior sequential behaviour (workers<=1 short-circuits to the original code path, and WithRestoreToWAL forces workers back to 1), the worker cap is validated at startup before any connections are opened, error classification across concurrent index restores is merged correctly via MergePGRestoreErrors (verified against addError/IsRetryable/HasCriticalErrors semantics), and the block-splitting/ordering logic (partitionDumpBlocks, joinDumpBlocks) mirrors the pre-existing splitConflictTargetConstraints pattern with added defensive statement separators, backed by extensive unit/integration tests including a real pg_dump fixture covering exotic index shapes.
tier T1-agent · 8 files / 280 substantive lines · risk medium. This is an automated review and does not replace human judgement on anything it escalates.
Description
Index restore during a pg-to-pg schema snapshot runs as a single sequential
psqlsession, so a schema with many indexes builds them one at a time even thoughCREATE INDEXstatements have no dependencies on each other.This adds an opt-in
index_restore_workerssetting that restores the standaloneCREATE INDEX/CREATE UNIQUE INDEXstatements concurrently. Everything that can depend on an index existing (constraints addedUSING INDEX, comments, partition attachments,REPLICA IDENTITY,CLUSTER) is still restored afterwards, once every index has been created, preserving the original relative order.It defaults to 1, which is byte-for-byte the previous sequential behaviour, so nothing changes for existing users until they opt in.
Improvement:
Measured locally.
Type of Change
Please select the relevant option(s):
Changes Made
IndexRestoreWorkersto the pgdump/pgrestore snapshot config, wired through YAML (index_restore_workers) and env (PGSTREAM_POSTGRES_SNAPSHOT_INDEX_RESTORE_WORKERS)CREATE INDEXones through a boundederrgroup, then restore the rest sequentially.PGRestoreErrors, so the retry decision is taken over the whole wave rather than over whichever error arrived firstTesting
Checklist
Additional Notes