1 /* -------------------------------------------------------------------------
2  *
3  * pg_subscription.h
4  *	  definition of the "subscription" system catalog (pg_subscription)
5  *
6  * Portions Copyright (c) 1996-2020, 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  * NOTE:  When adding a column, also update system_views.sql.
38  */
39 CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
40 {
41 	Oid			oid;			/* oid */
42 
43 	Oid			subdbid;		/* Database the subscription is in. */
44 	NameData	subname;		/* Name of the subscription */
45 
46 	Oid			subowner;		/* Owner of the subscription */
47 
48 	bool		subenabled;		/* True if the subscription is enabled (the
49 								 * worker should be running) */
50 
51 #ifdef CATALOG_VARLEN			/* variable-length fields start here */
52 	/* Connection string to the publisher */
53 	text		subconninfo BKI_FORCE_NOT_NULL;
54 
55 	/* Slot name on publisher */
56 	NameData	subslotname BKI_FORCE_NULL;
57 
58 	/* Synchronous commit setting for worker */
59 	text		subsynccommit BKI_FORCE_NOT_NULL;
60 
61 	/* List of publications subscribed to */
62 	text		subpublications[1] BKI_FORCE_NOT_NULL;
63 #endif
64 } FormData_pg_subscription;
65 
66 typedef FormData_pg_subscription *Form_pg_subscription;
67 
68 typedef struct Subscription
69 {
70 	Oid			oid;			/* Oid of the subscription */
71 	Oid			dbid;			/* Oid of the database which subscription is
72 								 * in */
73 	char	   *name;			/* Name of the subscription */
74 	Oid			owner;			/* Oid of the subscription owner */
75 	bool		enabled;		/* Indicates if the subscription is enabled */
76 	char	   *conninfo;		/* Connection string to the publisher */
77 	char	   *slotname;		/* Name of the replication slot */
78 	char	   *synccommit;		/* Synchronous commit setting for worker */
79 	List	   *publications;	/* List of publication names to subscribe to */
80 } Subscription;
81 
82 extern Subscription *GetSubscription(Oid subid, bool missing_ok);
83 extern void FreeSubscription(Subscription *sub);
84 extern Oid	get_subscription_oid(const char *subname, bool missing_ok);
85 extern char *get_subscription_name(Oid subid, bool missing_ok);
86 
87 extern int	CountDBSubscriptions(Oid dbid);
88 
89 #endif							/* PG_SUBSCRIPTION_H */
90