PostgreSQL Source Code  git master
pg_subscription.h File Reference
#include "access/xlogdefs.h"
#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'
 

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_WITH_MACRO (pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex)
 
 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)
 
void DisableSubscription (Oid subid)
 
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
 
XLogRecPtr subskiplsn
 
NameData subname
 
bool subenabled
 
bool subbinary
 
bool substream
 
char subtwophasestate
 
bool subdisableonerr
 
 FormData_pg_subscription
 

Macro Definition Documentation

◆ LOGICALREP_TWOPHASE_STATE_DISABLED

#define LOGICALREP_TWOPHASE_STATE_DISABLED   'd'

Definition at line 30 of file pg_subscription.h.

◆ LOGICALREP_TWOPHASE_STATE_ENABLED

#define LOGICALREP_TWOPHASE_STATE_ENABLED   'e'

Definition at line 32 of file pg_subscription.h.

◆ LOGICALREP_TWOPHASE_STATE_PENDING

#define LOGICALREP_TWOPHASE_STATE_PENDING   'p'

Definition at line 31 of file pg_subscription.h.

Typedef Documentation

◆ Form_pg_subscription

Definition at line 93 of file pg_subscription.h.

◆ Subscription

typedef struct Subscription Subscription

Function Documentation

◆ BKI_LOOKUP() [1/2]

Oid subowner BKI_LOOKUP ( pg_authid  )

◆ BKI_LOOKUP() [2/2]

Oid subdbid BKI_LOOKUP ( pg_database  )

◆ CATALOG()

CATALOG ( pg_subscription  ,
6100  ,
SubscriptionRelationId   
)

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

Definition at line 119 of file pg_subscription.c.

120 {
121  int nsubs = 0;
122  Relation rel;
123  ScanKeyData scankey;
124  SysScanDesc scan;
125  HeapTuple tup;
126 
127  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
128 
129  ScanKeyInit(&scankey,
130  Anum_pg_subscription_subdbid,
131  BTEqualStrategyNumber, F_OIDEQ,
132  ObjectIdGetDatum(dbid));
133 
134  scan = systable_beginscan(rel, InvalidOid, false,
135  NULL, 1, &scankey);
136 
137  while (HeapTupleIsValid(tup = systable_getnext(scan)))
138  nsubs++;
139 
140  systable_endscan(scan);
141 
142  table_close(rel, NoLock);
143 
144  return nsubs;
145 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:598
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:505
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:386
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define InvalidOid
Definition: postgres_ext.h:36
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

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

Referenced by dropdb().

◆ DECLARE_TOAST_WITH_MACRO()

DECLARE_TOAST_WITH_MACRO ( pg_subscription  ,
4183  ,
4184  ,
PgSubscriptionToastTable  ,
PgSubscriptionToastIndex   
)

◆ 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 
)

◆ DisableSubscription()

void DisableSubscription ( Oid  subid)

Definition at line 165 of file pg_subscription.c.

166 {
167  Relation rel;
168  bool nulls[Natts_pg_subscription];
169  bool replaces[Natts_pg_subscription];
170  Datum values[Natts_pg_subscription];
171  HeapTuple tup;
172 
173  /* Look up the subscription in the catalog */
174  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
176 
177  if (!HeapTupleIsValid(tup))
178  elog(ERROR, "cache lookup failed for subscription %u", subid);
179 
180  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
181 
182  /* Form a new tuple. */
183  memset(values, 0, sizeof(values));
184  memset(nulls, false, sizeof(nulls));
185  memset(replaces, false, sizeof(replaces));
186 
187  /* Set the subscription to disabled. */
188  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(false);
189  replaces[Anum_pg_subscription_subenabled - 1] = true;
190 
191  /* Update the catalog */
192  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
193  replaces);
194  CatalogTupleUpdate(rel, &tup->t_self, tup);
195  heap_freetuple(tup);
196 
197  table_close(rel, NoLock);
198 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define ERROR
Definition: elog.h:33
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
#define AccessShareLock
Definition: lockdefs.h:36
uintptr_t Datum
Definition: postgres.h:411
#define BoolGetDatum(X)
Definition: postgres.h:446
#define RelationGetDescr(relation)
Definition: rel.h:514
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179
@ SUBSCRIPTIONOID
Definition: syscache.h:99

References AccessShareLock, BoolGetDatum, CatalogTupleUpdate(), elog(), ERROR, heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, LockSharedObject(), NoLock, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy1, SUBSCRIPTIONOID, HeapTupleData::t_self, table_close(), table_open(), and values.

Referenced by DisableSubscriptionAndExit().

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)

Definition at line 151 of file pg_subscription.c.

152 {
153  pfree(sub->name);
154  pfree(sub->conninfo);
155  if (sub->slotname)
156  pfree(sub->slotname);
158  pfree(sub);
159 }
void list_free_deep(List *list)
Definition: list.c:1559
void pfree(void *pointer)
Definition: mcxt.c:1175

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

