postgresql/src/include
Tom Lane 0bc3ed98c0 Account for catalog snapshot in PGXACT->xmin updates.
The CatalogSnapshot was not plugged into SnapshotResetXmin()'s accounting
for whether MyPgXact->xmin could be cleared or advanced.  In normal
transactions this was masked by the fact that the transaction snapshot
would be older, but during backend startup and certain utility commands
it was possible to re-use the CatalogSnapshot after MyPgXact->xmin had
been cleared, meaning that recently-deleted rows could be pruned even
though this snapshot could still see them, causing unexpected catalog
lookup failures.  This effect appears to be the explanation for a recent
failure on buildfarm member piculet.

To fix, add the CatalogSnapshot to the RegisteredSnapshots heap whenever
it is valid.

In the previous logic, it was possible for the CatalogSnapshot to remain
valid across waits for client input, but with this change that would mean
it delays advance of global xmin in cases where it did not before.  To
avoid possibly causing new table-bloat problems with clients that sit idle
for long intervals, add code to invalidate the CatalogSnapshot before
waiting for client input.  (When the backend is busy, it's unlikely that
the CatalogSnapshot would be the oldest snap for very long, so we don't
worry about forcing early invalidation of it otherwise.)

In passing, remove the CatalogSnapshotStale flag in favor of using
"CatalogSnapshot != NULL" to represent validity, as we do for the other
special snapshots in snapmgr.c.  And improve some obsolete comments.

No regression test because I don't know a deterministic way to cause this
failure.  But the stress test shown in the original discussion provokes
"cache lookup failed for relation 1255" within a few dozen seconds for me.

Back-patch to 9.4 where MVCC catalog scans were introduced.  (Note: it's
quite easy to produce similar failures with the same test case in branches
before 9.4.  But MVCC catalog scans were supposed to fix that.)

Discussion: <16447.1478818294@sss.pgh.pa.us>
2016-11-15 15:55:35 -05:00
..
access Remove duplicate macro definition. 2016-11-05 11:51:46 -04:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Fix copy-pasto in comment. 2016-10-12 12:08:54 +03:00
commands Rework internals of changing a type's ownership 2015-12-17 14:25:41 -03:00
common pgindent run for 9.5 2015-05-23 21:35:49 -04:00
datatype Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
executor Mark read/write expanded values as read-only in ExecProject(). 2016-06-03 15:14:35 -04:00
foreign Allow foreign and custom joins to handle EvalPlanQual rechecks. 2015-12-08 12:54:33 -05:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:19 -04:00
libpq Fix pq_putmessage_noblock() to not block. 2016-07-29 12:53:02 -04:00
mb Teach UtfToLocal/LocalToUtf to support algorithmic encoding conversions. 2015-05-14 22:27:12 -04:00
nodes Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:50 -04:00
optimizer Fix mishandling of equivalence-class tests in parameterized plans. 2016-04-29 20:19:38 -04:00
parser Create new ParseExprKind for use by policy expressions. 2015-07-29 15:41:00 -07:00
port Fix fallback implementation of pg_atomic_write_u32(). 2016-10-07 17:00:58 -07:00
portability Use mmap MAP_NOSYNC option to limit shared memory writes 2015-03-21 22:06:19 -04:00
postmaster Avoid using PostmasterRandom() for DSM control segment ID. 2016-09-23 09:54:11 -04:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:11:52 -05:00
replication logical decoding: Fix handling of large old tuples with replica identity full. 2016-03-05 18:02:20 -08:00
rewrite RLS refactoring 2015-09-15 15:49:40 -04:00
snowball Update copyright for 2015 2015-01-06 11:43:47 -05:00
storage Don't CHECK_FOR_INTERRUPTS between WaitLatch and ResetLatch. 2016-08-01 15:13:53 -04:00
tcop pgindent run for 9.5 2015-05-23 21:35:49 -04:00
tsearch Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member. 2015-02-20 17:50:18 -05:00
utils Account for catalog snapshot in PGXACT->xmin updates. 2016-11-15 15:55:35 -05:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Fix more typos in comments. 2015-05-20 19:45:43 +03:00
fmgr.h Revert addition of PGDLLEXPORT in PG_FUNCTION_INFO_V1 macro. 2016-10-12 18:02:03 -04:00
funcapi.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
getaddrinfo.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
getopt_long.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Install all headers for the new atomics API. 2014-10-02 16:52:21 +02:00
miscadmin.h Perform an immediate shutdown if the postmaster.pid file is removed. 2015-10-06 17:15:27 -04:00
pg_config.h.in Fix building with LibreSSL. 2016-09-15 22:38:01 +03:00
pg_config.h.win32 Stamp 9.5.5. 2016-10-24 16:10:50 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Further reduce the number of semaphores used under --disable-spinlocks. 2016-04-18 13:33:07 -04:00
pg_getopt.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_trace.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pgstat.h Don't reset changes_since_analyze after a selective-columns ANALYZE. 2016-06-06 17:44:17 -04:00
pgtar.h Adopt the GNU convention for handling tar-archive members exceeding 8GB. 2015-11-21 20:21:32 -05:00
pgtime.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
port.h Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
postgres.h Adjust DatumGetBool macro, this time for sure. 2016-04-28 11:51:08 -04:00
postgres_ext.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
postgres_fe.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
rusagestub.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
windowapi.h Update copyright for 2015 2015-01-06 11:43:47 -05:00