Implementation:2ndQuadrant Pglogical Extension Init
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Configuration |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for registering pglogical extension configuration parameters (GUCs) and initializing shared memory infrastructure provided by the PostgreSQL extension framework.
Description
The _PG_init function is the entry point called by PostgreSQL when the pglogical shared library is loaded via shared_preload_libraries. It registers all pglogical-specific Grand Unified Configuration (GUC) variables, sets up shared memory for worker coordination, and installs planner and executor hooks.
The GUCs registered include conflict resolution strategy, conflict log level, synchronous commit, SPI mode, batch inserts, temp directory, extra connection options, and subscription owner. These control the runtime behavior of the extension.
Usage
Import this functionality when:
- Configuring pglogical via postgresql.conf
- Understanding which configuration parameters control pglogical behavior
- Troubleshooting GUC-related issues
Code Reference
Source Location
- Repository: pglogical
- File: pglogical.c
- Lines: L815-936
Signature
void _PG_init(void);
/* Registered GUCs (via DefineCustomEnumVariable, DefineCustomBoolVariable, DefineCustomStringVariable): */
/* pglogical.conflict_resolution: enum (error/apply_remote/keep_local/last_update_wins/first_update_wins) */
/* pglogical.conflict_log_level: int (default LOG) */
/* pglogical.synchronous_commit: bool (default false) */
/* pglogical.use_spi: bool (default false) */
/* pglogical.batch_inserts: bool (default true) */
/* pglogical.temp_directory: string (default NULL) */
/* pglogical.extra_connection_options: string (default NULL) */
/* pglogical.subscription_owner: string (default NULL) */
Import
/* Loaded automatically via shared_preload_libraries = 'pglogical' */
/* No explicit import needed; _PG_init is called by PostgreSQL on library load */
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| postgresql.conf | config file | Yes | Must set shared_preload_libraries = 'pglogical, wal_level = 'logical, max_worker_processes >= 4 |
| GUC values | various | No | Override defaults in postgresql.conf or via ALTER SYSTEM |
Outputs
| Name | Type | Description |
|---|---|---|
| Registered GUCs | config parameters | All pglogical.* variables available in postgresql.conf |
| Shared memory | PGLogicalContext | Shared memory structure for worker coordination initialized |
| Worker slots | background worker slots | max_worker_processes slots reserved for pglogical workers |
Usage Examples
Basic Configuration
# In postgresql.conf (requires restart):
shared_preload_libraries = 'pglogical'
wal_level = 'logical'
max_worker_processes = 10
# pglogical-specific GUCs (can be set without restart via ALTER SYSTEM):
pglogical.conflict_resolution = 'last_update_wins'
pglogical.conflict_log_level = 'log'
pglogical.batch_inserts = on
pglogical.use_spi = off
pglogical.synchronous_commit = off
Verify Configuration
-- Check that pglogical is loaded
SHOW shared_preload_libraries;
-- Check GUC values
SHOW pglogical.conflict_resolution;
SHOW pglogical.batch_inserts;
Related Pages
Implements Principle
- Principle:2ndQuadrant_Pglogical_Node_Management
- Principle:2ndQuadrant_Pglogical_Background_Worker_Coordination