Skip to content

feat(snapshot): add index restore session settings#990

Open
jonasHanhan wants to merge 2 commits into
xataio:mainfrom
jonasHanhan:feat/index-constraint-session-settings
Open

feat(snapshot): add index restore session settings#990
jonasHanhan wants to merge 2 commits into
xataio:mainfrom
jonasHanhan:feat/index-constraint-session-settings

Conversation

@jonasHanhan

@jonasHanhan jonasHanhan commented Jul 10, 2026

Copy link
Copy Markdown

Description

Adds configurable PostgreSQL session settings for the pg_dump/pg_restore index and constraint restore phase. Settings use a readable name=value list and are passed to PostgreSQL through PGOPTIONS only for direct index/constraint restores. Empty configuration preserves the current behavior, and WAL restore deliberately skips the settings.

Related Issue(s)

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Changes Made

  • Add YAML list and space-separated environment configuration for index/constraint restore session settings.
  • Pass the settings through PGRestoreOptions and apply them with PGOPTIONS=-c name=value, preserving existing PGOPTIONS.
  • Keep the SQL dump unchanged, scope settings to index/constraint restore sessions, and leave WAL restore unaffected.
  • Document the configuration with the suggested PostgreSQL tuning values.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

Additional Notes

Validation completed on the latest main with:

  • make generate
  • make test
  • golangci-lint v2.10.1 (0 issues)
  • PostgreSQL 14 manual restore-session check confirming all configured values and successful index creation

Comment thread cmd/config/test/test_config.env Outdated
PGSTREAM_POSTGRES_SNAPSHOT_NO_PRIVILEGES=true
PGSTREAM_POSTGRES_SNAPSHOT_EXCLUDED_SECURITY_LABELS="anon"
PGSTREAM_POSTGRES_SNAPSHOT_REFRESH_MATERIALIZED_VIEWS=true
PGSTREAM_POSTGRES_SNAPSHOT_INDEX_CONSTRAINT_SESSION_SETTINGS='{"maintenance_work_mem":"4GB","max_parallel_maintenance_workers":"4","synchronous_commit":"off","statement_timeout":"0","lock_timeout":"0"}'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change the format of this configuration. It would be more readable to set options like this so the setting:

mainteanance_work_mem=4GB max_parallel_maintenance_workers=4


var sessionSettingNamePattern = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$`)

func buildSessionSettingsDump(settings map[string]string) ([]byte, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of constructing the SET statements, we could pass the options to PostgreSQL using PGOPTIONS. RunPGRestore already uses psql, so we can pass the options easily.

@kvch kvch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! I have requested some changes. Let me know if you need more details.

@jonasHanhan
jonasHanhan force-pushed the feat/index-constraint-session-settings branch from de0b12c to 7d0a679 Compare July 15, 2026 06:03
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.

Apply tunable session settings during the snapshot index/constraint build phase

2 participants