pglogical
PostgreSQL Logical Replication
Repository
2ndQuadrant/pglogical
https://github.com/2ndQuadrant/pglogical
Source
pglogical-2.4.6.tar.gz
pglogical-2.4.6.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pglogical | 2.4.6 | ETL | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 9500 | pglogical | No | Yes | Yes | Yes | No | No | pglogical |
| 9501 | pglogical_origin | No | Yes | No | Yes | No | No | pglogical_origin |
| Related | decoderbufs wal2json dblink postgres_fdw pg_failover_slots pgactive repmgr kafka_fdw |
|---|---|
| Depended By | pgl_ddl_deploy pglogical_ticker |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 2.4.6 | 1817161514 | pglogical | - |
| RPM | PGDG | 2.4.6 | 1817161514 | pglogical_$v | - |
| DEB | PGDG | 2.4.6 | 1817161514 | postgresql-$v-pglogical | - |
Install
You can install pglogical directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pglogical; # Install for current active PG version
pig ext install -y pglogical -v 18 # PG 18
pig ext install -y pglogical -v 17 # PG 17
pig ext install -y pglogical -v 16 # PG 16
pig ext install -y pglogical -v 15 # PG 15
pig ext install -y pglogical -v 14 # PG 14
dnf install -y pglogical_18 # PG 18
dnf install -y pglogical_17 # PG 17
dnf install -y pglogical_16 # PG 16
dnf install -y pglogical_15 # PG 15
dnf install -y pglogical_14 # PG 14
apt install -y postgresql-18-pglogical # PG 18
apt install -y postgresql-17-pglogical # PG 17
apt install -y postgresql-16-pglogical # PG 16
apt install -y postgresql-15-pglogical # PG 15
apt install -y postgresql-14-pglogical # PG 14
Preload:
shared_preload_libraries = 'pglogical';
Create Extension:
CREATE EXTENSION pglogical;
Usage
A logical replication system for PostgreSQL using a publish/subscribe model. Requires no triggers or external programs.
Enabling
Add to postgresql.conf:
wal_level = 'logical'
max_worker_processes = 10
max_replication_slots = 10
max_wal_senders = 10
shared_preload_libraries = 'pglogical'
CREATE EXTENSION pglogical;
Provider (Publisher) Setup
-- Create a node on the provider
SELECT pglogical.create_node(
node_name := 'provider1',
dsn := 'host=providerhost port=5432 dbname=mydb'
);
-- Add all tables in public schema to default replication set
SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
-- Add all sequences in public schema
SELECT pglogical.replication_set_add_all_sequences('default', ARRAY['public']);
Subscriber Setup
-- Create a node on the subscriber
SELECT pglogical.create_node(
node_name := 'subscriber1',
dsn := 'host=subscriberhost port=5432 dbname=mydb'
);
-- Create a subscription to the provider
SELECT pglogical.create_subscription(
subscription_name := 'subscription1',
provider_dsn := 'host=providerhost port=5432 dbname=mydb'
);
Replication Set Management
-- Create a custom replication set
SELECT pglogical.create_replication_set('my_set');
-- Add a specific table
SELECT pglogical.replication_set_add_table('my_set', 'my_table', true);
-- Remove a table
SELECT pglogical.replication_set_remove_table('my_set', 'my_table');
Row and Column Filtering
-- Row filtering: only replicate rows matching a condition
SELECT pglogical.replication_set_add_table(
set_name := 'default',
relation := 'my_table',
row_filter := 'id > 1000'
);
-- Column filtering: only replicate specific columns
SELECT pglogical.replication_set_add_table(
set_name := 'default',
relation := 'my_table',
columns := '{id, name, updated_at}'
);
Subscription Management
-- Check subscription status
SELECT * FROM pglogical.show_subscription_status();
-- Drop subscription
SELECT pglogical.drop_subscription('subscription1');
Key Features
- Selective replication (per-table, row filtering, column filtering)
- Replication between different PostgreSQL major versions
- Delayed replication
- No need for superuser on subscriber
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.