Use an MVCC snapshot, rather than SnapshotNow, for catalog scans.
SnapshotNow scans have the undesirable property that, in the face of
concurrent updates, the scan can fail to see either the old or the new
versions of the row. In many cases, we work around this by requiring
DDL operations to hold AccessExclusiveLock on the object being
modified; in some cases, the existing locking is inadequate and random
failures occur as a result. This commit doesn't change anything
related to locking, but will hopefully pave the way to allowing lock
strength reductions in the future.
The major issue has held us back from making this change in the past
is that taking an MVCC snapshot is significantly more expensive than
using a static special snapshot such as SnapshotNow. However, testing
of various worst-case scenarios reveals that this problem is not
severe except under fairly extreme workloads. To mitigate those
problems, we avoid retaking the MVCC snapshot for each new scan;
instead, we take a new snapshot only when invalidation messages have
been processed. The catcache machinery already requires that
invalidation messages be sent before releasing the related heavyweight
lock; else other backends might rely on locally-cached data rather
than scanning the catalog at all. Thus, making snapshot reuse
dependent on the same guarantees shouldn't break anything that wasn't
already subtly broken.
Patch by me. Review by Michael Paquier and Andres Freund.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/568d4138c646cd7cd8a837ac244ef2caf27c6bb8
Modified Files
--------------
contrib/dblink/dblink.c | 2 +-
contrib/sepgsql/label.c | 2 +-
doc/src/sgml/indexam.sgml | 2 +-
src/backend/access/heap/heapam.c | 24 +++++--
src/backend/access/index/genam.c | 34 +++++++++-
src/backend/access/nbtree/README | 7 +-
src/backend/access/rmgrdesc/xactdesc.c | 5 +-
src/backend/bootstrap/bootstrap.c | 8 +--
src/backend/catalog/aclchk.c | 29 +++++----
src/backend/catalog/catalog.c | 24 +++----
src/backend/catalog/dependency.c | 6 +-
src/backend/catalog/heap.c | 16 ++---
src/backend/catalog/index.c | 28 ++++----
src/backend/catalog/namespace.c | 4 +-
src/backend/catalog/objectaddress.c | 24 +++----
src/backend/catalog/pg_collation.c | 2 +-
src/backend/catalog/pg_constraint.c | 14 ++--
src/backend/catalog/pg_conversion.c | 3 +-
src/backend/catalog/pg_db_role_setting.c | 9 +--
src/backend/catalog/pg_depend.c | 18 +++---
src/backend/catalog/pg_enum.c | 5 +-
src/backend/catalog/pg_inherits.c | 4 +-
src/backend/catalog/pg_largeobject.c | 16 ++---
src/backend/catalog/pg_range.c | 2 +-
src/backend/catalog/pg_shdepend.c | 16 ++---
src/backend/commands/cluster.c | 7 +-
src/backend/commands/comment.c | 10 +--
src/backend/commands/dbcommands.c | 66 +++----------------
src/backend/commands/extension.c | 20 +++---
src/backend/commands/functioncmds.c | 2 +-
src/backend/commands/indexcmds.c | 4 +-
src/backend/commands/opclasscmds.c | 6 +-
src/backend/commands/proclang.c | 2 +-
src/backend/commands/seclabel.c | 12 ++--
src/backend/commands/tablecmds.c | 59 ++++++++++-------
src/backend/commands/tablespace.c | 12 ++--
src/backend/commands/trigger.c | 18 +++---
src/backend/commands/tsearchcmds.c | 12 ++--
src/backend/commands/typecmds.c | 19 ++++--
src/backend/commands/user.c | 4 +-
src/backend/commands/vacuum.c | 6 +-
src/backend/executor/nodeBitmapHeapscan.c | 8 +--
src/backend/postmaster/autovacuum.c | 6 +-
src/backend/postmaster/pgstat.c | 6 +-
src/backend/rewrite/rewriteDefine.c | 6 +-
src/backend/rewrite/rewriteHandler.c | 4 +-
src/backend/rewrite/rewriteRemove.c | 2 +-
src/backend/rewrite/rewriteSupport.c | 2 +-
src/backend/storage/large_object/inv_api.c | 9 ++-
src/backend/utils/adt/dbsize.c | 2 +-
src/backend/utils/adt/regproc.c | 8 +--
src/backend/utils/adt/ruleutils.c | 4 +-
src/backend/utils/cache/catcache.c | 4 +-
src/backend/utils/cache/evtcache.c | 6 +-
src/backend/utils/cache/inval.c | 67 +++++++++++++++++--
src/backend/utils/cache/relcache.c | 24 +++----
src/backend/utils/cache/syscache.c | 97 +++++++++++++++++++++++++++-
src/backend/utils/cache/ts_cache.c | 2 +-
src/backend/utils/cache/typcache.c | 9 +--
src/backend/utils/init/postinit.c | 19 ++++--
src/backend/utils/time/snapmgr.c | 67 ++++++++++++++++++-
src/bin/pg_dump/pg_dump.c | 14 ++--
src/include/access/heapam.h | 2 +
src/include/access/relscan.h | 2 +
src/include/catalog/objectaccess.h | 4 +-
src/include/catalog/pg_db_role_setting.h | 4 +-
src/include/storage/sinval.h | 21 ++++--
src/include/utils/snapmgr.h | 3 +
src/include/utils/syscache.h | 3 +
69 files changed, 616 insertions(+), 352 deletions(-)