Referenced by maybe_reread_subscription().

◆ get_subscription_name()

char* get_subscription_name ( Oid  subid,
bool  missing_ok 
)

Definition at line 227 of file pg_subscription.c.

228 {
229  HeapTuple tup;
230  char *subname;
231  Form_pg_subscription subform;
232 
234 
235  if (!HeapTupleIsValid(tup))
236  {
237  if (!missing_ok)
238  elog(ERROR, "cache lookup failed for subscription %u", subid);
239  return NULL;
240  }
241 
242  subform = (Form_pg_subscription) GETSTRUCT(tup);
243  subname = pstrdup(NameStr(subform->subname));
244 
245  ReleaseSysCache(tup);
246 
247  return subname;
248 }
#define NameStr(name)
Definition: c.h:692
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
char * pstrdup(const char *in)
Definition: mcxt.c:1305
NameData subname
FormData_pg_subscription * Form_pg_subscription
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173

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

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

◆ get_subscription_oid()

Oid get_subscription_oid ( const char *  subname,
bool  missing_ok 
)

Definition at line 207 of file pg_subscription.c.

208 {
209  Oid oid;
210 
211  oid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
213  if (!OidIsValid(oid) && !missing_ok)
214  ereport(ERROR,
215  (errcode(ERRCODE_UNDEFINED_OBJECT),
216  errmsg("subscription \"%s\" does not exist", subname)));
217  return oid;
218 }
#define OidIsValid(objectId)
Definition: c.h:721
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ereport(elevel,...)
Definition: elog.h:143
Oid MyDatabaseId
Definition: globals.c:89
#define CStringGetDatum(X)
Definition: postgres.h:622
unsigned int Oid
Definition: postgres_ext.h:31
@ SUBSCRIPTIONNAME
Definition: syscache.h:98
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:199

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

Referenced by get_object_address_unqualified().

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 43 of file pg_subscription.c.

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->skiplsn = subform->subskiplsn;
67  sub->name = pstrdup(NameStr(subform->subname));
68  sub->owner = subform->subowner;
69  sub->enabled = subform->subenabled;
70  sub->binary = subform->subbinary;
71  sub->stream = subform->substream;
72  sub->twophasestate = subform->subtwophasestate;
73  sub->disableonerr = subform->subdisableonerr;
74 
75  /* Get conninfo */
77  tup,
78  Anum_pg_subscription_subconninfo,
79  &isnull);
80  Assert(!isnull);
81  sub->conninfo = TextDatumGetCString(datum);
82 
83  /* Get slotname */
85  tup,
86  Anum_pg_subscription_subslotname,
87  &isnull);
88  if (!isnull)
89  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
90  else
91  sub->slotname = NULL;
92 
93  /* Get synccommit */
95  tup,
96  Anum_pg_subscription_subsynccommit,
97  &isnull);
98  Assert(!isnull);
99  sub->synccommit = TextDatumGetCString(datum);
100 
101  /* Get publications */
103  tup,
104  Anum_pg_subscription_subpublications,
105  &isnull);
106  Assert(!isnull);
108 
109  ReleaseSysCache(tup);
110 
111  return sub;
112 }
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define TextDatumGetCString(d)
Definition: builtins.h:86
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc(Size size)
Definition: mcxt.c:1068
static List * textarray_to_stringlist(ArrayType *textarray)
#define DatumGetName(X)
Definition: postgres.h:629
XLogRecPtr skiplsn
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1434

References Assert(), Subscription::binary, Subscription::conninfo, DatumGetArrayTypeP, DatumGetName, Subscription::dbid, Subscription::disableonerr, elog(), Subscription::enabled, ERROR, GETSTRUCT, HeapTupleIsValid, Subscription::name, NameStr, ObjectIdGetDatum, Subscription::oid, Subscription::owner, palloc(), pstrdup(), Subscription::publications, ReleaseSysCache(), SearchSysCache1(), Subscription::skiplsn, Subscription::slotname, Subscription::stream, SUBSCRIPTIONOID, Subscription::synccommit, SysCacheGetAttr(), textarray_to_stringlist(), TextDatumGetCString, and Subscription::twophasestate.

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

Variable Documentation

◆ BKI_SCHEMA_MACRO

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
Initial value:
{
Oid oid

Definition at line 51 of file pg_subscription.h.

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 91 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 68 of file pg_subscription.h.

◆ subdisableonerr

bool subdisableonerr

Definition at line 75 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 65 of file pg_subscription.h.

◆ subname

◆ subskiplsn

XLogRecPtr subskiplsn

Definition at line 58 of file pg_subscription.h.

◆ substream

bool substream

Definition at line 71 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 73 of file pg_subscription.h.