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   7
 
#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_subpublications   7
 

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 56 of file pg_subscription.h.

Referenced by CountDBSubscriptions(), and CreateSubscription().

#define Anum_pg_subscription_subenabled   4

Definition at line 59 of file pg_subscription.h.

Referenced by AlterSubscription(), and CreateSubscription().

#define Anum_pg_subscription_subname   2

Definition at line 57 of file pg_subscription.h.

Referenced by CreateSubscription(), and DropSubscription().

#define Anum_pg_subscription_subowner   3

Definition at line 58 of file pg_subscription.h.

Referenced by CreateSubscription().

#define Anum_pg_subscription_subpublications   7

Definition at line 62 of file pg_subscription.h.

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

#define Anum_pg_subscription_subslotname   6
#define Natts_pg_subscription   7
#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 31 of file pg_subscription.h.

32 {
33  Oid subdbid; /* Database the subscription is in. */
34  NameData subname; /* Name of the subscription */
35 
36  Oid subowner; /* Owner of the subscription */
37 
38  bool subenabled; /* True if the subscription is enabled
39  * (the worker should be running) */
40 
41 #ifdef CATALOG_VARLEN /* variable-length fields start here */
42  text subconninfo; /* Connection string to the publisher */
43  NameData subslotname; /* Slot name on publisher */
44 
45  text subpublications[1]; /* List of publications subscribed to */
46 #endif
FormData_pg_subscription
unsigned int Oid
Definition: postgres_ext.h:31
Definition: c.h:488
Definition: c.h:434
int CountDBSubscriptions ( Oid  dbid)

Definition at line 101 of file pg_subscription.c.

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

Referenced by dropdb().

102 {
103  int nsubs = 0;
104  Relation rel;
105  ScanKeyData scankey;
106  SysScanDesc scan;
107  HeapTuple tup;
108 
110 
111  ScanKeyInit(&scankey,
113  BTEqualStrategyNumber, F_OIDEQ,
114  ObjectIdGetDatum(dbid));
115 
116  scan = systable_beginscan(rel, InvalidOid, false,
117  NULL, 1, &scankey);
118 
119  while (HeapTupleIsValid(tup = systable_getnext(scan)))
120  nsubs++;
121 
122  systable_endscan(scan);
123 
124  heap_close(rel, NoLock);
125 
126  return nsubs;
127 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#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:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#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:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
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 133 of file pg_subscription.c.

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

Referenced by reread_subscription().

134 {
135  pfree(sub->name);
136  pfree(sub->conninfo);
137  pfree(sub->slotname);
139  pfree(sub);
140 }
void list_free_deep(List *list)
Definition: list.c:1147
void pfree(void *pointer)
Definition: mcxt.c:992
List * publications
char* get_subscription_name ( Oid  subid)

Definition at line 166 of file pg_subscription.c.

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

Referenced by getObjectDescription(), and getObjectIdentityParts().

167 {
168  HeapTuple tup;
169  char *subname;
170  Form_pg_subscription subform;
171 
173 
174  if (!HeapTupleIsValid(tup))
175  elog(ERROR, "cache lookup failed for subscription %u", subid);
176 
177  subform = (Form_pg_subscription) GETSTRUCT(tup);
178  subname = pstrdup(NameStr(subform->subname));
179 
180  ReleaseSysCache(tup);
181 
182  return subname;
183 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1165
FormData_pg_subscription * Form_pg_subscription
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NameStr(name)
Definition: c.h:494
#define elog
Definition: elog.h:219
Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 149 of file pg_subscription.c.

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

Referenced by get_object_address_unqualified().

150 {
151  Oid oid;
152 
154  CStringGetDatum(subname));
155  if (!OidIsValid(oid) && !missing_ok)
156  ereport(ERROR,
157  (errcode(ERRCODE_UNDEFINED_OBJECT),
158  errmsg("subscription \"%s\" does not exist", subname)));
159  return oid;
160 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:533
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:178
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:586
#define ereport(elevel, rest)
Definition: elog.h:122
Oid MyDatabaseId
Definition: globals.c:76
int errmsg(const char *fmt,...)
Definition: elog.c:797
Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 40 of file pg_subscription.c.

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

Referenced by ApplyWorkerMain(), and reread_subscription().

41 {
42  HeapTuple tup;
43  Subscription *sub;
44  Form_pg_subscription subform;
45  Datum datum;
46  bool isnull;
47 
49 
50  if (!HeapTupleIsValid(tup))
51  {
52  if (missing_ok)
53  return NULL;
54 
55  elog(ERROR, "cache lookup failed for subscription %u", subid);
56  }
57 
58  subform = (Form_pg_subscription) GETSTRUCT(tup);
59 
60  sub = (Subscription *) palloc(sizeof(Subscription));
61  sub->oid = subid;
62  sub->dbid = subform->subdbid;
63  sub->name = pstrdup(NameStr(subform->subname));
64  sub->owner = subform->subowner;
65  sub->enabled = subform->subenabled;
66 
67  /* Get conninfo */
69  tup,
71  &isnull);
72  Assert(!isnull);
73  sub->conninfo = pstrdup(TextDatumGetCString(datum));
74 
75  /* Get slotname */
77  tup,
79  &isnull);
80  Assert(!isnull);
81  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
82 
83  /* Get publications */
85  tup,
87  &isnull);
88  Assert(!isnull);
90 
91  ReleaseSysCache(tup);
92 
93  return sub;
94 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define Anum_pg_subscription_subpublications
char * pstrdup(const char *in)
Definition: mcxt.c:1165
FormData_pg_subscription * Form_pg_subscription
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define DatumGetName(X)
Definition: postgres.h:593
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
static List * textarray_to_stringlist(ArrayType *textarray)
List * publications
#define Anum_pg_subscription_subslotname
#define TextDatumGetCString(d)
Definition: builtins.h:91
uintptr_t Datum
Definition: postgres.h:374
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1245
#define Anum_pg_subscription_subconninfo
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
void * palloc(Size size)
Definition: mcxt.c:891
#define NameStr(name)
Definition: c.h:494
#define elog
Definition: elog.h:219
#define DatumGetArrayTypeP(X)
Definition: array.h:242

Variable Documentation

FormData_pg_subscription

Definition at line 47 of file pg_subscription.h.