postgresql/src/include/utils
Tom Lane f3b5565dd4 Use a safer method for determining whether relcache init file is stale.
When we invalidate the relcache entry for a system catalog or index, we
must also delete the relcache "init file" if the init file contains a copy
of that rel's entry.  The old way of doing this relied on a specially
maintained list of the OIDs of relations present in the init file: we made
the list either when reading the file in, or when writing the file out.
The problem is that when writing the file out, we included only rels
present in our local relcache, which might have already suffered some
deletions due to relcache inval events.  In such cases we correctly decided
not to overwrite the real init file with incomplete data --- but we still
used the incomplete initFileRelationIds list for the rest of the current
session.  This could result in wrong decisions about whether the session's
own actions require deletion of the init file, potentially allowing an init
file created by some other concurrent session to be left around even though
it's been made stale.

Since we don't support changing the schema of a system catalog at runtime,
the only likely scenario in which this would cause a problem in the field
involves a "vacuum full" on a catalog concurrently with other activity, and
even then it's far from easy to provoke.  Remarkably, this has been broken
since 2002 (in commit 7863404417), but we had
never seen a reproducible test case until recently.  If it did happen in
the field, the symptoms would probably involve unexpected "cache lookup
failed" errors to begin with, then "could not open file" failures after the
next checkpoint, as all accesses to the affected catalog stopped working.
Recovery would require manually removing the stale "pg_internal.init" file.

To fix, get rid of the initFileRelationIds list, and instead consult
syscache.c's list of relations used in catalog caches to decide whether a
relation is included in the init file.  This should be a tad more efficient
anyway, since we're replacing linear search of a list with ~100 entries
with a binary search.  It's a bit ugly that the init file contents are now
so directly tied to the catalog caches, but in practice that won't make
much difference.

Back-patch to all supported branches.
2015-06-07 15:32:09 -04:00
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
aclchk_internal.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
array.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
arrayaccess.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
ascii.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
attoptcache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
builtins.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
bytea.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
combocid.h Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
date.h Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
datetime.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
datum.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
dynahash.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
dynamic_loader.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
elog.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
evtcache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
expandeddatum.h Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
fmgrtab.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
formatting.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
geo_decls.h Allow GiST distance function to return merely a lower-bound. 2015-05-15 14:26:51 +03:00
guc.h Revert exporting of internal GUC variable "data_directory". 2015-05-29 11:57:33 -04:00
guc_tables.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
help_config.h Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
hsearch.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
inet.h Add index-only scan support to inet GiST opclass. 2015-03-28 15:11:53 +02:00
int8.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
inval.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
json.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
jsonapi.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
jsonb.h Rename jsonb_replace to jsonb_set and allow it to add new values 2015-05-31 20:34:10 -04:00
logtape.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
lsyscache.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
memdebug.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
memutils.h Move memory context callback declarations into palloc.h. 2015-03-01 12:31:32 -05:00
nabstime.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
numeric.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
palloc.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
pg_crc.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
pg_locale.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_lsn.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_rusage.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
plancache.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
portal.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Move strategy numbers to include/access/stratnum.h 2015-05-15 17:03:16 -03:00
rel.h Fix more typos in comments. 2015-05-20 19:45:43 +03:00
relcache.h Use a safer method for determining whether relcache init file is stale. 2015-06-07 15:32:09 -04:00
relfilenodemap.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
relmapper.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
reltrigger.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
resowner.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
resowner_private.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
rls.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
ruleutils.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
sampling.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
selfuncs.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
snapmgr.h Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
snapshot.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
sortsupport.h pgindent run for 9.5 2015-05-23 21:35:49 -04:00
spccache.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
syscache.h Use a safer method for determining whether relcache init file is stale. 2015-06-07 15:32:09 -04:00
timeout.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
timestamp.h Add transform functions for AT TIME ZONE. 2015-03-01 13:22:34 -05:00
tqual.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tuplesort.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tuplestore.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
typcache.h Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
tzparser.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
uuid.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
varbit.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
xml.h Update copyright for 2015 2015-01-06 11:43:47 -05:00