PostgreSQL Source Code  git master
pg_subscription.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_subscription_d.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
 

Typedefs

typedef FormData_pg_subscriptionForm_pg_subscription
 
typedef struct Subscription Subscription
 

Functions

 CATALOG (pg_subscription, 6100, SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101
 
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

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
 
NameData subname
 
Oid subowner
 
bool subenabled
 
 FormData_pg_subscription
 

Typedef Documentation

◆ Form_pg_subscription

◆ Subscription

Function Documentation

◆ CATALOG()

CATALOG ( pg_subscription  ,
6100  ,
SubscriptionRelationId   
)

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

Definition at line 118 of file pg_subscription.c.

References BTEqualStrategyNumber, heap_close, heap_open(), HeapTupleIsValid, InvalidOid, NoLock, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), 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 
126  rel = heap_open(SubscriptionRelationId, RowExclusiveLock);
127 
128  ScanKeyInit(&scankey,
129  Anum_pg_subscription_subdbid,
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:502
#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:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ FreeSubscription()

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:1031
List * publications

◆ get_subscription_name()

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(), subname, 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:668
char * pstrdup(const char *in)
Definition: mcxt.c:1161
FormData_pg_subscription * Form_pg_subscription
NameData subname
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#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:78
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219

◆ get_subscription_oid()

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 
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
NameData subname
#define OidIsValid(objectId)
Definition: c.h:605
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:193
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:563
#define ereport(elevel, rest)
Definition: elog.h:122
Oid MyDatabaseId
Definition: globals.c:86
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 47 of file pg_subscription.c.

References 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,
77  Anum_pg_subscription_subconninfo,
78  &isnull);
79  Assert(!isnull);
80  sub->conninfo = TextDatumGetCString(datum);
81 
82  /* Get slotname */
84  tup,
85  Anum_pg_subscription_subslotname,
86  &isnull);
87  if (!isnull)
88  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
89  else
90  sub->slotname = NULL;
91 
92  /* Get synccommit */
94  tup,
95  Anum_pg_subscription_subsynccommit,
96  &isnull);
97  Assert(!isnull);
98  sub->synccommit = TextDatumGetCString(datum);
99 
100  /* Get publications */
102  tup,
103  Anum_pg_subscription_subpublications,
104  &isnull);
105  Assert(!isnull);
107 
108  ReleaseSysCache(tup);
109 
110  return sub;
111 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
char * pstrdup(const char *in)
Definition: mcxt.c:1161
FormData_pg_subscription * Form_pg_subscription
#define DatumGetName(X)
Definition: postgres.h:570
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
static List * textarray_to_stringlist(ArrayType *textarray)
List * publications
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define TextDatumGetCString(d)
Definition: builtins.h:96
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
void * palloc(Size size)
Definition: mcxt.c:924
#define NameStr(name)
Definition: c.h:576
#define elog
Definition: elog.h:219
#define DatumGetArrayTypeP(X)
Definition: array.h:246

Variable Documentation

◆ BKI_SCHEMA_MACRO

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
Initial value:
{
Oid subdbid
unsigned int Oid
Definition: postgres_ext.h:31

Definition at line 40 of file pg_subscription.h.

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 62 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 46 of file pg_subscription.h.

◆ subname

◆ subowner

Oid subowner

Definition at line 44 of file pg_subscription.h.

Referenced by pg_subscription_ownercheck().