pg_createsubscriber: Fix incorrect handling of cleanup flags

First seen: 2025-05-05 03:45:35+00:00 · Messages: 12 · Participants: 4

Latest Update

2026-06-01 · claude-opus-4-6

pg_createsubscriber: Fix incorrect handling of cleanup flags — May 2026 Summary

Overview

A bug in pg_createsubscriber's cleanup flag handling was identified, reviewed, and committed (with backpatch to v17) during this month. The fix removes incorrect state mutations that could leave orphaned publications and replication slots on the primary server after failures.

The Bug

pg_createsubscriber converts a physical standby into a logical replication subscriber through a multi-step process. Two boolean flags (made_publication, made_replslot) in the per-database dbinfo structure gate cleanup of tool-created objects on the primary via an atexit handler.

The helper functions drop_publication() and drop_replication_slot() are reused for multiple purposes:

These functions unconditionally reset the cleanup flags on failure, regardless of which object or server was involved. If a subscriber-side drop failed, it would flip made_publication = false, causing the atexit handler to skip cleanup of the primary-side tool-created publication — leaving orphaned objects.

The Fix

The resolution was minimal: remove the made_publication = false and made_replslot = false assignments entirely from the drop functions. Rationale:

Review and Commit Timeline

Architectural Lesson

This is a textbook case of feature creep eroding invariants. drop_publication() originally existed solely to clean up tool-created publications (making the flag mutation sensible). As it was reused for subscriber-side drops and --remove operations, the original invariant silently broke. The fix shrinks the function's contract to match its actual multi-purpose usage rather than adding conditional logic.

History (1 prior analysis)
2026-06-01 · claude-opus-4-6

No Substantive Progress

The only new message is Nisha Moond's brief thank-you to Fujii Masao for committing the patch. There is no new technical content, no design discussion, and no follow-up issues raised. The thread is fully concluded.