Skip to content

Granular object type filtering for pg to pg snapshot and streaming#735

Open
tsg wants to merge 5 commits intomainfrom
object_type_filtering
Open

Granular object type filtering for pg to pg snapshot and streaming#735
tsg wants to merge 5 commits intomainfrom
object_type_filtering

Conversation

@tsg
Copy link
Member

@tsg tsg commented Feb 22, 2026

Description

Adds granular object type filtering for both schema snapshots and DDL replication in the pg-to-pg pipeline. Users can specify which categories of database objects (tables, sequences, types, indexes, functions, views, etc.) to include or exclude, giving fine-grained control over what gets replicated.

There are 16 supported categories for filtering: tables, sequences, types, indexes, constraints, functions, views, materialized_views, triggers, event_triggers, policies, rules, comments, extensions, collations, text_search

It's worth noting that in some situations inter-dependencies between these object types might block the snapshot for completing or introducing errors. Therefore should be used with care when you know your schema well enough.

Type of Change

Please select the relevant option(s):

  • 🐛 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

  • Schema snapshot filtering — Parses pg_dump TOC headers to include/exclude object type sections during snapshot generation. Filters both the main dump and cleanup (DROP) statements. Sequences are also conditionally skipped when excluded.

  • DDL replication filtering — Evaluates incoming DDL events during WAL processing and skips execution for excluded object types. Handles mixed DDL statements (e.g., CREATE TABLE with a PRIMARY KEY creates both table and index objects) by only skipping when all objects in the event are excluded.

  • Configuration — Supports both include_object_types (allowlist) and exclude_object_types (denylist) modes, enforcing mutual exclusivity. Available via YAML config and environment variables for both snapshot and DDL replication independently.

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

@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/cmd/config 84.58% (+0.20%) 👍
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore 89.51% (+0.39%) 👍
github.com/xataio/pgstream/pkg/stream/integration 0.00% (ø)
github.com/xataio/pgstream/pkg/wal/processor/postgres 79.23% (+0.33%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/cmd/config/config_env.go 90.75% (+0.17%) 227 (+4) 206 (+4) 21 👍
github.com/xataio/pgstream/cmd/config/config_yaml.go 89.69% (+0.11%) 194 (+2) 174 (+2) 20 👍
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore/object_type_filter.go 98.25% (+98.25%) 57 (+57) 56 (+56) 1 (+1) 🌟
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator.go 82.65% (-0.46%) 317 (+15) 262 (+11) 55 (+4) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres/config.go 0.00% (ø) 3 0 3
github.com/xataio/pgstream/pkg/wal/processor/postgres/ddl_object_type_filter.go 100.00% (+100.00%) 38 (+38) 38 (+38) 0 🌟
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_adapter.go 52.94% (-7.06%) 34 (+4) 18 16 (+4) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_writer.go 37.14% (ø) 35 13 22

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore/object_type_filter_test.go
  • github.com/xataio/pgstream/pkg/stream/integration/helper_test.go
  • github.com/xataio/pgstream/pkg/stream/integration/pg_pg_object_type_filter_integration_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/ddl_object_type_filter_test.go

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.

2 participants