diff options
author | Peter Eisentraut | 2020-03-10 07:42:59 +0000 |
---|---|---|
committer | Peter Eisentraut | 2020-03-10 08:09:32 +0000 |
commit | 17b9e7f9fe238eeb5f6b40061b444ebf28d9e06f (patch) | |
tree | 7c6f8d87b72708aeeb5f800ec6384cc19c927b63 /src/backend/replication/pgoutput/pgoutput.c | |
parent | 61d7c7bce3686ec02bd64abac742dd35ed9b9b01 (diff) |
Support adding partitioned tables to publication
When a partitioned table is added to a publication, changes of all of
its partitions (current or future) are published via that publication.
This change only affects which tables a publication considers as its
members. The receiving side still sees the data coming from the
individual leaf partitions. So existing restrictions that partition
hierarchies can only be replicated one-to-one are not changed by this.
Author: Amit Langote <[email protected]>
Reviewed-by: Rafia Sabih <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CA+HiwqH=Y85vRK3mOdjEkqFK+E=ST=eQiHdpj43L=_eJMOOznQ@mail.gmail.com
Diffstat (limited to 'src/backend/replication/pgoutput/pgoutput.c')
-rw-r--r-- | src/backend/replication/pgoutput/pgoutput.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 752508213af..552a70cffa5 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -50,7 +50,12 @@ static List *LoadPublications(List *pubnames); static void publication_invalidation_cb(Datum arg, int cacheid, uint32 hashvalue); -/* Entry in the map used to remember which relation schemas we sent. */ +/* + * Entry in the map used to remember which relation schemas we sent. + * + * For partitions, 'pubactions' considers not only the table's own + * publications, but also those of all of its ancestors. + */ typedef struct RelationSyncEntry { Oid relid; /* relation oid */ @@ -406,6 +411,13 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, if (!relentry->pubactions.pubtruncate) continue; + /* + * Don't send partitioned tables, because partitions should be sent + * instead. + */ + if (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + continue; + relids[nrelids++] = relid; maybe_send_schema(ctx, relation, relentry); } @@ -524,6 +536,11 @@ init_rel_sync_cache(MemoryContext cachectx) /* * Find or create entry in the relation schema cache. + * + * This looks up publications that the given relation is directly or + * indirectly part of (the latter if it's really the relation's ancestor that + * is part of a publication) and fills up the found entry with the information + * about which operations to publish. */ static RelationSyncEntry * get_rel_sync_entry(PGOutputData *data, Oid relid) |