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
 

Macros

#define PgSubscriptionToastTable   4183
 
#define PgSubscriptionToastIndex   4184
 
#define SubscriptionObjectIndexId   6114
 
#define SubscriptionNameIndexId   6115
 

Typedefs

typedef FormData_pg_subscriptionForm_pg_subscription
 
typedef struct Subscription Subscription
 

Functions

 CATALOG (pg_subscription, 6100, SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101
 
Oid subdbid BKI_LOOKUP (pg_database)
 
Oid subowner BKI_LOOKUP (pg_authid)
 
 DECLARE_TOAST (pg_subscription, 4183, 4184)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_subscription_oid_index, 6114, on pg_subscription using btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_subscription_subname_index, 6115, on pg_subscription using btree(subdbid oid_ops, subname name_ops))
 
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
 
NameData subname
 
bool subenabled
 
bool subbinary
 
bool substream
 
 FormData_pg_subscription
 

Macro Definition Documentation

◆ PgSubscriptionToastIndex

#define PgSubscriptionToastIndex   4184

Definition at line 76 of file pg_subscription.h.

Referenced by IsSharedRelation().

◆ PgSubscriptionToastTable

#define PgSubscriptionToastTable   4183

Definition at line 75 of file pg_subscription.h.

Referenced by IsSharedRelation().

◆ SubscriptionNameIndexId

#define SubscriptionNameIndexId   6115

Definition at line 81 of file pg_subscription.h.

Referenced by IsSharedRelation().

◆ SubscriptionObjectIndexId

#define SubscriptionObjectIndexId   6114

Definition at line 79 of file pg_subscription.h.

Referenced by CreateSubscription(), and IsSharedRelation().

Typedef Documentation

◆ Form_pg_subscription

Definition at line 72 of file pg_subscription.h.

◆ Subscription

typedef struct Subscription Subscription

Function Documentation

◆ BKI_LOOKUP() [1/2]

Oid subdbid BKI_LOOKUP ( pg_database  )

◆ BKI_LOOKUP() [2/2]

Oid subowner BKI_LOOKUP ( pg_authid  )

◆ CATALOG()

CATALOG ( pg_subscription  ,
6100  ,
SubscriptionRelationId   
)

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

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

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

◆ DECLARE_TOAST()

DECLARE_TOAST ( pg_subscription  ,
4183  ,
4184   
)

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_subscription_subname_index  ,
6115  ,
on pg_subscription using   btreesubdbid oid_ops, subname name_ops 
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_subscription_oid_index  ,
6114  ,
on pg_subscription using   btreeoid oid_ops 
)

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)

Definition at line 148 of file pg_subscription.c.

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

Referenced by maybe_reread_subscription().

149 {
150  pfree(sub->name);
151  pfree(sub->conninfo);
152  if (sub->slotname)
153  pfree(sub->slotname);
155  pfree(sub);
156 }
void list_free_deep(List *list)
Definition: list.c:1405
void pfree(void *pointer)
Definition: mcxt.c:1057
List * publications

◆ get_subscription_name()

char* get_subscription_name ( Oid  subid,
bool  missing_ok 
)

Definition at line 185 of file pg_subscription.c.

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

Referenced by getObjectDescription(), getObjectIdentityParts(), and RemoveSubscriptionRel().

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

◆ get_subscription_oid()

Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 165 of file pg_subscription.c.

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

Referenced by get_object_address_unqualified().

166 {
167  Oid oid;
168 
169  oid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
171  if (!OidIsValid(oid) && !missing_ok)
172  ereport(ERROR,
173  (errcode(ERRCODE_UNDEFINED_OBJECT),
174  errmsg("subscription \"%s\" does not exist", subname)));
175  return oid;
176 }
int errcode(int sqlerrcode)
Definition: elog.c:694
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
#define OidIsValid(objectId)
Definition: c.h:710
#define ERROR
Definition: elog.h:45
#define CStringGetDatum(X)
Definition: postgres.h:578
Oid MyDatabaseId
Definition: globals.c:86
#define ereport(elevel,...)
Definition: elog.h:155
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:195
int errmsg(const char *fmt,...)
Definition: elog.c:905

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 43 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, Subscription::stream, SUBSCRIPTIONOID, Subscription::synccommit, SysCacheGetAttr(), textarray_to_stringlist(), and TextDatumGetCString.

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

44 {
45  HeapTuple tup;
46  Subscription *sub;
47  Form_pg_subscription subform;
48  Datum datum;
49  bool isnull;
50 
52 
53  if (!HeapTupleIsValid(tup))
54  {
55  if (missing_ok)
56  return NULL;
57 
58  elog(ERROR, "cache lookup failed for subscription %u", subid);
59  }
60 
61  subform = (Form_pg_subscription) GETSTRUCT(tup);
62 
63  sub = (Subscription *) palloc(sizeof(Subscription));
64  sub->oid = subid;
65  sub->dbid = subform->subdbid;
66  sub->name = pstrdup(NameStr(subform->subname));
67  sub->owner = subform->subowner;
68  sub->enabled = subform->subenabled;
69  sub->binary = subform->subbinary;
70  sub->stream = subform->substream;
71 
72  /* Get conninfo */
74  tup,
75  Anum_pg_subscription_subconninfo,
76  &isnull);
77  Assert(!isnull);
78  sub->conninfo = TextDatumGetCString(datum);
79 
80  /* Get slotname */
82  tup,
83  Anum_pg_subscription_subslotname,
84  &isnull);
85  if (!isnull)
86  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
87  else
88  sub->slotname = NULL;
89 
90  /* Get synccommit */
92  tup,
93  Anum_pg_subscription_subsynccommit,
94  &isnull);
95  Assert(!isnull);
96  sub->synccommit = TextDatumGetCString(datum);
97 
98  /* Get publications */
100  tup,
101  Anum_pg_subscription_subpublications,
102  &isnull);
103  Assert(!isnull);
105 
106  ReleaseSysCache(tup);
107 
108  return sub;
109 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1187
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:45
static List * textarray_to_stringlist(ArrayType *textarray)
List * publications
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define TextDatumGetCString(d)
Definition: builtins.h:83
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:227
#define NameStr(name)
Definition: c.h:681
#define DatumGetArrayTypeP(X)
Definition: array.h:254

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

◆ subbinary

bool subbinary

Definition at line 52 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 49 of file pg_subscription.h.

◆ subname

◆ substream

bool substream

Definition at line 55 of file pg_subscription.h.