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-2021, 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 "catalog/genbki.h"
21 #include "catalog/pg_subscription_d.h"
22 
23 #include "nodes/pg_list.h"
24 
25 /*
26  * two_phase tri-state values. See comments atop worker.c to know more about
27  * these states.
28  */
29 #define LOGICALREP_TWOPHASE_STATE_DISABLED 'd'
30 #define LOGICALREP_TWOPHASE_STATE_PENDING 'p'
31 #define LOGICALREP_TWOPHASE_STATE_ENABLED 'e'
32 
33 /* ----------------
34  * pg_subscription definition. cpp turns this into
35  * typedef struct FormData_pg_subscription
36  * ----------------
37  */
38 
39 /*
40  * Technically, the subscriptions live inside the database, so a shared catalog
41  * seems weird, but the replication launcher process needs to access all of
42  * them to be able to start the workers, so we have to put them in a shared,
43  * nailed catalog.
44  *
45  * CAUTION: There is a GRANT in system_views.sql to grant public select
46  * access on all columns except subconninfo. When you add a new column
47  * here, be sure to update that (or, if the new column is not to be publicly
48  * readable, update associated comments and catalogs.sgml instead).
49  */
50 CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
51 {
52  Oid oid; /* oid */
53 
54  Oid subdbid BKI_LOOKUP(pg_database); /* Database the
55  * subscription is in. */
56  NameData subname; /* Name of the subscription */
57 
58  Oid subowner BKI_LOOKUP(pg_authid); /* Owner of the subscription */
59 
60  bool subenabled; /* True if the subscription is enabled (the
61  * worker should be running) */
62 
63  bool subbinary; /* True if the subscription wants the
64  * publisher to send data in binary */
65 
66  bool substream; /* Stream in-progress transactions. */
67 
68  char subtwophasestate; /* Stream two-phase transactions */
69 
70 #ifdef CATALOG_VARLEN /* variable-length fields start here */
71  /* Connection string to the publisher */
72  text subconninfo BKI_FORCE_NOT_NULL;
73 
74  /* Slot name on publisher */
75  NameData subslotname BKI_FORCE_NULL;
76 
77  /* Synchronous commit setting for worker */
78  text subsynccommit BKI_FORCE_NOT_NULL;
79 
80  /* List of publications subscribed to */
81  text subpublications[1] BKI_FORCE_NOT_NULL;
82 #endif
84 
86 
87 DECLARE_TOAST(pg_subscription, 4183, 4184);
88 #define PgSubscriptionToastTable 4183
89 #define PgSubscriptionToastIndex 4184
90 
91 DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops));
92 DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, on pg_subscription using btree(subdbid oid_ops, subname name_ops));
93 
94 typedef struct Subscription
95 {
96  Oid oid; /* Oid of the subscription */
97  Oid dbid; /* Oid of the database which subscription is
98  * in */
99  char *name; /* Name of the subscription */
100  Oid owner; /* Oid of the subscription owner */
101  bool enabled; /* Indicates if the subscription is enabled */
102  bool binary; /* Indicates if the subscription wants data in
103  * binary format */
104  bool stream; /* Allow streaming in-progress transactions. */
105  char twophasestate; /* Allow streaming two-phase transactions */
106  char *conninfo; /* Connection string to the publisher */
107  char *slotname; /* Name of the replication slot */
108  char *synccommit; /* Synchronous commit setting for worker */
109  List *publications; /* List of publication names to subscribe to */
110 } Subscription;
111 
112 extern Subscription *GetSubscription(Oid subid, bool missing_ok);
113 extern void FreeSubscription(Subscription *sub);
114 extern Oid get_subscription_oid(const char *subname, bool missing_ok);
115 extern char *get_subscription_name(Oid subid, bool missing_ok);
116 
117 extern int CountDBSubscriptions(Oid dbid);
118 
119 #endif /* PG_SUBSCRIPTION_H */
FormData_pg_subscription
#define BKI_SHARED_RELATION
Definition: genbki.h:27
DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, on pg_subscription using btree(subdbid oid_ops, subname name_ops))
FormData_pg_subscription * Form_pg_subscription
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
bool substream
Subscription * GetSubscription(Oid subid, bool missing_ok)
int CountDBSubscriptions(Oid dbid)
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:33
CATALOG(pg_subscription, 6100, SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101
DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops))
#define BKI_FORCE_NULL
Definition: genbki.h:32
Definition: c.h:675
DECLARE_TOAST(pg_subscription, 4183, 4184)
SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
char * get_subscription_name(Oid subid, bool missing_ok)
#define BKI_ROWTYPE_OID(oid, oidmacro)
Definition: genbki.h:28
void FreeSubscription(Subscription *sub)
struct Subscription Subscription
bool subbinary
char subtwophasestate
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: c.h:621
bool subenabled
Oid subdbid BKI_LOOKUP(pg_database)
Definition: pg_list.h:50