Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2ndQuadrant Pglogical Subscription Management

From Leeroopedia
Knowledge Sources
Domains Database, Replication
Last Updated 2026-10-13 00:00 GMT

Overview

Concept of establishing a managed replication link between a subscriber node and a provider node, specifying which replication sets to receive, whether to synchronize structure and data, and how to handle forwarded origins and apply delay.

Description

A subscription is the edge in the replication topology graph: it defines a connection from a subscriber to a provider, specifying which replication sets the subscriber wants to receive, whether to perform initial synchronization (schema and/or data), and operational parameters like apply delay and text-mode transfer.

Subscription creation is the pivotal step that connects two nodes. It validates connectivity (both regular and replication mode), registers the remote node in the local catalog if not already present, checks for overlapping replication sets with existing subscriptions (to prevent conflicting data sources), creates a replication slot on the provider, and initiates the synchronization process.

After creation, the subscription enters a state machine: initializing → replicating (or down if the worker crashes, disabled if manually disabled). The manager worker supervises the subscription's apply worker and restarts it on crash with exponential backoff.

Usage

Use subscription management when:

  • Connecting a subscriber to a provider to begin receiving changes
  • Configuring which replication sets a subscriber receives
  • Setting up apply delay for controlled replication lag
  • Enabling or disabling replication without dropping the subscription
  • Monitoring subscription health and synchronization status

Theoretical Basis

A subscription sub is defined as:

Failed to parse (syntax error): {\displaystyle sub = (\text{name}, \text{provider\_dsn}, \text{replication\_sets}, \text{sync\_structure}, \text{sync\_data}, \text{forward\_origins}, \text{apply\_delay}, \text{force\_text\_transfer}) }

Subscription lifecycle:

CREATE → INIT (slot created, sync worker spawned)
      → STRUCTURE (schema copied via pg_dump/pg_restore)
      → DATA (table data copied via COPY)
      → CATCHUP (waiting for apply to reach sync point)
      → SYNCDONE (sync complete, apply takes over)
      → READY (normal streaming replication)

Overlapping replication set check:

Two subscriptions to the same provider cannot subscribe to overlapping replication sets, because both would attempt to apply the same changes, causing conflicts. This is enforced at creation time.

Practical Guide

Creating a Subscription

SELECT pglogical.create_subscription(
    subscription_name := 'sub_provider1',
    provider_dsn := 'host=provider.example.com port=5432 dbname=mydb',
    replication_sets := ARRAY['default', 'insert_only'],
    synchronize_structure := true,
    synchronize_data := true,
    forward_origins := ARRAY[''],
    apply_delay := '0s'::interval,
    force_text_transfer := false
);

Monitoring

-- Check status
SELECT * FROM pglogical.show_subscription_status();

-- Wait for sync to complete
SELECT pglogical.wait_for_subscription_sync_complete('sub_provider1');

Key Considerations

  • Replication sets must not overlap with other subscriptions to the same provider
  • The provider must be reachable in both regular and replication connection modes
  • Apply delay introduces intentional lag (useful for disaster recovery windows)
  • Force text transfer avoids binary format issues across PostgreSQL major versions

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment