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
2015-04-29 19:30:53 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pg_replication_origin.h
|
|
|
|
* Persistent replication origin registry
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* src/include/catalog/pg_replication_origin.h
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* the genbki.pl script reads this file and generates .bki
|
|
|
|
* information from the DATA() statements.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PG_REPLICATION_ORIGIN_H
|
|
|
|
#define PG_REPLICATION_ORIGIN_H
|
|
|
|
|
|
|
|
#include "catalog/genbki.h"
|
|
|
|
#include "access/xlogdefs.h"
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* pg_replication_origin. cpp turns this into
|
|
|
|
* typedef struct FormData_pg_replication_origin
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#define ReplicationOriginRelationId 6000
|
|
|
|
|
|
|
|
CATALOG(pg_replication_origin,6000) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Locally known id that get included into WAL.
|
|
|
|
*
|
|
|
|
* This should never leave the system.
|
|
|
|
*
|
2015-05-01 12:22:13 +02:00
|
|
|
* Needs to fit into an uint16, so we don't waste too much space in WAL
|
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
2015-04-29 19:30:53 +02:00
|
|
|
* records. For this reason we don't use a normal Oid column here, since
|
|
|
|
* we need to handle allocation of new values manually.
|
|
|
|
*/
|
|
|
|
Oid roident;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable-length fields start here, but we allow direct access to
|
|
|
|
* roname.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* external, free-format, name */
|
|
|
|
text roname BKI_FORCE_NOT_NULL;
|
|
|
|
|
|
|
|
#ifdef CATALOG_VARLEN /* further variable-length fields */
|
|
|
|
#endif
|
|
|
|
} FormData_pg_replication_origin;
|
|
|
|
|
|
|
|
typedef FormData_pg_replication_origin *Form_pg_replication_origin;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* compiler constants for pg_replication_origin
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
#define Natts_pg_replication_origin 2
|
|
|
|
#define Anum_pg_replication_origin_roident 1
|
|
|
|
#define Anum_pg_replication_origin_roname 2
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* pg_replication_origin has no initial contents
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* PG_REPLICATION_ORIGIN_H */
|