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, bool missing_ok)
 
int CountDBSubscriptions (Oid dbid)
 

Variables

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
 
Oid subdbid
 
NameData subname
 
Oid subowner
 
bool subenabled
 
 FormData_pg_subscription
 

Typedef Documentation

◆ Form_pg_subscription

Definition at line 66 of file pg_subscription.h.

◆ Subscription

typedef struct Subscription Subscription

Function Documentation

◆ CATALOG()

CATALOG ( pg_subscription  ,
6100  ,
SubscriptionRelationId   
)

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

Definition at line 113 of file pg_subscription.c.

References BTEqualStrategyNumber, HeapTupleIsValid, InvalidOid, NoLock, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by dropdb().

114 {
115  int nsubs = 0;
116  Relation rel;
117  ScanKeyData scankey;
118  SysScanDesc scan;
119  HeapTuple tup;
120 
121  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
122 
123  ScanKeyInit(&scankey,
124  Anum_pg_subscription_subdbid,
125  BTEqualStrategyNumber, F_OIDEQ,
126  ObjectIdGetDatum(dbid));
127 
128  scan = systable_beginscan(rel, InvalidOid, false,
129  NULL, 1, &scankey);
130 
131  while (HeapTupleIsValid(tup = systable_getnext(scan)))
132  nsubs++;
133 
134  systable_endscan(scan);
135 
136  table_close(rel, NoLock);
137 
138  return nsubs;
139 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#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
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)

Definition at line 145 of file pg_subscription.c.

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

Referenced by maybe_reread_subscription().

146 {
147  pfree(sub->name);
148  pfree(sub->conninfo);
149  if (sub->slotname)
150  pfree(sub->slotname);
152  pfree(sub);
153 }
void list_free_deep(List *list)
Definition: list.c:1391
void pfree(void *pointer)
Definition: mcxt.c:1056
List * publications

◆ get_subscription_name()

char* get_subscription_name ( Oid  subid,
bool  missing_ok 
)

Definition at line 182 of file pg_subscription.c.

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

Referenced by getObjectDescription(), and getObjectIdentityParts().

183 {
184  HeapTuple tup;
185  char *subname;
186  Form_pg_subscription subform;
187 
189 
190  if (!HeapTupleIsValid(tup))
191  {
192  if (!missing_ok)
193  elog(ERROR, "cache lookup failed for subscription %u", subid);
194  return NULL;
195  }
196 
197  subform = (Form_pg_subscription) GETSTRUCT(tup);
198  subname = pstrdup(NameStr(subform->subname));
199 
200  ReleaseSysCache(tup);
201 
202  return subname;
203 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
FormData_pg_subscription * Form_pg_subscription
NameData subname
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:228
#define NameStr(name)
Definition: c.h:610

◆ get_subscription_oid()

Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 162 of file pg_subscription.c.

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

Referenced by get_object_address_unqualified().

163 {
164  Oid oid;
165 
166  oid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
168  if (!OidIsValid(oid) && !missing_ok)
169  ereport(ERROR,
170  (errcode(ERRCODE_UNDEFINED_OBJECT),
171  errmsg("subscription \"%s\" does not exist", subname)));
172  return oid;
173 }
int errcode(int sqlerrcode)
Definition: elog.c:608
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
#define OidIsValid(objectId)
Definition: c.h:639
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
Oid MyDatabaseId
Definition: globals.c:85
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:194
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 42 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().

43 {
44  HeapTuple tup;
45  Subscription *sub;
46  Form_pg_subscription subform;
47  Datum datum;
48  bool isnull;
49 
51 
52  if (!HeapTupleIsValid(tup))
53  {
54  if (missing_ok)
55  return NULL;
56 
57  elog(ERROR, "cache lookup failed for subscription %u", subid);
58  }
59 
60  subform = (Form_pg_subscription) GETSTRUCT(tup);
61 
62  sub = (Subscription *) palloc(sizeof(Subscription));
63  sub->oid = subid;
64  sub->dbid = subform->subdbid;
65  sub->name = pstrdup(NameStr(subform->subname));
66  sub->owner = subform->subowner;
67  sub->enabled = subform->subenabled;
68 
69  /* Get conninfo */
71  tup,
72  Anum_pg_subscription_subconninfo,
73  &isnull);
74  Assert(!isnull);
75  sub->conninfo = TextDatumGetCString(datum);
76 
77  /* Get slotname */
79  tup,
80  Anum_pg_subscription_subslotname,
81  &isnull);
82  if (!isnull)
83  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
84  else
85  sub->slotname = NULL;
86 
87  /* Get synccommit */
89  tup,
90  Anum_pg_subscription_subsynccommit,
91  &isnull);
92  Assert(!isnull);
93  sub->synccommit = TextDatumGetCString(datum);
94 
95  /* Get publications */
97  tup,
98  Anum_pg_subscription_subpublications,
99  &isnull);
100  Assert(!isnull);
102 
103  ReleaseSysCache(tup);
104 
105  return sub;
106 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
FormData_pg_subscription * Form_pg_subscription
#define DatumGetName(X)
Definition: postgres.h:585
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static List * textarray_to_stringlist(ArrayType *textarray)
List * publications
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define TextDatumGetCString(d)
Definition: builtins.h:84
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:733
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:228
#define NameStr(name)
Definition: c.h:610
#define DatumGetArrayTypeP(X)
Definition: array.h:249

Variable Documentation

◆ BKI_SCHEMA_MACRO

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
Initial value:
{
Oid oid
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 64 of file pg_subscription.h.

◆ subdbid

Oid subdbid

Definition at line 43 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 48 of file pg_subscription.h.

◆ subname

◆ subowner

Oid subowner

Definition at line 46 of file pg_subscription.h.

Referenced by pg_subscription_ownercheck().