diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-11 16:12:36 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-06-11 16:12:41 -0400 |
commit | ab55d742eb7162c22ee60f1e15e07d2a60063c4e (patch) | |
tree | f208cfb0c4a8a1978531626453cd06ce97d82bdd /src/backend/replication/logical/relation.c | |
parent | 4efcf47053eaf8dd88de2b1a89478df43d37d5c0 (diff) | |
download | postgresql-ab55d742eb7162c22ee60f1e15e07d2a60063c4e.tar.gz postgresql-ab55d742eb7162c22ee60f1e15e07d2a60063c4e.zip |
Fix multiple crasher bugs in partitioned-table replication logic.
apply_handle_tuple_routing(), having detected and reported that
the tuple it needed to update didn't exist, tried to update that
tuple anyway, leading to a null-pointer dereference.
logicalrep_partition_open() failed to ensure that the
LogicalRepPartMapEntry it built for a partition was fully
independent of that for the partition root, leading to
trouble if the root entry was later freed or rebuilt.
Meanwhile, on the publisher's side, pgoutput_change() sometimes
attempted to apply execute_attr_map_tuple() to a NULL tuple.
The first of these was reported by Sergey Bernikov in bug #17055;
I found the other two while developing some test cases for this
sadly under-tested code.
Diagnosis and patch for the first issue by Amit Langote; patches
for the others by me; new test cases by me. Back-patch to v13
where this logic came in.
Discussion: https://postgr.es/m/17055-9ba800ec8522668b@postgresql.org
Diffstat (limited to 'src/backend/replication/logical/relation.c')
-rw-r--r-- | src/backend/replication/logical/relation.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index e861c0ff802..4930f2ca348 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -620,7 +620,9 @@ logicalrep_partmap_init(void) * logicalrep_partition_open * * Returned entry reuses most of the values of the root table's entry, save - * the attribute map, which can be different for the partition. + * the attribute map, which can be different for the partition. However, + * we must physically copy all the data, in case the root table's entry + * gets freed/rebuilt. * * Note there's no logicalrep_partition_close, because the caller closes the * component relation. @@ -656,7 +658,7 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root, part_entry->partoid = partOid; - /* Remote relation is used as-is from the root entry. */ + /* Remote relation is copied as-is from the root entry. */ entry = &part_entry->relmapentry; entry->remoterel.remoteid = remoterel->remoteid; entry->remoterel.nspname = pstrdup(remoterel->nspname); @@ -699,7 +701,12 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root, } } else - entry->attrmap = attrmap; + { + /* Lacking copy_attmap, do this the hard way. */ + entry->attrmap = make_attrmap(attrmap->maplen); + memcpy(entry->attrmap->attnums, attrmap->attnums, + attrmap->maplen * sizeof(AttrNumber)); + } entry->updatable = root->updatable; |