PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_subscription.h File Reference
#include "catalog/genbki.h"
#include "nodes/pg_list.h"
Include dependency graph for pg_subscription.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Subscription
 

Macros

#define SubscriptionRelationId   6100
 
#define SubscriptionRelation_Rowtype_Id   6101
 
#define Natts_pg_subscription   8
 
#define Anum_pg_subscription_subdbid   1
 
#define Anum_pg_subscription_subname   2
 
#define Anum_pg_subscription_subowner   3
 
#define Anum_pg_subscription_subenabled   4
 
#define Anum_pg_subscription_subconninfo   5
 
#define Anum_pg_subscription_subslotname   6
 
#define Anum_pg_subscription_subsynccommit   7
 
#define Anum_pg_subscription_subpublications   8
 

Typedefs

typedef FormData_pg_subscriptionForm_pg_subscription
 
typedef struct Subscription Subscription
 

Functions

 CATALOG (pg_subscription, 6100) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101) BKI_SCHEMA_MACRO
 
SubscriptionGetSubscription (Oid subid, bool missing_ok)
 
void FreeSubscription (Subscription *sub)
 
Oid get_subscription_oid (const char *subname, bool missing_ok)
 
char * get_subscription_name (Oid subid)
 
int CountDBSubscriptions (Oid dbid)
 

Variables

 FormData_pg_subscription
 

Macro Definition Documentation

#define Anum_pg_subscription_subconninfo   5
#define Anum_pg_subscription_subdbid   1

Definition at line 65 of file pg_subscription.h.

Referenced by CountDBSubscriptions(), and CreateSubscription().

#define Anum_pg_subscription_subenabled   4

Definition at line 68 of file pg_subscription.h.

Referenced by AlterSubscription(), and CreateSubscription().

#define Anum_pg_subscription_subname   2

Definition at line 66 of file pg_subscription.h.

Referenced by CreateSubscription(), and DropSubscription().

#define Anum_pg_subscription_subowner   3

Definition at line 67 of file pg_subscription.h.

Referenced by CreateSubscription().

#define Anum_pg_subscription_subpublications   8

Definition at line 72 of file pg_subscription.h.

Referenced by AlterSubscription(), CreateSubscription(), and GetSubscription().

#define Anum_pg_subscription_subslotname   6
#define Anum_pg_subscription_subsynccommit   7

Definition at line 71 of file pg_subscription.h.

Referenced by AlterSubscription(), CreateSubscription(), and GetSubscription().

#define Natts_pg_subscription   8
#define SubscriptionRelation_Rowtype_Id   6101

Definition at line 23 of file pg_subscription.h.

Referenced by RelationCacheInitializePhase2().

Typedef Documentation

Function Documentation

CATALOG ( pg_subscription  ,
6100   
)

Definition at line 33 of file pg_subscription.h.

References BKI_FORCE_NOT_NULL.

34 {
35  Oid subdbid; /* Database the subscription is in. */
36  NameData subname; /* Name of the subscription */
37 
38  Oid subowner; /* Owner of the subscription */
39 
40  bool subenabled; /* True if the subscription is enabled (the
41  * worker should be running) */
42 
43 #ifdef CATALOG_VARLEN /* variable-length fields start here */
44  /* Connection string to the publisher */
45  text subconninfo BKI_FORCE_NOT_NULL;
46 
47  /* Slot name on publisher */
48  NameData subslotname;
49 
50  /* Synchronous commit setting for worker */
51  text subsynccommit BKI_FORCE_NOT_NULL;
52 
53  /* List of publications subscribed to */
54  text subpublications[1] BKI_FORCE_NOT_NULL;
55 #endif
FormData_pg_subscription
unsigned int Oid
Definition: postgres_ext.h:31
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:32
Definition: c.h:487
Definition: c.h:433
int CountDBSubscriptions ( Oid  dbid)

Definition at line 118 of file pg_subscription.c.

References Anum_pg_subscription_subdbid, BTEqualStrategyNumber, heap_close, heap_open(), HeapTupleIsValid, InvalidOid, NoLock, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), SubscriptionRelationId, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by dropdb().

