|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* snapmgr.h
|
|
|
|
|
* POSTGRES snapshot manager
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
* src/include/utils/snapmgr.h
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef SNAPMGR_H
|
|
|
|
|
#define SNAPMGR_H
|
|
|
|
|
|
|
|
|
|
#include "fmgr.h"
|
|
|
|
|
#include "utils/resowner.h"
|
|
|
|
|
#include "utils/snapshot.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern bool FirstSnapshotSet;
|
|
|
|
|
|
|
|
|
|
extern TransactionId TransactionXmin;
|
|
|
|
|
extern TransactionId RecentXmin;
|
|
|
|
|
extern TransactionId RecentGlobalXmin;
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
12 years ago
|
|
|
extern TransactionId RecentGlobalDataXmin;
|
|
|
|
|
|
|
|
|
|
extern Snapshot GetTransactionSnapshot(void);
|
|
|
|
|
extern Snapshot GetLatestSnapshot(void);
|
|
|
|
|
extern void SnapshotSetCommandId(CommandId curcid);
|
|
|
|
|
|
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
|
|
|
extern Snapshot GetCatalogSnapshot(Oid relid);
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
12 years ago
|
|
|
extern Snapshot GetNonHistoricCatalogSnapshot(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
|
|
|
extern void InvalidateCatalogSnapshot(void);
|
|
|
|
|
|
|
|
|
|
extern void PushActiveSnapshot(Snapshot snapshot);
|
|
|
|
|
extern void PushCopiedSnapshot(Snapshot snapshot);
|
|
|
|
|
extern void UpdateActiveSnapshotCommandId(void);
|
|
|
|
|
extern void PopActiveSnapshot(void);
|
|
|
|
|
extern Snapshot GetActiveSnapshot(void);
|
|
|
|
|
extern bool ActiveSnapshotSet(void);
|
|
|
|
|
|
|
|
|
|
extern Snapshot RegisterSnapshot(Snapshot snapshot);
|
|
|
|
|
extern void UnregisterSnapshot(Snapshot snapshot);
|
|
|
|
|
extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner);
|
|
|
|
|
extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
|
|
|
|
|
|
|
|
|
|
extern void AtSubCommit_Snapshot(int level);
|
|
|
|
|
extern void AtSubAbort_Snapshot(int level);
|
|
|
|
|
extern void AtEOXact_Snapshot(bool isCommit);
|
|
|
|
|
|
|
|
|
|
extern Datum pg_export_snapshot(PG_FUNCTION_ARGS);
|
|
|
|
|
extern void ImportSnapshot(const char *idstr);
|
|
|
|
|
extern bool XactHasExportedSnapshots(void);
|
|
|
|
|
extern void DeleteAllExportedSnapshotFiles(void);
|
|
|
|
|
extern bool ThereAreNoPriorRegisteredSnapshots(void);
|
|
|
|
|
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
12 years ago
|
|
|
extern char *ExportSnapshot(Snapshot snapshot);
|
|
|
|
|
|
|
|
|
|
/* Support for catalog timetravel for logical decoding */
|
|
|
|
|
struct HTAB;
|
|
|
|
|
extern struct HTAB *HistoricSnapshotGetTupleCids(void);
|
|
|
|
|
extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB *tuplecids);
|
|
|
|
|
extern void TeardownHistoricSnapshot(bool is_error);
|
|
|
|
|
extern bool HistoricSnapshotActive(void);
|
|
|
|
|
|
|
|
|
|
#endif /* SNAPMGR_H */
|