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-2025, 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" /* IWYU pragma: export */
23#include "lib/stringinfo.h"
24#include "nodes/pg_list.h"
25
26/* ----------------
27 * pg_subscription definition. cpp turns this into
28 * typedef struct FormData_pg_subscription
29 * ----------------
30 */
31
32/*
33 * Technically, the subscriptions live inside the database, so a shared catalog
34 * seems weird, but the replication launcher process needs to access all of
35 * them to be able to start the workers, so we have to put them in a shared,
36 * nailed catalog.
37 *
38 * CAUTION: There is a GRANT in system_views.sql to grant public select
39 * access on all columns except subconninfo. When you add a new column
40 * here, be sure to update that (or, if the new column is not to be publicly
41 * readable, update associated comments and catalogs.sgml instead).
42 */
43CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
44{
45 Oid oid; /* oid */
46
47 Oid subdbid BKI_LOOKUP(pg_database); /* Database the
48 * subscription is in. */
49
50 XLogRecPtr subskiplsn; /* All changes finished at this LSN are
51 * skipped */
52
53 NameData subname; /* Name of the subscription */
54
55 Oid subowner BKI_LOOKUP(pg_authid); /* Owner of the subscription */
56
57 bool subenabled; /* True if the subscription is enabled (the
58 * worker should be running) */
59
60 bool subbinary; /* True if the subscription wants the
61 * publisher to send data in binary */
62
63 char substream; /* Stream in-progress transactions. See
64 * LOGICALREP_STREAM_xxx constants. */
65
66 char subtwophasestate; /* Stream two-phase transactions */
67
68 bool subdisableonerr; /* True if a worker error should cause the
69 * subscription to be disabled */
70
71 bool subpasswordrequired; /* Must connection use a password? */
72
73 bool subrunasowner; /* True if replication should execute as the
74 * subscription owner */
75
76 bool subfailover; /* True if the associated replication slots
77 * (i.e. the main slot and the table sync
78 * slots) in the upstream database are enabled
79 * to be synchronized to the standbys. */
80
81#ifdef CATALOG_VARLEN /* variable-length fields start here */
82 /* Connection string to the publisher */
83 text subconninfo BKI_FORCE_NOT_NULL;
84
85 /* Slot name on publisher */
86 NameData subslotname BKI_FORCE_NULL;
87
88 /* Synchronous commit setting for worker */
89 text subsynccommit BKI_FORCE_NOT_NULL;
90
91 /* List of publications subscribed to */
92 text subpublications[1] BKI_FORCE_NOT_NULL;
93
94 /* Only publish data originating from the specified origin */
95 text suborigin BKI_DEFAULT(LOGICALREP_ORIGIN_ANY);
96#endif
98
100
101DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex);
102
103DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, pg_subscription, btree(oid oid_ops));
104DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, pg_subscription, btree(subdbid oid_ops, subname name_ops));
105
106MAKE_SYSCACHE(SUBSCRIPTIONOID, pg_subscription_oid_index, 4);
107MAKE_SYSCACHE(SUBSCRIPTIONNAME, pg_subscription_subname_index, 4);
108
109typedef struct Subscription
110{
111 Oid oid; /* Oid of the subscription */
112 Oid dbid; /* Oid of the database which subscription is
113 * in */
114 XLogRecPtr skiplsn; /* All changes finished at this LSN are
115 * skipped */
116 char *name; /* Name of the subscription */
117 Oid owner; /* Oid of the subscription owner */
118 bool ownersuperuser; /* Is the subscription owner a superuser? */
119 bool enabled; /* Indicates if the subscription is enabled */
120 bool binary; /* Indicates if the subscription wants data in
121 * binary format */
122 char stream; /* Allow streaming in-progress transactions.
123 * See LOGICALREP_STREAM_xxx constants. */
124 char twophasestate; /* Allow streaming two-phase transactions */
125 bool disableonerr; /* Indicates if the subscription should be
126 * automatically disabled if a worker error
127 * occurs */
128 bool passwordrequired; /* Must connection use a password? */
129 bool runasowner; /* Run replication as subscription owner */
130 bool failover; /* True if the associated replication slots
131 * (i.e. the main slot and the table sync
132 * slots) in the upstream database are enabled
133 * to be synchronized to the standbys. */
134 char *conninfo; /* Connection string to the publisher */
135 char *slotname; /* Name of the replication slot */
136 char *synccommit; /* Synchronous commit setting for worker */
137 List *publications; /* List of publication names to subscribe to */
138 char *origin; /* Only publish data originating from the
139 * specified origin */
141
142#ifdef EXPOSE_TO_CLIENT_CODE
143
144/*
145 * two_phase tri-state values. See comments atop worker.c to know more about
146 * these states.
147 */
148#define LOGICALREP_TWOPHASE_STATE_DISABLED 'd'
149#define LOGICALREP_TWOPHASE_STATE_PENDING 'p'
150#define LOGICALREP_TWOPHASE_STATE_ENABLED 'e'
151
152/*
153 * The subscription will request the publisher to only send changes that do not
154 * have any origin.
155 */
156#define LOGICALREP_ORIGIN_NONE "none"
157
158/*
159 * The subscription will request the publisher to send changes regardless
160 * of their origin.
161 */
162#define LOGICALREP_ORIGIN_ANY "any"
163
164/* Disallow streaming in-progress transactions. */
165#define LOGICALREP_STREAM_OFF 'f'
166
167/*
168 * Streaming in-progress transactions are written to a temporary file and
169 * applied only after the transaction is committed on upstream.
170 */
171#define LOGICALREP_STREAM_ON 't'
172
173/*
174 * Streaming in-progress transactions are applied immediately via a parallel
175 * apply worker.
176 */
177#define LOGICALREP_STREAM_PARALLEL 'p'
178
179#endif /* EXPOSE_TO_CLIENT_CODE */
180
181extern Subscription *GetSubscription(Oid subid, bool missing_ok);
182extern void FreeSubscription(Subscription *sub);
183extern void DisableSubscription(Oid subid);
184
185extern int CountDBSubscriptions(Oid dbid);
186
187extern void GetPublicationsStr(List *publications, StringInfo dest,
188 bool quote_literal);
189
190#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 subrunasowner
bool subenabled
char subtwophasestate
DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex)
void FreeSubscription(Subscription *sub)
char substream
bool subpasswordrequired
void DisableSubscription(Oid subid)
NameData subname
void GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal)
XLogRecPtr subskiplsn
FormData_pg_subscription
bool subbinary
DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, pg_subscription, btree(oid oid_ops))
struct Subscription Subscription
Oid subdbid BKI_LOOKUP(pg_database)
MAKE_SYSCACHE(SUBSCRIPTIONOID, pg_subscription_oid_index, 4)
Subscription * GetSubscription(Oid subid, bool missing_ok)
FormData_pg_subscription * Form_pg_subscription
DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, pg_subscription, btree(subdbid oid_ops, subname name_ops))
bool subfailover
SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
unsigned int Oid
Definition: postgres_ext.h:32
Datum quote_literal(PG_FUNCTION_ARGS)
Definition: quote.c:78
Definition: pg_list.h:54
XLogRecPtr skiplsn
Definition: c.h:712
Definition: c.h:658
uint64 XLogRecPtr
Definition: xlogdefs.h:21