119 {
120  int nsubs = 0;
121  Relation rel;
122  ScanKeyData scankey;
123  SysScanDesc scan;
124  HeapTuple tup;
125 
127 
128  ScanKeyInit(&scankey,
130  BTEqualStrategyNumber, F_OIDEQ,
131  ObjectIdGetDatum(dbid));
132 
133  scan = systable_beginscan(rel, InvalidOid, false,
134  NULL, 1, &scankey);
135 
136  while (HeapTupleIsValid(tup = systable_getnext(scan)))
137  nsubs++;
138 
139  systable_endscan(scan);
140 
141  heap_close(rel, NoLock);
142 
143  return nsubs;
144 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define SubscriptionRelationId
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_subscription_subdbid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void FreeSubscription ( Subscription sub)

Definition at line 150 of file pg_subscription.c.

References Subscription::conninfo, list_free_deep(), Subscription::name, pfree(), Subscription::publications, and Subscription::slotname.

Referenced by maybe_reread_subscription().

151 {
152  pfree(sub->name);
153  pfree(sub->conninfo);
154  if (sub->slotname)
155  pfree(sub->slotname);
157  pfree(sub);
158 }
void list_free_deep(List *list)
Definition: list.c:1147
void pfree(void *pointer)
Definition: mcxt.c:949
List * publications
char* get_subscription_name ( Oid  subid)

Definition at line 184 of file pg_subscription.c.

References elog, ERROR, GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, pstrdup(), ReleaseSysCache(), SearchSysCache1(), and SUBSCRIPTIONOID.

Referenced by getObjectDescription(), and getObjectIdentityParts().

185 {
186  HeapTuple tup;
187  char *subname;
188  Form_pg_subscription subform;
189 
191 
192  if (!HeapTupleIsValid(tup))
193  elog(ERROR, "cache lookup failed for subscription %u", subid);
194 
195  subform = (Form_pg_subscription) GETSTRUCT(tup);
196  subname = pstrdup(NameStr(subform->subname));
197 
198  ReleaseSysCache(tup);
199 
200  return subname;
201 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1076
FormData_pg_subscription * Form_pg_subscription
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 167 of file pg_subscription.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetSysCacheOid2, MyDatabaseId, OidIsValid, and SUBSCRIPTIONNAME.

Referenced by get_object_address_unqualified().

168 {
169  Oid oid;
170 
172  CStringGetDatum(subname));
173  if (!OidIsValid(oid) && !missing_ok)
174  ereport(ERROR,
175  (errcode(ERRCODE_UNDEFINED_OBJECT),
176  errmsg("subscription \"%s\" does not exist", subname)));
177  return oid;
178 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:193
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
Oid MyDatabaseId
Definition: globals.c:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 47 of file pg_subscription.c.

References Anum_pg_subscription_subconninfo, Anum_pg_subscription_subpublications, Anum_pg_subscription_subslotname, Anum_pg_subscription_subsynccommit, Assert, Subscription::conninfo, DatumGetArrayTypeP, DatumGetName, Subscription::dbid, elog, Subscription::enabled, ERROR, GETSTRUCT, HeapTupleIsValid, Subscription::name, NameStr, ObjectIdGetDatum, Subscription::oid, Subscription::owner, palloc(), pstrdup(), Subscription::publications, ReleaseSysCache(), SearchSysCache1(), Subscription::slotname, SUBSCRIPTIONOID, Subscription::synccommit, SysCacheGetAttr(), textarray_to_stringlist(), and TextDatumGetCString.

Referenced by AlterSubscription(), ApplyWorkerMain(), and maybe_reread_subscription().

48 {
49  HeapTuple tup;
50  Subscription *sub;
51  Form_pg_subscription subform;
52  Datum datum;
53  bool isnull;
54 
56 
57  if (!HeapTupleIsValid(tup))
58  {
59  if (missing_ok)
60  return NULL;
61 
62  elog(ERROR, "cache lookup failed for subscription %u", subid);
63  }
64 
65  subform = (Form_pg_subscription) GETSTRUCT(tup);
66 
67  sub = (Subscription *) palloc(sizeof(Subscription));
68  sub->oid = subid;
69  sub->dbid = subform->subdbid;
70  sub->name = pstrdup(NameStr(subform->subname));
71  sub->owner = subform->subowner;
72  sub->enabled = subform->subenabled;
73 
74  /* Get conninfo */
76  tup,
78  &isnull);
79  Assert(!isnull);
80  sub->conninfo = TextDatumGetCString(datum);
81 
82  /* Get slotname */
84  tup,
86  &isnull);
87  if (!isnull)
88  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
89  else
90  sub->slotname = NULL;
91 
92  /* Get synccommit */
94  tup,
96  &isnull);
97  Assert(!isnull);
98  sub->synccommit = TextDatumGetCString(datum);
99 
100  /* Get publications */
102  tup,
104  &isnull);
105  Assert(!isnull);
107 
108  ReleaseSysCache(tup);
109 
110  return sub;
111 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define Anum_pg_subscription_subpublications
char * pstrdup(const char *in)
Definition: mcxt.c:1076
FormData_pg_subscription * Form_pg_subscription
#define DatumGetName(X)
Definition: postgres.h:591
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
static List * textarray_to_stringlist(ArrayType *textarray)
List * publications
#define Anum_pg_subscription_subslotname
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define Anum_pg_subscription_subconninfo
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:681
void * palloc(Size size)
Definition: mcxt.c:848
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
#define Anum_pg_subscription_subsynccommit
#define DatumGetArrayTypeP(X)
Definition: array.h:246

Variable Documentation

FormData_pg_subscription

Definition at line 56 of file pg_subscription.h.