Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2ndQuadrant Pglogical Replication Set Filtering

From Leeroopedia
Knowledge Sources
Domains Database, Replication, Filtering
Last Updated 2026-10-13 00:00 GMT

Overview

Design pattern for selectively controlling which table changes are replicated by grouping tables into named replication sets and applying row-level and column-level filters.

Description

Replication set filtering solves the problem of selective replication: not all tables, and not all rows within a table, may need to be replicated to every subscriber. A replication set is a named grouping of tables that controls which operations (INSERT, UPDATE, DELETE, TRUNCATE) are replicated for its member tables.

Each replication set specifies four boolean flags controlling which DML operations are replicated. A table can belong to multiple replication sets. Subscriptions specify which replication sets they subscribe to, and only changes matching those sets are streamed.

Additionally, per-table row filters (WHERE-clause expressions) and column lists further narrow what data is replicated. Row filters allow replicating only rows matching a predicate (e.g., only rows where active = true). Column lists allow replicating only a subset of columns (e.g., excluding sensitive columns). Replica identity columns must always be included in the column list.

Usage

Use replication set filtering when:

  • Different subscribers need different subsets of tables
  • Some tables should only replicate INSERTs (append-only, audit logs)
  • Row-level security requires replicating only certain rows
  • Column-level security requires excluding sensitive columns
  • DDL replication needs a separate channel from data replication

Theoretical Basis

A replication set S is defined as a tuple:

S=(name,Rinsert,Rupdate,Rdelete,Rtruncate)

where each R_op is a boolean indicating whether that operation is replicated for member tables.

A change c on table T is replicated to subscription sub if and only if:

Failed to parse (syntax error): {\displaystyle \exists S \in \text{sub.replication\_sets} : T \in S \land S.R_{c.op} = \text{true} \land \text{rowfilter}(c) = \text{true} }

Filtering pipeline:

WAL Change → Replication Set Membership Check → Operation Flag Check → Row Filter Check → Column Projection → Encode

Default replication sets created per node:

  • default: replicates INSERT, UPDATE, DELETE, TRUNCATE
  • insert_only: replicates only INSERT and TRUNCATE (for append-only tables)
  • ddl_sql: for DDL command replication

Practical Guide

Configuring Replication Sets

-- Add a table to the "default" replication set
SELECT pglogical.replication_set_add_table(
    set_name := 'default',
    relation := 'public.users',
    synchronize := true
);

-- Add with a row filter (only active users)
SELECT pglogical.replication_set_add_table(
    set_name := 'default',
    relation := 'public.users',
    synchronize := true,
    row_filter := 'active = true'
);

-- Add with a column list (exclude sensitive columns)
SELECT pglogical.replication_set_add_table(
    set_name := 'default',
    relation := 'public.users',
    synchronize := true,
    column_list := ARRAY['id', 'name', 'email', 'active']
);

Key Considerations

  • Replica identity (PRIMARY KEY) columns must be in the column list
  • Row filters are evaluated on the provider side during logical decoding
  • Adding a table with synchronize=true triggers an initial data copy
  • Tables can belong to multiple replication sets

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment