Implementation:2ndQuadrant Pglogical Replication Set Add Table
| Knowledge Sources | |
|---|---|
| Domains | Database, Replication, Filtering |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
SQL-callable function that adds a table to a replication set with optional row filter, column list, and synchronization trigger.
Description
The pglogical.replication_set_add_table() function maps a table to a named replication set. It validates that the replication set exists, opens the table with a share-row-exclusive lock, processes optional column lists (ensuring replica identity columns are included), parses optional row filter expressions, and inserts a mapping into the pglogical.replication_set_table catalog. If synchronize=true, it also creates sync status entries for the table.
The companion function pglogical.replication_set_add_all_tables() adds all tables in specified schemas to a replication set at once.
Usage
Call this function when:
- Adding a table to a replication set for the first time
- Configuring row-level filtering (only replicate rows matching a WHERE clause)
- Configuring column-level filtering (exclude sensitive columns)
- Re-synchronizing a table by adding it with synchronize=true
Code Reference
Source Location
- Repository: pglogical
- File: pglogical_functions.c (SQL wrapper), pglogical_repset.c (catalog CRUD)
- Lines: pglogical_functions.c:L1394-1673 (add_table), L1679-1689 (add_all_tables); pglogical_repset.c:L110-268
Signature
pglogical.replication_set_add_table(
set_name name,
relation regclass,
synchronize bool,
row_filter text,
column_list text[]
) RETURNS bool
pglogical.replication_set_add_all_tables(
set_name name,
schema_names text[],
synchronize bool
) RETURNS bool
Import
-- Available after CREATE EXTENSION pglogical;
-- Called as: SELECT pglogical.replication_set_add_table(...);
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| set_name | name | Yes | Replication set name (must exist) |
| relation | regclass | Yes | Table OID or name |
| synchronize | bool | Yes | Trigger initial sync for this table |
| row_filter | text | No | WHERE-style filter expression |
| column_list | text[] | No | Array of column names to replicate |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | bool | true on success |
| pglogical.replication_set_table | catalog row | Mapping from table to replication set |
| sync status entries | catalog rows | Created if synchronize=true (SYNC_STATUS_INIT) |
Usage Examples
Add Table to Default Replication Set
SELECT pglogical.replication_set_add_table(
set_name := 'default',
relation := 'public.users',
synchronize := true
);
Add Table with Row Filter
-- Only replicate rows where active = true
SELECT pglogical.replication_set_add_table(
set_name := 'default',
relation := 'public.users',
synchronize := true,
row_filter := 'active = true'
);
Add Table with Column List
-- Exclude sensitive columns (ssn, password_hash)
SELECT pglogical.replication_set_add_table(
set_name := 'default',
relation := 'public.users',
synchronize := true,
column_list := ARRAY['id', 'username', 'email', 'active', 'created_at']
);
Add All Tables in a Schema
SELECT pglogical.replication_set_add_all_tables(
set_name := 'default',
schema_names := ARRAY['public', 'app'],
synchronize := true
);