Implementation:2ndQuadrant Pglogical Show Subscription Status
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Monitoring |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
SQL-callable function that reports the status of pglogical subscriptions, including worker state, provider info, slot name, and replication sets.
Description
The pglogical.show_subscription_status() function returns a set of rows describing each subscription's current state. It checks whether the apply worker is running via shared memory, examines the sync status to determine if the subscription is replicating, initializing, down, or disabled, and reports the provider node name, DSN, slot name, replication sets, and forward origins.
The companion functions pglogical.wait_for_subscription_sync_complete() and pglogical.wait_for_table_sync_complete() block the caller until the subscription (or a specific table) reaches SYNC_STATUS_READY. pglogical.wait_slot_confirm_lsn() waits until a replication slot's confirmed flush position passes a target LSN.
Usage
Call this function when:
- Monitoring replication health
- Verifying subscription status after creation
- Waiting for initial synchronization to complete
- Checking if a replication slot has consumed up to a specific LSN
Code Reference
Source Location
- Repository: pglogical
- File: pglogical_functions.c, pglogical_monitoring.c
- Lines: pglogical_functions.c:L1061-1165 (show_status), L2230-2317 (wait_for_sync); pglogical_monitoring.c:L38-115 (wait_slot_confirm_lsn)
Signature
pglogical.show_subscription_status(
subscription_name name DEFAULT NULL
) RETURNS setof record
-- Columns: subscription_name text, status text, provider_node text,
-- provider_dsn text, slot_name text, replication_sets text[],
-- forward_origins text[]
pglogical.wait_for_subscription_sync_complete(
subscription_name name
) RETURNS void
pglogical.wait_for_table_sync_complete(
subscription_name name,
relation regclass
) RETURNS void
pglogical.wait_slot_confirm_lsn(
slot_name name DEFAULT NULL,
target_lsn pg_lsn DEFAULT NULL
) RETURNS void
Import
-- Available after CREATE EXTENSION pglogical;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| subscription_name | name | No | Filter to specific subscription (NULL returns all) |
| relation | regclass | No | For wait_for_table_sync_complete: specific table to wait for |
| slot_name | name | No | For wait_slot_confirm_lsn: specific slot (NULL for all) |
| target_lsn | pg_lsn | No | Target LSN to wait for (defaults to XactLastCommitEnd) |
Outputs
| Name | Type | Description |
|---|---|---|
| status rows | setof record | One row per subscription with status and metadata |
| status values | text | "replicating", "initializing", "down", "disabled", or "unknown" |
| wait functions | void | Block until condition met, then return |
Usage Examples
Check All Subscriptions
SELECT * FROM pglogical.show_subscription_status();
-- Output:
-- subscription_name | status | provider_node | provider_dsn | slot_name | replication_sets | forward_origins
-- sub_provider1 | replicating | provider1 | host=... | pgl_... | {default} | {}
Check Specific Subscription
SELECT * FROM pglogical.show_subscription_status('sub_provider1');
Wait for Sync to Complete
-- Block until the subscription finishes initial sync
SELECT pglogical.wait_for_subscription_sync_complete('sub_provider1');
Wait for a Specific Table to Sync
SELECT pglogical.wait_for_table_sync_complete('sub_provider1', 'public.large_table');
Wait for Slot to Confirm LSN
-- Wait until slot confirms the current WAL position
SELECT pglogical.wait_slot_confirm_lsn('pgl_mydb_provider1_sub1');
Related Pages
Implements Principle
- Principle:2ndQuadrant_Pglogical_Subscription_Management
- Principle:2ndQuadrant_Pglogical_Background_Worker_Coordination