postgresql/src/backend
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
..
access Fix race condition with toast table access from a stale syscache entry. 2011-11-01 19:49:58 -04:00
bootstrap Split work of bgwriter between 2 processes: bgwriter and checkpointer. 2011-11-01 17:14:47 +00:00
catalog More cleanup after failed reduced-lock-levels-for-DDL feature. 2011-10-21 13:50:30 -04:00
commands Comment changes to show bgwriter no longer performs checkpoints. 2011-11-01 18:48:47 +00:00
executor Avoid assuming that index-only scan data matches the index's rowtype. 2011-10-16 19:15:04 -04:00
foreign deflist_to_tuplestore dumped core on an option with no value. 2011-09-13 11:36:49 -04:00
lib Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
libpq Reject empty pg_hba.conf files. 2011-10-18 20:09:18 -04:00
main Add postmaster -C option to query configuration parameters, and have 2011-10-06 09:38:39 -04:00
nodes Don't trust deferred-unique indexes for join removal. 2011-10-23 00:43:39 -04:00
optimizer Improve planner's ability to recognize cases where an IN's RHS is unique. 2011-10-26 17:52:29 -04:00
parser Clean up whitespace and indentation in parser and scanner files 2011-11-01 21:51:30 +02:00
po Translation updates 2011-08-17 14:07:46 +03:00
port Remove unnecessary #include references, per pgrminclude script. 2011-09-01 10:04:27 -04:00
postmaster Comment changes to show bgwriter no longer performs checkpoints. 2011-11-01 18:48:47 +00:00
regex Add markers for skips. 2011-08-26 18:15:13 -04:00
replication Clean up whitespace and indentation in parser and scanner files 2011-11-01 21:51:30 +02:00
rewrite More cleanup after failed reduced-lock-levels-for-DDL feature. 2011-10-21 13:50:30 -04:00
snowball Remove unnecessary #include references, per pgrminclude script. 2011-09-01 10:04:27 -04:00
storage Split work of bgwriter between 2 processes: bgwriter and checkpointer. 2011-11-01 17:14:47 +00:00
tcop Consolidate DROP handling for some object types. 2011-10-19 23:27:19 -04:00
tsearch Remove many -Wcast-qual warnings 2011-09-11 21:54:32 +03:00
utils Fix race condition with toast table access from a stale syscache entry. 2011-11-01 19:49:58 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Workaround for recursive make breakage 2011-01-13 09:32:06 +02:00
Makefile Fix symlink for errcodes.h so it works in VPATH builds from tarballs. 2011-06-22 13:08:08 -04:00
nls.mk Add the possibility to pass --flag arguments to xgettext calls 2011-06-27 00:37:21 +03:00