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 LOGICALREP_TWOPHASE_STATE_DISABLED   'd'
 
#define LOGICALREP_TWOPHASE_STATE_PENDING   'p'
 
#define LOGICALREP_TWOPHASE_STATE_ENABLED   'e'
 
#define PgSubscriptionToastTable   4183
 
#define PgSubscriptionToastIndex   4184
 

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, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_subscription_subname_index, 6115, SubscriptionNameIndexId, 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
 
char subtwophasestate
 
 FormData_pg_subscription
 

Macro Definition Documentation

◆ LOGICALREP_TWOPHASE_STATE_DISABLED

#define LOGICALREP_TWOPHASE_STATE_DISABLED   'd'

◆ LOGICALREP_TWOPHASE_STATE_ENABLED

#define LOGICALREP_TWOPHASE_STATE_ENABLED   'e'

◆ LOGICALREP_TWOPHASE_STATE_PENDING

#define LOGICALREP_TWOPHASE_STATE_PENDING   'p'

◆ PgSubscriptionToastIndex

#define PgSubscriptionToastIndex   4184

Definition at line 89 of file pg_subscription.h.

Referenced by IsSharedRelation().

◆ PgSubscriptionToastTable

#define PgSubscriptionToastTable   4183

Definition at line 88 of file pg_subscription.h.

Referenced by IsSharedRelation().

Typedef Documentation

◆ Form_pg_subscription

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

118 {
119  int nsubs = 0;
120  Relation rel;
121  ScanKeyData scankey;
122  SysScanDesc scan;
123  HeapTuple tup;
124 
125  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
126 
127  ScanKeyInit(&scankey,
128  Anum_pg_subscription_subdbid,
129  BTEqualStrategyNumber, F_OIDEQ,
130  ObjectIdGetDatum(dbid));
131 
132  scan = systable_beginscan(rel, InvalidOid, false,
133  NULL, 1, &scankey);
134 
135  while (HeapTupleIsValid(tup = systable_getnext(scan)))
136  nsubs++;
137 
138  systable_endscan(scan);
139 
140  table_close(rel, NoLock);
141 
142  return nsubs;
143 }
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:551
#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  ,
SubscriptionNameIndexId  ,
on pg_subscription using   btreesubdbid oid_ops, subname name_ops 
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

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

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)

Definition at line 149 of file pg_subscription.c.

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

Referenced by maybe_reread_subscription().

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

◆ get_subscription_name()

char* get_subscription_name ( Oid  subid,
bool  missing_ok 
)

Definition at line 186 of file pg_subscription.c.

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

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

187 {
188  HeapTuple tup;
189  char *subname;
190  Form_pg_subscription subform;
191 
193 
194  if (!HeapTupleIsValid(tup))
195  {
196  if (!missing_ok)
197  elog(ERROR, "cache lookup failed for subscription %u", subid);
198  return NULL;
199  }
200 
201  subform = (Form_pg_subscription) GETSTRUCT(tup);
202  subname = pstrdup(NameStr(subform->subname));
203 
204  ReleaseSysCache(tup);
205 
206  return subname;
207 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * pstrdup(const char *in)
Definition: mcxt.c:1299
FormData_pg_subscription * Form_pg_subscription
NameData subname
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
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:232
#define NameStr(name)
Definition: c.h:681

◆ get_subscription_oid()

Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 166 of file pg_subscription.c.

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

Referenced by get_object_address_unqualified().

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

◆ 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(), TextDatumGetCString, and Subscription::twophasestate.

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  sub->twophasestate = subform->subtwophasestate;
72 
73  /* Get conninfo */
75  tup,
76  Anum_pg_subscription_subconninfo,
77  &isnull);
78  Assert(!isnull);
79  sub->conninfo = TextDatumGetCString(datum);
80 
81  /* Get slotname */
83  tup,
84  Anum_pg_subscription_subslotname,
85  &isnull);
86  if (!isnull)
87  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
88  else
89  sub->slotname = NULL;
90 
91  /* Get synccommit */
93  tup,
94  Anum_pg_subscription_subsynccommit,
95  &isnull);
96  Assert(!isnull);
97  sub->synccommit = TextDatumGetCString(datum);
98 
99  /* Get publications */
101  tup,
102  Anum_pg_subscription_subpublications,
103  &isnull);
104  Assert(!isnull);
106 
107  ReleaseSysCache(tup);
108 
109  return sub;
110 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
char * pstrdup(const char *in)
Definition: mcxt.c:1299
FormData_pg_subscription * Form_pg_subscription
#define DatumGetName(X)
Definition: postgres.h:629
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
static List * textarray_to_stringlist(ArrayType *textarray)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:411
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:1062
#define elog(elevel,...)
Definition: elog.h:232
#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 51 of file pg_subscription.h.

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 83 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 63 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 60 of file pg_subscription.h.

◆ subname

◆ substream

bool substream

Definition at line 66 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 68 of file pg_subscription.h.