postgresql/src/backend
Andres Freund e9edc1ba0b Fix logical decoding error when system table w/ toast is repeatedly rewritten.
Repeatedly rewriting a mapped catalog table with VACUUM FULL or
CLUSTER could cause logical decoding to fail with:
ERROR, "could not map filenode \"%s\" to relation OID"

To trigger the problem the rewritten catalog had to have live tuples
with toasted columns.

The problem was triggered as during catalog table rewrites the
heap_insert() check that prevents logical decoding information to be
emitted for system catalogs, failed to treat the new heap's toast table
as a system catalog (because the new heap is not recognized as a
catalog table via RelationIsLogicallyLogged()). The relmapper, in
contrast to the normal catalog contents, does not contain historical
information. After a single rewrite of a mapped table the new relation
is known to the relmapper, but if the table is rewritten twice before
logical decoding occurs, the relfilenode cannot be mapped to a
relation anymore.  Which then leads us to error out.   This only
happens for toast tables, because the main table contents aren't
re-inserted with heap_insert().

The fix is simple, add a new heap_insert() flag that prevents logical
decoding information from being emitted, and accept during decoding
that there might not be tuple data for toast tables.

Unfortunately that does not fix pre-existing logical decoding
errors. Doing so would require not throwing an error when a filenode
cannot be mapped to a relation during decoding, and that seems too
likely to hide bugs.  If it's crucial to fix decoding for an existing
slot, temporarily changing the ERROR in ReorderBufferCommit() to a
WARNING appears to be the best fix.

Author: Andres Freund
Discussion: https://postgr.es/m/20180914021046.oi7dm4ra3ot2g2kt@alap3.anarazel.de
Backpatch: 9.4-, where logical decoding was introduced
2018-10-10 13:53:02 -07:00
..
access Fix logical decoding error when system table w/ toast is repeatedly rewritten. 2018-10-10 13:53:02 -07:00
bootstrap Install a check for mis-linking of src/port and src/common functions. 2018-09-09 12:23:23 -04:00
catalog Add pg_ls_archive_statusdir function 2018-10-09 22:29:09 +09:00
commands Turn transaction_isolation into GUC enum 2018-10-09 21:26:00 +02:00
executor Advance transaction timestamp for intra-procedure transactions. 2018-10-08 16:16:36 -04:00
foreign Remove bogus "extern" annotations on function definitions. 2018-02-19 12:07:44 -05:00
jit Change TupleTableSlot->tts_nvalid to type AttrNumber. 2018-09-25 15:59:46 -07:00
lib Implement %m in src/port/snprintf.c, and teach elog.c to rely on that. 2018-09-26 13:31:56 -04:00
libpq Minor cleanup/future-proofing for pg_saslprep(). 2018-09-08 18:20:36 -04:00
main Update copyright for 2018 2018-01-02 23:30:12 -05:00
nodes Remove some unnecessary fields from Plan trees. 2018-10-07 14:33:17 -04:00
optimizer Remove some unnecessary fields from Plan trees. 2018-10-07 14:33:17 -04:00
parser Add option SKIP_LOCKED to VACUUM and ANALYZE 2018-10-04 09:00:33 +09:00
partitioning Centralize executor's opening/closing of Relations for rangetable entries. 2018-10-04 14:03:42 -04:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Convert elog.c's useful_strerror() into a globally-used strerror wrapper. 2018-09-26 11:06:42 -04:00
postmaster Add application_name to connection authorized msg 2018-09-28 19:04:50 -04:00
regex Clean up warnings from -Wimplicit-fallthrough. 2018-05-01 19:35:08 -04:00
replication Fix logical decoding error when system table w/ toast is repeatedly rewritten. 2018-10-10 13:53:02 -07:00
rewrite Change rewriter/planner/executor/plancache to depend on RTE rellockmode. 2018-10-02 14:43:09 -04:00
snowball Sync our Snowball stemmer dictionaries with current upstream. 2018-09-24 17:29:38 -04:00
statistics Fix typos. 2018-08-27 09:32:59 +12:00
storage Refactor user-facing SQL functions signalling backends 2018-10-04 18:27:25 +09:00
tcop Slightly correct context check for event triggers 2018-10-10 22:41:12 +02:00
tsearch Hand code string to integer conversion for performance. 2018-07-22 14:58:23 -07:00
utils Turn transaction_isolation into GUC enum 2018-10-09 21:26:00 +02:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Refactor dlopen() support 2018-09-06 11:33:04 +02:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00