PostgreSQL Source Code  git master
pg_subscription.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  *
3  * pg_subscription.h
4  * definition of the "subscription" system catalog (pg_subscription)
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/catalog/pg_subscription.h
10  *
11  * NOTES
12  * The Catalog.pm module reads this file and derives schema
13  * information.
14  *
15  * -------------------------------------------------------------------------
16  */
17 #ifndef PG_SUBSCRIPTION_H
18 #define PG_SUBSCRIPTION_H
19 
20 #include "access/xlogdefs.h"
21 #include "catalog/genbki.h"
22 #include "catalog/pg_subscription_d.h"
23 
24 #include "nodes/pg_list.h"
25 
26 /*
27  * two_phase tri-state values. See comments atop worker.c to know more about
28  * these states.
29  */
30 #define LOGICALREP_TWOPHASE_STATE_DISABLED 'd'
31 #define LOGICALREP_TWOPHASE_STATE_PENDING 'p'
32 #define LOGICALREP_TWOPHASE_STATE_ENABLED 'e'
33 
34 /*
35  * The subscription will request the publisher to only send changes that do not
36  * have any origin.
37  */
38 #define LOGICALREP_ORIGIN_NONE "none"
39 
40 /*
41  * The subscription will request the publisher to send changes regardless
42  * of their origin.
43  */
44 #define LOGICALREP_ORIGIN_ANY "any"
45 
46 /* ----------------
47  * pg_subscription definition. cpp turns this into
48  * typedef struct FormData_pg_subscription
49  * ----------------
50  */
51 
52 /*
53  * Technically, the subscriptions live inside the database, so a shared catalog
54  * seems weird, but the replication launcher process needs to access all of
55  * them to be able to start the workers, so we have to put them in a shared,
56  * nailed catalog.
57  *
58  * CAUTION: There is a GRANT in system_views.sql to grant public select
59  * access on all columns except subconninfo. When you add a new column
60  * here, be sure to update that (or, if the new column is not to be publicly
61  * readable, update associated comments and catalogs.sgml instead).
62  */
63 CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
64 {
65  Oid oid; /* oid */
66 
67  Oid subdbid BKI_LOOKUP(pg_database); /* Database the
68  * subscription is in. */
69 
70  XLogRecPtr subskiplsn; /* All changes finished at this LSN are
71  * skipped */
72 
73  NameData subname; /* Name of the subscription */
74 
75  Oid subowner BKI_LOOKUP(pg_authid); /* Owner of the subscription */
76 
77  bool subenabled; /* True if the subscription is enabled (the
78  * worker should be running) */
79 
80  bool subbinary; /* True if the subscription wants the
81  * publisher to send data in binary */
82 
83  bool substream; /* Stream in-progress transactions. */
84 
85  char subtwophasestate; /* Stream two-phase transactions */
86 
87  bool subdisableonerr; /* True if a worker error should cause the
88  * subscription to be disabled */
89 
90 #ifdef CATALOG_VARLEN /* variable-length fields start here */
91  /* Connection string to the publisher */
92  text subconninfo BKI_FORCE_NOT_NULL;
93 
94  /* Slot name on publisher */
95  NameData subslotname BKI_FORCE_NULL;
96 
97  /* Synchronous commit setting for worker */
98  text subsynccommit BKI_FORCE_NOT_NULL;
99 
100  /* List of publications subscribed to */
101  text subpublications[1] BKI_FORCE_NOT_NULL;
102 
103  /* Only publish data originating from the specified origin */
105 #endif
107 
109 
110 DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex);
111 
112 DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops));
113 DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, on pg_subscription using btree(subdbid oid_ops, subname name_ops));
114 
115 typedef struct Subscription
116 {
117  Oid oid; /* Oid of the subscription */
118  Oid dbid; /* Oid of the database which subscription is
119  * in */
120  XLogRecPtr skiplsn; /* All changes finished at this LSN are
121  * skipped */
122  char *name; /* Name of the subscription */
123  Oid owner; /* Oid of the subscription owner */
124  bool enabled; /* Indicates if the subscription is enabled */
125  bool binary; /* Indicates if the subscription wants data in
126  * binary format */
127  bool stream; /* Allow streaming in-progress transactions. */
128  char twophasestate; /* Allow streaming two-phase transactions */
129  bool disableonerr; /* Indicates if the subscription should be
130  * automatically disabled if a worker error
131  * occurs */
132  char *conninfo; /* Connection string to the publisher */
133  char *slotname; /* Name of the replication slot */
134  char *synccommit; /* Synchronous commit setting for worker */
135  List *publications; /* List of publication names to subscribe to */
136  char *origin; /* Only publish data originating from the
137  * specified origin */
139 
140 extern Subscription *GetSubscription(Oid subid, bool missing_ok);
141 extern void FreeSubscription(Subscription *sub);
142 extern void DisableSubscription(Oid subid);
143 
144 extern int CountDBSubscriptions(Oid dbid);
145 
146 #endif /* PG_SUBSCRIPTION_H */
#define BKI_DEFAULT(value)
Definition: genbki.h:35
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:33
#define BKI_FORCE_NULL
Definition: genbki.h:32
#define BKI_SHARED_RELATION
Definition: genbki.h:27
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition: genbki.h:28
bool subdisableonerr
CATALOG(pg_subscription, 6100, SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101
int CountDBSubscriptions(Oid dbid)
bool subenabled
char subtwophasestate
DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex)
#define LOGICALREP_ORIGIN_ANY
void FreeSubscription(Subscription *sub)
void DisableSubscription(Oid subid)
NameData subname
Subscription * GetSubscription(Oid subid, bool missing_ok)
XLogRecPtr subskiplsn
FormData_pg_subscription
bool subbinary
struct Subscription Subscription
DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops))
DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, on pg_subscription using btree(subdbid oid_ops, subname name_ops))
Oid subdbid BKI_LOOKUP(pg_database)
FormData_pg_subscription * Form_pg_subscription
bool substream
SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
unsigned int Oid
Definition: postgres_ext.h:31
Definition: pg_list.h:52
XLogRecPtr skiplsn
Definition: c.h:677
Definition: c.h:623
uint64 XLogRecPtr
Definition: xlogdefs.h:21