Problem
During an initial snapshot, pgstream loads table data via COPY and then builds indexes and constraints afterward (the pg_dump post-data section, restored in restoreIndicesAndConstraints at snapshot_pg_dump_restore_generator.go:281, plus the pre-data conflict-target PK/unique constraints at line 259). This deferred index build is often a significant chunk of snapshot time, and it currently runs with the target server's default session settings.
Operators today can only speed it up by configuring the target server (ALTER ROLE … SET, PGOPTIONS, or ?options= on the connection URL). All of those require touching the database/role rather than pgstream config.
We should let pgstream apply index-build tuning itself, scoped to just that phase.
Proposed solution
Prepend a configurable set of SET statements to the index/constraint dump before restoring it. Because the plain-format restore pipes the whole dump to a single psql session (pg_restore.go:80), the settings apply to every CREATE INDEX / ADD CONSTRAINT in that phase and auto-reset when the session ends.
Default settings (all tunable/disable-able):
SET maintenance_work_mem = '4GB'
SET max_parallel_maintenance_workers = 4
SET synchronous_commit = off
SET statement_timeout = 0
SET lock_timeout = 0
Requirements
Problem
During an initial snapshot, pgstream loads table data via
COPYand then builds indexes and constraints afterward (the pg_dump post-data section, restored inrestoreIndicesAndConstraintsatsnapshot_pg_dump_restore_generator.go:281, plus the pre-data conflict-target PK/unique constraints at line 259). This deferred index build is often a significant chunk of snapshot time, and it currently runs with the target server's default session settings.Operators today can only speed it up by configuring the target server (
ALTER ROLE … SET,PGOPTIONS, or ?options= on the connection URL). All of those require touching the database/role rather thanpgstreamconfig.We should let pgstream apply index-build tuning itself, scoped to just that phase.
Proposed solution
Prepend a configurable set of
SETstatements to the index/constraint dump before restoring it. Because the plain-format restore pipes the whole dump to a singlepsqlsession (pg_restore.go:80), the settings apply to everyCREATE INDEX/ADD CONSTRAINTin that phase and auto-reset when the session ends.Default settings (all tunable/disable-able):
Requirements