postgresql/src/include/access
Tom Lane 08e261cbc9 Fix race condition with toast table access from a stale syscache entry.
If a tuple in a syscache contains an out-of-line toasted field, and we
try to fetch that field shortly after some other transaction has committed
an update or deletion of the tuple, there is a race condition: vacuum
could come along and remove the toast tuples before we can fetch them.
This leads to transient failures like "missing chunk number 0 for toast
value NNNNN in pg_toast_2619", as seen in recent reports from Andrew
Hammond and Tim Uckun.

The design idea of syscache is that access to stale syscache entries
should be prevented by relation-level locks, but that fails for at least
two cases where toasted fields are possible: ANALYZE updates pg_statistic
rows without locking out sessions that might want to plan queries on the
same table, and CREATE OR REPLACE FUNCTION updates pg_proc rows without
any meaningful lock at all.

The least risky fix seems to be an idea that Heikki suggested when we
were dealing with a related problem back in August: forcibly detoast any
out-of-line fields before putting a tuple into syscache in the first place.
This avoids the problem because at the time we fetch the parent tuple from
the catalog, we should be holding an MVCC snapshot that will prevent
removal of the toast tuples, even if the parent tuple is outdated
immediately after we fetch it.  (Note: I'm not convinced that this
statement holds true at every instant where we could be fetching a syscache
entry at all, but it does appear to hold true at the times where we could
fetch an entry that could have a toasted field.  We will need to be a bit
wary of adding toast tables to low-level catalogs that don't have them
already.)  An additional benefit is that subsequent uses of the syscache
entry should be faster, since they won't have to detoast the field.

Back-patch to all supported versions.  The problem is significantly harder
to reproduce in pre-9.0 releases, because of their willingness to flush
every entry in a syscache whenever the underlying catalog is vacuumed
(cf CatalogCacheFlushRelation); but there is still a window for trouble.
2011-11-01 19:49:58 -04:00
..
attnum.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
clog.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
genam.h Support index-only scans using the visibility map to avoid heap fetches. 2011-10-07 20:14:13 -04:00
gin_private.h Allow more include files to be compiled in their own by adding missing 2011-08-27 11:05:33 -04:00
gin.h Clean up the #include mess a little. 2011-09-04 01:13:16 -04:00
gist_private.h Support GiST index support functions that want to cache data across calls. 2011-09-30 19:48:57 -04:00
gist.h Start using flexible array members 2011-06-16 22:45:38 +03:00
gistscan.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
hash.h Allow more include files to be compiled in their own by adding missing 2011-08-27 11:05:33 -04:00
heapam.h Clean up the #include mess a little. 2011-09-04 01:13:16 -04:00
hio.h Modify RelationGetBufferForTuple() to use a typedef, rather than a 2011-10-12 16:53:54 -04:00
htup.h Remove unnecessary AssertMacro() to suppress gcc 4.6 compiler warning. 2011-10-18 17:39:14 -04:00
itup.h pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
multixact.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
nbtree.h Teach btree to handle ScalarArrayOpExpr quals natively. 2011-10-16 15:39:24 -04:00
printtup.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
reloptions.h Change the way string relopts are allocated. 2011-08-09 15:25:44 +03:00
relscan.h Avoid assuming that index-only scan data matches the index's rowtype. 2011-10-16 19:15:04 -04:00
rewriteheap.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
rmgr.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
sdir.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
skey.h Teach btree to handle ScalarArrayOpExpr quals natively. 2011-10-16 15:39:24 -04:00
slru.h Use callbacks in SlruScanDirectory for the actual action 2011-10-04 14:03:23 -03:00
subtrans.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
sysattr.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
transam.h Make the visibility map crash-safe. 2011-06-21 23:04:40 -04:00
tupconvert.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
tupdesc.h Enable CHECK constraints to be declared NOT VALID 2011-06-30 11:24:31 -04:00
tupmacs.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
tuptoaster.h Fix race condition with toast table access from a stale syscache entry. 2011-11-01 19:49:58 -04:00
twophase_rmgr.h Renumber 2PC resource managers so that compared to 9.0, predicate lock rmgr 2011-06-14 12:36:31 +03:00
twophase.h Remove unnecessary #include references, per pgrminclude script. 2011-09-01 10:04:27 -04:00
valid.h Pass collations to functions in FunctionCallInfoData, not FmgrInfo. 2011-04-12 19:19:24 -04:00
visibilitymap.h Measure the number of all-visible pages for use in index-only scan costing. 2011-10-14 17:23:46 -04:00
xact.h Clean up the #include mess a little. 2011-09-04 01:13:16 -04:00
xlog_internal.h Split work of bgwriter between 2 processes: bgwriter and checkpointer. 2011-11-01 17:14:47 +00:00
xlog.h Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h. 2011-09-09 13:23:41 -04:00
xlogdefs.h pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
xlogutils.h Remove unnecessary #include references, per pgrminclude script. 2011-09-01 10:04:27 -04:00