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
 
bool subbinary
 
 FormData_pg_subscription
 

Typedef Documentation

◆ Form_pg_subscription

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

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

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

Referenced by maybe_reread_subscription().

147 {
148  pfree(sub->name);
149  pfree(sub->conninfo);
150  if (sub->slotname)
151  pfree(sub->slotname);
153  pfree(sub);
154 }
void list_free_deep(List *list)
Definition: list.c:1390
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 183 of file pg_subscription.c.

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

Referenced by getObjectDescription(), and getObjectIdentityParts().

184 {
185  HeapTuple tup;
186  char *subname;
187  Form_pg_subscription subform;
188 
190 
191  if (!HeapTupleIsValid(tup))
192  {
193  if (!missing_ok)
194  elog(ERROR, "cache lookup failed for subscription %u", subid);
195  return NULL;
196  }
197 
198  subform = (Form_pg_subscription) GETSTRUCT(tup);
199  subname = pstrdup(NameStr(subform->subname));
200 
201  ReleaseSysCache(tup);
202 
203  return subname;
204 }
#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:214
#define NameStr(name)
Definition: c.h:622

◆ get_subscription_oid()

Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 163 of file pg_subscription.c.

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

Referenced by get_object_address_unqualified().

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

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 42 of file pg_subscription.c.

References Assert, Subscription::binary, 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  sub->binary = subform->subbinary;
69 
70  /* Get conninfo */
72  tup,
73  Anum_pg_subscription_subconninfo,
74  &isnull);
75  Assert(!isnull);
76  sub->conninfo = TextDatumGetCString(datum);
77 
78  /* Get slotname */
80  tup,
81  Anum_pg_subscription_subslotname,
82  &isnull);
83  if (!isnull)
84  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
85  else
86  sub->slotname = NULL;
87 
88  /* Get synccommit */
90  tup,
91  Anum_pg_subscription_subsynccommit,
92  &isnull);
93  Assert(!isnull);
94  sub->synccommit = TextDatumGetCString(datum);
95 
96  /* Get publications */
98  tup,
99  Anum_pg_subscription_subpublications,
100  &isnull);
101  Assert(!isnull);
103 
104  ReleaseSysCache(tup);
105 
106  return sub;
107 }
#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:87
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:745
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:622
#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 67 of file pg_subscription.h.

◆ subbinary

bool subbinary

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