Implementation:2ndQuadrant Pglogical Pglogical Subscribe
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Deployment |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Internal wrapper function within the pglogical_create_subscriber CLI tool that installs the pglogical extension, creates the subscriber node, and creates the subscription with synchronization disabled (data already present from base backup).
Description
The pglogical_subscribe() function is a static helper in pglogical_create_subscriber.c that orchestrates the final setup steps after the physical base backup is running as an independent primary:
- install_extension(): Executes CREATE EXTENSION pglogical (and pglogical_origin if needed) via libpq on the subscriber.
- Creates the subscriber node by executing pglogical.create_node() via libpq.
- Creates the subscription by executing pglogical.create_subscription() with synchronize_structure=false and synchronize_data=false (since the data is already present from the base backup).
- Updates local_sync_status to READY ('r') since no sync is needed.
The install_extension() helper checks if the extension already exists (extension_exists()), and if not, executes CREATE EXTENSION via PQexec.
This is a Wrapper Doc — it wraps the SQL-callable pglogical API (create_node, create_subscription) for use from the CLI tool via libpq.
Usage
This is an internal function called by pglogical_create_subscriber's main() function. Users do not call it directly.
Code Reference
Source Location
- Repository: pglogical
- File: pglogical_create_subscriber.c
- Lines: L972-1000 (install_extension), L1133-1209 (pglogical_subscribe), L940-960 (extension_exists)
Signature
static void install_extension(PGconn *conn, const char *extname);
static void pglogical_subscribe(PGconn *conn,
char *subscriber_name,
char *subscriber_dsn,
char *provider_dsn,
char *replication_sets,
int apply_delay,
bool force_text_transfer);
static bool extension_exists(PGconn *conn, const char *extname);
Import
/* Internal static functions within pglogical_create_subscriber.c.
Not user-callable. Wraps pglogical SQL API via libpq. */
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| conn | PGconn* | Yes Subscriber database connection | |
| extname | const char* | Yes install_extension: "pglogical" or "pglogical_origin" | |
| subscriber_name | char* | Yes Subscriber node name | |
| subscriber_dsn | char* | Yes Subscriber DSN | |
| provider_dsn | char* | Yes Provider DSN | |
| replication_sets | char* | Yes Comma-separated set names | |
| apply_delay | int | Yes Apply delay in seconds | |
| force_text_transfer | bool | Yes Force text transfer mode |
Outputs
| Name | Type | Description |
|---|---|---|
| extension | installed | CREATE EXTENSION pglogical executed |
| node | catalog entry | pglogical.create_node() called on subscriber |
| subscription | catalog entry | pglogical.create_subscription() called (sync=false) |
| sync status | catalog | local_sync_status set to READY ('r') |
Usage Examples
Internal SQL Execution (Wrapper Doc)
-- install_extension() executes:
CREATE EXTENSION IF NOT EXISTS pglogical;
-- pglogical_subscribe() executes:
SELECT pglogical.create_node(
node_name := 'subscriber1',
dsn := 'host=subscriber.example.com dbname=mydb'
);
SELECT pglogical.create_subscription(
subscription_name := 'subscriber1',
provider_dsn := 'host=provider.example.com dbname=mydb',
replication_sets := ARRAY['default', 'insert_only'],
synchronize_structure := false, -- Data from base backup
synchronize_data := false, -- Data from base backup
forward_origins := ARRAY[''],
apply_delay := '0s'::interval,
force_text_transfer := false
);
-- Set sync status to ready (no sync needed)
UPDATE pglogical.local_sync_status SET status = 'r';
User-Invoked (via CLI)
# pglogical_subscribe is called internally by:
pglogical_create_subscriber \
--subscriber-name=subscriber1 \
--provider-dsn="host=provider.example.com dbname=mydb" \
--subscriber-dsn="host=subscriber.example.com dbname=mydb" \
--pgdata=/var/lib/postgresql/subscriber1
Related Pages
Implements Principle
- Principle:2ndQuadrant_Pglogical_Base_Backup_Subscriber_Init
- Principle:2ndQuadrant_Pglogical_Subscription_Management
- Principle:2ndQuadrant_Pglogical_Node_Management