Skip to content

Fix replication errors with tables containing generated columns - #592

Merged
mason-sharp merged 1 commit into
v5_STABLEfrom
v5-generated-backport
Aug 21, 2026
Merged

Fix replication errors with tables containing generated columns#592
mason-sharp merged 1 commit into
v5_STABLEfrom
v5-generated-backport

Conversation

@danolivo

Copy link
Copy Markdown
Contributor

PostgreSQL generated columns (GENERATED ALWAYS AS ... STORED) were causing errors during Spock replication. The issue occurred because generated columns were being treated as regular columns during:

  • Initial table synchronization (COPY operations)
  • Logical replication protocol messages
  • Default value filling for missing attributes
  • Conflict resolution and tuple processing

Generated columns should not be replicated since they are computed automatically on the target database based on their definition.

Solution:
Add checks for attgenerated flag alongside existing attisdropped checks throughout the codebase to skip generated columns in:

  • spock_sync.c: COPY attribute list construction
  • spock_apply_heap.c: Default value filling
  • spock_proto_native.c: Native protocol tuple serialization
  • spock_proto_json.c: JSON protocol handling
  • spock_conflict.c: Conflict tuple formatting
  • spock_jsonb_utils.c: JSONB conversion utilities
  • spock_functions.c: Replication set table info
  • spock_repset.c: Attribute name lookup

Test Coverage:
Added regression test in sync_table.sql that verifies:

  • Table with STORED generated column can be added to replication set
  • Initial table synchronization works correctly via sub_resync_table()
  • Generated column values are correctly computed on subscriber
  • Both initial sync and ongoing replication handle generated columns

PostgreSQL generated columns (GENERATED ALWAYS AS ... STORED) were
causing errors during Spock replication. The issue occurred because
generated columns were being treated as regular columns during:
- Initial table synchronization (COPY operations)
- Logical replication protocol messages
- Default value filling for missing attributes
- Conflict resolution and tuple processing

Generated columns should not be replicated since they are computed
automatically on the target database based on their definition.

Solution:
Add checks for attgenerated flag alongside existing attisdropped
checks throughout the codebase to skip generated columns in:
- spock_sync.c: COPY attribute list construction
- spock_apply_heap.c: Default value filling
- spock_proto_native.c: Native protocol tuple serialization
- spock_proto_json.c: JSON protocol handling
- spock_conflict.c: Conflict tuple formatting
- spock_jsonb_utils.c: JSONB conversion utilities
- spock_functions.c: Replication set table info
- spock_repset.c: Attribute name lookup

Test Coverage:
Added regression test in sync_table.sql that verifies:
- Table with STORED generated column can be added to replication set
- Initial table synchronization works correctly via sub_resync_table()
- Generated column values are correctly computed on subscriber
- Both initial sync and ongoing replication handle generated columns
@danolivo danolivo self-assigned this Aug 21, 2026
@danolivo danolivo added the back-patch It is a back-port of already merged feature label Aug 21, 2026
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e3349c8d-f73a-47ca-af53-eed98f13de91

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -2 duplication

Metric Results
Complexity 0
Duplication -2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@danolivo
danolivo requested a review from mason-sharp August 21, 2026 11:59
@mason-sharp
mason-sharp merged commit 1de0743 into v5_STABLE Aug 21, 2026
7 checks passed
@mason-sharp
mason-sharp deleted the v5-generated-backport branch August 21, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

back-patch It is a back-port of already merged feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants