pgsql: Allow specifying column lists for logical replication

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow specifying column lists for logical replication
Date: 2022-03-26 00:02:02
Message-ID: E1nXtsX-001OJ4-C5@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow specifying column lists for logical replication

This allows specifying an optional column list when adding a table to
logical replication. The column list may be specified after the table
name, enclosed in parentheses. Columns not included in this list are not
sent to the subscriber, allowing the schema on the subscriber to be a
subset of the publisher schema.

For UPDATE/DELETE publications, the column list needs to cover all
REPLICA IDENTITY columns. For INSERT publications, the column list is
arbitrary and may omit some REPLICA IDENTITY columns. Furthermore, if
the table uses REPLICA IDENTITY FULL, column list is not allowed.

The column list can contain only simple column references. Complex
expressions, function calls etc. are not allowed. This restriction could
be relaxed in the future.

During the initial table synchronization, only columns included in the
column list are copied to the subscriber. If the subscription has
several publications, containing the same table with different column
lists, columns specified in any of the lists will be copied.

This means all columns are replicated if the table has no column list
at all (which is treated as column list with all columns), or when of
the publications is defined as FOR ALL TABLES (possibly IN SCHEMA that
matches the schema of the table).

For partitioned tables, publish_via_partition_root determines whether
the column list for the root or the leaf relation will be used. If the
parameter is 'false' (the default), the list defined for the leaf
relation is used. Otherwise, the column list for the root partition
will be used.

Psql commands \dRp+ and \d <table-name> now display any column lists.

Author: Tomas Vondra, Alvaro Herrera, Rahila Syed
Reviewed-by: Peter Eisentraut, Alvaro Herrera, Vignesh C, Ibrar Ahmed,
Amit Kapila, Hou zj, Peter Smith, Wang wei, Tang, Shi yu
Discussion: https://postgr.es/m/CAH2L28vddB_NFdRVpuyRBJEBWjz4BSyTB=_ektNRH8NJ1jf95g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/923def9a533a7d986acfb524139d8b9e5466d0a5

Modified Files
--------------
doc/src/sgml/catalogs.sgml | 15 +-
doc/src/sgml/protocol.sgml | 3 +-
doc/src/sgml/ref/alter_publication.sgml | 18 +-
doc/src/sgml/ref/create_publication.sgml | 17 +-
src/backend/catalog/pg_publication.c | 145 ++++
src/backend/commands/publicationcmds.c | 265 ++++++-
src/backend/executor/execReplication.c | 19 +-
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/equalfuncs.c | 1 +
src/backend/parser/gram.y | 33 +-
src/backend/replication/logical/proto.c | 61 +-
src/backend/replication/logical/tablesync.c | 153 +++-
src/backend/replication/pgoutput/pgoutput.c | 201 ++++-
src/backend/utils/cache/relcache.c | 33 +-
src/bin/pg_dump/pg_dump.c | 41 +-
src/bin/pg_dump/pg_dump.h | 1 +
src/bin/pg_dump/t/002_pg_dump.pl | 60 ++
src/bin/psql/describe.c | 44 +-
src/include/catalog/pg_publication.h | 12 +
src/include/catalog/pg_publication_rel.h | 1 +
src/include/commands/publicationcmds.h | 4 +-
src/include/nodes/parsenodes.h | 1 +
src/include/replication/logicalproto.h | 6 +-
src/test/regress/expected/publication.out | 372 +++++++++
src/test/regress/sql/publication.sql | 287 +++++++
src/test/subscription/t/031_column_list.pl | 1131 +++++++++++++++++++++++++++
26 files changed, 2833 insertions(+), 92 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Justin Pryzby 2022-03-26 03:13:53 Re: pgsql: Add 'basebackup_to_shell' contrib module.
Previous Message Thomas Munro 2022-03-25 21:52:03 Re: pgsql: Add 'basebackup_to_shell' contrib module.