postgresql/src/include/access
Andres Freund a88482dd24 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
..
amapi.h Add SQL-accessible functions for inspecting index AM properties. 2016-08-13 18:31:14 -04:00
amvalidate.h Improve index AMs' opclass validation procedures. 2016-01-21 19:47:15 -05:00
attnum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
brin.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
brin_internal.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
brin_page.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
brin_pageops.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
brin_revmap.h Add the "snapshot too old" feature 2016-04-08 14:36:30 -05:00
brin_tuple.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
brin_xlog.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
clog.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
commit_ts.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
genam.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
generic_xlog.h Improve API of GenericXLogRegister(). 2016-04-12 11:42:06 -04:00
gin.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
gin_private.h Fix broken cleanup interlock for GIN pending list. 2017-11-16 15:26:49 -05:00
gist.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
gist_private.h Fix outdated comments, GIST search queue is not an RBTree anymore. 2016-09-20 11:40:13 +03:00
gistscan.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
hash.h Fix building of large (bigger than shared_buffers) hash indexes. 2016-06-24 16:57:36 -04:00
heapam.h Fix logical decoding error when system table w/ toast is repeatedly rewritten. 2018-10-10 13:53:02 -07:00
heapam_xlog.h Perform a lot more sanity checks when freezing tuples. 2017-12-14 18:20:48 -08:00
hio.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
htup.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
htup_details.h Change some test macros to return true booleans 2017-01-18 18:06:13 -03:00
itup.h Revert CREATE INDEX ... INCLUDING ... 2016-04-08 21:52:13 +03:00
multixact.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
nbtree.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:30 -04:00
parallel.h Report an ERROR if a parallel worker fails to start properly. 2018-01-23 11:13:50 -05:00
printtup.h Stop the executor if no more tuples can be sent from worker to leader. 2016-06-06 14:52:58 -04:00
reloptions.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
relscan.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rewriteheap.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rmgr.h Add rmgr callback to name xlog record types for display purposes. 2014-09-19 16:20:29 +02:00
rmgrlist.h Generic Messages for Logical Decoding 2016-04-06 10:05:41 +01:00
sdir.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
skey.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
slru.h Make all built-in lwlock tranche IDs fixed. 2016-02-02 06:45:55 -05:00
spgist.h Introduce traversalValue for SP-GiST scan 2016-03-30 18:29:28 +03:00
spgist_private.h Prevent query-lifespan memory leakage of SP-GiST traversal values. 2018-03-19 23:59:17 -04:00
stratnum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
subtrans.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
sysattr.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
timeline.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
transam.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tsmapi.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tupconvert.h Fix ALTER TABLE / SET TYPE for irregular inheritance 2017-01-09 19:26:58 -03:00
tupdesc.h Backpatch introduction of TupleDescAttr(tupdesc, i). 2017-08-22 07:47:42 -07:00
tupmacs.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tuptoaster.h Fix deletion of speculatively inserted TOAST on conflict 2016-08-17 17:03:36 -07:00
twophase.h Mark assorted variables PGDLLIMPORT. 2017-12-05 09:27:20 -05:00
twophase_rmgr.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
valid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
visibilitymap.h Fix typos in comments. 2017-02-06 11:34:15 +02:00
xact.h Propagate xactStartTimestamp and stmtStartTimestamp to parallel workers. 2018-10-06 12:00:10 -04:00
xlog.h Fix backup canceling 2017-03-24 13:55:02 +03:00
xlog_fn.h Implement backup API functions for non-exclusive backups 2016-04-05 20:03:49 +02:00
xlog_internal.h Fix comment. 2017-08-01 08:08:32 +09:00
xlogdefs.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xloginsert.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xlogreader.h Fix scenario where streaming standby gets stuck at a continuation record. 2018-05-05 01:35:12 +03:00
xlogrecord.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xlogutils.h XLogReader general code cleanup 2016-03-30 18:56:13 -03:00