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