|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* syscache.h
|
|
|
|
|
* System catalog cache definitions.
|
|
|
|
|
*
|
|
|
|
|
* See also lsyscache.h, which provides convenience routines for
|
|
|
|
|
* common cache-lookup operations.
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
* src/include/utils/syscache.h
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef SYSCACHE_H
|
|
|
|
|
#define SYSCACHE_H
|
|
|
|
|
|
|
|
|
|
#include "access/attnum.h"
|
|
|
|
|
#include "access/htup.h"
|
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 786340441706ac1957a031f11ad1c2e5b6e18314), 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.
11 years ago
|
|
|
/* we intentionally do not include utils/catcache.h here */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* SysCache identifiers.
|
|
|
|
|
*
|
|
|
|
|
* The order of these identifiers must match the order
|
|
|
|
|
* of the entries in the array cacheinfo[] in syscache.c.
|
|
|
|
|
* Keep them in alphabetical order (renumbering only costs a
|
|
|
|
|
* backend rebuild).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
enum SysCacheIdentifier
|
|
|
|
|
{
|
|
|
|
|
AGGFNOID = 0,
|
|
|
|
|
AMNAME,
|
|
|
|
|
AMOID,
|
|
|
|
|
AMOPOPID,
|
|
|
|
|
AMOPSTRATEGY,
|
|
|
|
|
AMPROCNUM,
|
|
|
|
|
ATTNAME,
|
|
|
|
|
ATTNUM,
|
|
|
|
|
AUTHMEMMEMROLE,
|
|
|
|
|
AUTHMEMROLEMEM,
|
|
|
|
|
AUTHNAME,
|
|
|
|
|
AUTHOID,
|
|
|
|
|
CASTSOURCETARGET,
|
|
|
|
|
CLAAMNAMENSP,
|
|
|
|
|
CLAOID,
|
|
|
|
|
COLLNAMEENCNSP,
|
|
|
|
|
COLLOID,
|
|
|
|
|
CONDEFAULT,
|
|
|
|
|
CONNAMENSP,
|
|
|
|
|
CONSTROID,
|
|
|
|
|
CONVOID,
|
|
|
|
|
DATABASEOID,
|
|
|
|
|
DEFACLROLENSPOBJ,
|
|
|
|
|
ENUMOID,
|
|
|
|
|
ENUMTYPOIDNAME,
|
|
|
|
|
EVENTTRIGGERNAME,
|
|
|
|
|
EVENTTRIGGEROID,
|
|
|
|
|
FOREIGNDATAWRAPPERNAME,
|
|
|
|
|
FOREIGNDATAWRAPPEROID,
|
|
|
|
|
FOREIGNSERVERNAME,
|
|
|
|
|
FOREIGNSERVEROID,
|
|
|
|
|
FOREIGNTABLEREL,
|
|
|
|
|
INDEXRELID,
|
|
|
|
|
LANGNAME,
|
|
|
|
|
LANGOID,
|
|
|
|
|
NAMESPACENAME,
|
|
|
|
|
NAMESPACEOID,
|
|
|
|
|
OPERNAMENSP,
|
|
|
|
|
OPEROID,
|
|
|
|
|
OPFAMILYAMNAMENSP,
|
|
|
|
|
OPFAMILYOID,
|
|
|
|
|
PROCNAMEARGSNSP,
|
|
|
|
|
PROCOID,
|
|
|
|
|
RANGETYPE,
|
|
|
|
|
RELNAMENSP,
|
|
|
|
|
RELOID,
|
Introduce replication progress tracking infrastructure.
When implementing a replication solution ontop of logical decoding, two
related problems exist:
* How to safely keep track of replication progress
* How to change replication behavior, based on the origin of a row;
e.g. to avoid loops in bi-directional replication setups
The solution to these problems, as implemented here, consist out of
three parts:
1) 'replication origins', which identify nodes in a replication setup.
2) 'replication progress tracking', which remembers, for each
replication origin, how far replay has progressed in a efficient and
crash safe manner.
3) The ability to filter out changes performed on the behest of a
replication origin during logical decoding; this allows complex
replication topologies. E.g. by filtering all replayed changes out.
Most of this could also be implemented in "userspace", e.g. by inserting
additional rows contain origin information, but that ends up being much
less efficient and more complicated. We don't want to require various
replication solutions to reimplement logic for this independently. The
infrastructure is intended to be generic enough to be reusable.
This infrastructure also replaces the 'nodeid' infrastructure of commit
timestamps. It is intended to provide all the former capabilities,
except that there's only 2^16 different origins; but now they integrate
with logical decoding. Additionally more functionality is accessible via
SQL. Since the commit timestamp infrastructure has also been introduced
in 9.5 (commit 73c986add) changing the API is not a problem.
For now the number of origins for which the replication progress can be
tracked simultaneously is determined by the max_replication_slots
GUC. That GUC is not a perfect match to configure this, but there
doesn't seem to be sufficient reason to introduce a separate new one.
Bumps both catversion and wal page magic.
Author: Andres Freund, with contributions from Petr Jelinek and Craig Ringer
Reviewed-By: Heikki Linnakangas, Petr Jelinek, Robert Haas, Steve Singer
Discussion: 20150216002155.GI15326@awork2.anarazel.de,
20140923182422.GA15776@alap3.anarazel.de,
20131114172632.GE7522@alap2.anarazel.de
11 years ago
|
|
|
REPLORIGIDENT,
|
|
|
|
|
REPLORIGNAME,
|
|
|
|
|
RULERELNAME,
|
|
|
|
|
STATRELATTINH,
|
|
|
|
|
TABLESPACEOID,
|
|
|
|
|
TRFOID,
|
|
|
|
|
TRFTYPELANG,
|
|
|
|
|
TSCONFIGMAP,
|
|
|
|
|
TSCONFIGNAMENSP,
|
|
|
|
|
TSCONFIGOID,
|
|
|
|
|
TSDICTNAMENSP,
|
|
|
|
|
TSDICTOID,
|
|
|
|
|
TSPARSERNAMENSP,
|
|
|
|
|
TSPARSEROID,
|
|
|
|
|
TSTEMPLATENAMENSP,
|
|
|
|
|
TSTEMPLATEOID,
|
|
|
|
|
TYPENAMENSP,
|
|
|
|
|
TYPEOID,
|
|
|
|
|
USERMAPPINGOID,
|
|
|
|
|
USERMAPPINGUSERSERVER
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern void InitCatalogCache(void);
|
|
|
|
|
extern void InitCatalogCachePhase2(void);
|
|
|
|
|
|
|
|
|
|
extern HeapTuple SearchSysCache(int cacheId,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
extern void ReleaseSysCache(HeapTuple tuple);
|
|
|
|
|
|
|
|
|
|
/* convenience routines */
|
|
|
|
|
extern HeapTuple SearchSysCacheCopy(int cacheId,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
extern bool SearchSysCacheExists(int cacheId,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
extern Oid GetSysCacheOid(int cacheId,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
|
|
|
|
|
extern HeapTuple SearchSysCacheAttName(Oid relid, const char *attname);
|
|
|
|
|
extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char *attname);
|
|
|
|
|
extern bool SearchSysCacheExistsAttName(Oid relid, const char *attname);
|
|
|
|
|
|
|
|
|
|
extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,
|
|
|
|
|
AttrNumber attributeNumber, bool *isNull);
|
|
|
|
|
|
|
|
|
|
extern uint32 GetSysCacheHashValue(int cacheId,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
|
|
|
|
|
/* list-search interface. Users of this must import catcache.h too */
|
|
|
|
|
struct catclist;
|
|
|
|
|
extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
|
|
|
|
|
Datum key1, Datum key2, Datum key3, Datum key4);
|
|
|
|
|
|
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 786340441706ac1957a031f11ad1c2e5b6e18314), 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.
11 years ago
|
|
|
extern bool RelationInvalidatesSnapshotsOnly(Oid relid);
|
|
|
|
|
extern bool RelationHasSysCache(Oid relid);
|
|
|
|
|
extern bool RelationSupportsSysCache(Oid relid);
|
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.
13 years ago
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The use of the macros below rather than direct calls to the corresponding
|
|
|
|
|
* functions is encouraged, as it insulates the caller from changes in the
|
|
|
|
|
* maximum number of keys.
|
|
|
|
|
*/
|
|
|
|
|
#define SearchSysCache1(cacheId, key1) \
|
|
|
|
|
SearchSysCache(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCache2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCache3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCache4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCache(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheCopy1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheCopy2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheCopy3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheCopy(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheExists1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheExists2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheExists3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheExists(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define GetSysCacheOid1(cacheId, key1) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define GetSysCacheOid2(cacheId, key1, key2) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define GetSysCacheOid3(cacheId, key1, key2, key3) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define GetSysCacheOid4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
GetSysCacheOid(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define GetSysCacheHashValue1(cacheId, key1) \
|
|
|
|
|
GetSysCacheHashValue(cacheId, key1, 0, 0, 0)
|
|
|
|
|
#define GetSysCacheHashValue2(cacheId, key1, key2) \
|
|
|
|
|
GetSysCacheHashValue(cacheId, key1, key2, 0, 0)
|
|
|
|
|
#define GetSysCacheHashValue3(cacheId, key1, key2, key3) \
|
|
|
|
|
GetSysCacheHashValue(cacheId, key1, key2, key3, 0)
|
|
|
|
|
#define GetSysCacheHashValue4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define SearchSysCacheList1(cacheId, key1) \
|
|
|
|
|
SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
|
|
|
|
|
#define SearchSysCacheList2(cacheId, key1, key2) \
|
|
|
|
|
SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
|
|
|
|
|
#define SearchSysCacheList3(cacheId, key1, key2, key3) \
|
|
|
|
|
SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
|
|
|
|
|
#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
|
|
|
|
|
SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
|
|
|
|
|
|
|
|
|
|
#define ReleaseSysCacheList(x) ReleaseCatCacheList(x)
|
|
|
|
|
|
|
|
|
|
#endif /* SYSCACHE_H */
|