postgresql/src/include/utils
Tom Lane ffaa44cb55 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
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h Add location field to DefElem 2016-09-06 12:00:00 -04:00
aclchk_internal.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
array.h In plpgsql, don't try to convert int2vector or oidvector to expanded array. 2016-08-18 14:49:08 -04:00
arrayaccess.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ascii.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
attoptcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
builtins.h Remove unnecessary int2vector-specific hash function and equality operator. 2016-10-12 14:54:08 -04:00
bytea.h Extend sortsupport for text to more opclasses. 2016-02-03 14:29:53 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
combocid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
date.h Improve parsetree representation of special functions such as CURRENT_DATE. 2016-08-16 20:33:01 -04:00
datetime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
datum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynahash.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynamic_loader.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
elog.h Improve unreachability recognition in elog() macro. 2016-09-10 17:54:23 -04:00
evtcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
expandeddatum.h Inline the easy cases in MakeExpandedObjectReadOnly(). 2016-06-03 18:34:05 -04:00
fmgrtab.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
formatting.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
geo_decls.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
guc.h Show a sensible value in pg_settings.unit for GUC_UNIT_XSEGS variables. 2016-10-03 16:40:25 -04:00
guc_tables.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
help_config.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
hsearch.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
index_selfuncs.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
inet.h Create an SP-GiST opclass for inet/cidr. 2016-08-23 15:16:30 -04:00
int8.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
inval.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
json.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
jsonapi.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
jsonb.h Fix breakage in previous change 2016-09-30 15:27:51 -04:00
logtape.h Simplify the code for logical tape read buffers. 2016-10-12 12:05:45 +03:00
lsyscache.h Improve index AMs' opclass validation procedures. 2016-01-21 19:47:15 -05:00
memdebug.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
memutils.h Add macros to make AllocSetContextCreate() calls simpler and safer. 2016-08-27 17:50:38 -04:00
nabstime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
numeric.h Remove bogus dependencies on NUMERIC_MAX_PRECISION. 2016-08-14 15:06:01 -04:00
palloc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_crc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_locale.h Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>. 2016-03-15 13:19:57 -04:00
pg_lsn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_rusage.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
plancache.h Avoid invalidating all foreign-join cached plans when user mappings change. 2016-07-15 17:23:02 -04:00
portal.h Fix TOAST access failure in RETURNING queries. 2016-08-07 17:46:08 -04:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rel.h Re-allow user_catalog_table option for materialized views. 2016-11-10 15:00:58 -05:00
relcache.h Restore foreign-key-aware estimation of join relation sizes. 2016-06-18 15:22:34 -04:00
relfilenodemap.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
relmapper.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
reltrigger.h Implement syntax for transition tables in AFTER triggers. 2016-11-04 10:49:50 -05:00
resowner.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
resowner_private.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rls.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ruleutils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
sampling.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
selfuncs.h Support CREATE ACCESS METHOD 2016-03-23 23:01:35 -03:00
snapmgr.h Account for catalog snapshot in PGXACT->xmin updates. 2016-11-15 15:55:35 -05:00
snapshot.h Add the "snapshot too old" feature 2016-04-08 14:36:30 -05:00
sortsupport.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
spccache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
syscache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
timeout.h Be more predictable about reporting "lock timeout" vs "statement timeout". 2016-05-27 10:40:20 -04:00
timestamp.h Improve parsetree representation of special functions such as CURRENT_DATE. 2016-08-16 20:33:01 -04:00
tqual.h Fix copy-and-pasteo in 81c766b3fd. 2016-08-05 16:21:38 -04:00
tuplesort.h Reuse abbreviated keys in ordered [set] aggregates. 2016-02-17 15:40:00 +05:30
tuplestore.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
typcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tzparser.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
uuid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
varbit.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xml.h Update copyright for 2016 2016-01-02 13:33:40 -05:00