Principle:2ndQuadrant Pglogical Base Backup Subscriber Init
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Deployment |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Method of initializing a pglogical subscriber from a physical base backup of the provider, bypassing the normal schema/data synchronization phase by cloning the provider's data directory and then converting the clone into an independent subscriber node.
Description
The base backup subscriber initialization method solves the "cold start" problem for large databases: when the provider contains terabytes of data, the normal initial synchronization (which uses pg_dump/pg_restore and per-table COPY) may take hours or days. Instead, this method uses pg_basebackup to create a byte-level copy of the provider's entire data directory, which is much faster for large datasets.
The process involves:
- CLI parameter parsing: The pglogical_create_subscriber tool accepts subscriber name, provider/subscriber DSNs, data directory, replication sets, and optional config files.
- Physical base backup: Run pg_basebackup to copy the provider's data directory to the target location.
- System identifier modification: Verify the backup matches the provider (system ID check), then modify the control file to give the new node a unique identity.
- Recovery and startup: Write recovery configuration and start the new PostgreSQL instance via pg_ctl, promoting it to a primary.
- Extension and node setup: Install the pglogical extension, create the subscriber node, and create the subscription with synchronize_structure=false, synchronize_data=false (data already present from base backup).
- Verification: Confirm the subscription is in "replicating" status.
The key insight is that the base backup already contains all data and schema, so the subscription skips the sync phase and immediately begins streaming replication from the provider's current WAL position.
Usage
Use base backup subscriber init when:
- The provider database is large (GBs/TBs) and per-table COPY would be too slow
- A binary-identical copy is acceptable (same PostgreSQL version)
- Setting up a subscriber quickly from a known-good provider state
- Migrating from physical standby to logical subscriber
Do NOT use this method when:
- Provider and subscriber run different PostgreSQL major versions (use normal sync)
- Only a subset of tables needs replication (use normal sync with replication sets)
- The subscriber needs a different schema (use normal structure sync)
Theoretical Basis
Process flow:
1. pg_basebackup(provider) → data_dir // Physical copy
2. verify_system_id(data_dir, provider) // Validate backup
3. create_replication_slot_on_provider() // Reserve WAL position
4. write_recovery_conf(data_dir) // Point to provider
5. pg_ctl start(data_dir) // Start as standby
6. pg_ctl promote(data_dir) // Promote to primary
7. CREATE EXTENSION pglogical // Install extension
8. pglogical.create_node() // Create subscriber node
9. pglogical.create_subscription(sync=false) // Start streaming
10. show_subscription_status() // Verify "replicating"
Why this works:
The base backup is a consistent copy of the provider at a specific checkpoint. After recovery and promotion, the new instance has all data up to that point. Creating the subscription with synchronize_data=false tells pglogical that no initial copy is needed — it should begin streaming from the provider's current WAL position. The replication slot (created in Step 3) ensures the provider retains WAL from the backup's checkpoint, so no changes are lost between backup and streaming start.
System identifier:
Each PostgreSQL cluster has a unique system identifier. A physical replica shares this identifier with its primary. To make the new node independent (not a physical standby), its system identifier must be modified so it can have its own replication origins, slots, and timeline.
Practical Guide
Using pglogical_create_subscriber
pglogical_create_subscriber \
--subscriber-name=subscriber1 \
--provider-dsn="host=provider.example.com port=5432 dbname=mydb" \
--subscriber-dsn="host=subscriber.example.com port=5432 dbname=mydb" \
--pgdata=/var/lib/postgresql/subscriber1 \
--replication-sets=default,insert_only \
--apply-delay=0
Key Considerations
- The new subscriber must run the same PostgreSQL major version as the provider
- The replication slot is created on the provider before the backup, ensuring WAL retention
- The local_sync_status is set to 'r' (READY) since data is already present
- Config files (postgresql.conf, pg_hba.conf) can be customized for the subscriber
- The tool handles the entire lifecycle: backup, start, promote, setup, verify