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'
 
#define LOGICALREP_ORIGIN_NONE   "none"
 
#define LOGICALREP_ORIGIN_ANY   "any"
 
#define LOGICALREP_STREAM_OFF   'f'
 
#define LOGICALREP_STREAM_ON   't'
 
#define LOGICALREP_STREAM_PARALLEL   'p'
 

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

Variables

SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
 
XLogRecPtr subskiplsn
 
NameData subname
 
bool subenabled
 
bool subbinary
 
char substream
 
char subtwophasestate
 
bool subdisableonerr
 
bool subpasswordrequired
 
bool subrunasowner
 
 FormData_pg_subscription
 

Macro Definition Documentation

◆ LOGICALREP_ORIGIN_ANY

#define LOGICALREP_ORIGIN_ANY   "any"

Definition at line 44 of file pg_subscription.h.

◆ LOGICALREP_ORIGIN_NONE

#define LOGICALREP_ORIGIN_NONE   "none"

Definition at line 38 of file pg_subscription.h.

◆ LOGICALREP_STREAM_OFF

#define LOGICALREP_STREAM_OFF   'f'

Definition at line 150 of file pg_subscription.h.

◆ LOGICALREP_STREAM_ON

#define LOGICALREP_STREAM_ON   't'

Definition at line 156 of file pg_subscription.h.

◆ LOGICALREP_STREAM_PARALLEL

#define LOGICALREP_STREAM_PARALLEL   'p'

Definition at line 162 of file pg_subscription.h.

◆ 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

◆ 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 121 of file pg_subscription.c.

122 {
123  int nsubs = 0;
124  Relation rel;
125  ScanKeyData scankey;
126  SysScanDesc scan;
127  HeapTuple tup;
128 
129  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
130 
131  ScanKeyInit(&scankey,
132  Anum_pg_subscription_subdbid,
133  BTEqualStrategyNumber, F_OIDEQ,
134  ObjectIdGetDatum(dbid));
135 
136  scan = systable_beginscan(rel, InvalidOid, false,
137  NULL, 1, &scankey);
138 
139  while (HeapTupleIsValid(tup = systable_getnext(scan)))
140  nsubs++;
141 
142  systable_endscan(scan);
143 
144  table_close(rel, NoLock);
145 
146  return nsubs;
147 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#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:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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 167 of file pg_subscription.c.

168 {
169  Relation rel;
170  bool nulls[Natts_pg_subscription];
171  bool replaces[Natts_pg_subscription];
172  Datum values[Natts_pg_subscription];
173  HeapTuple tup;
174 
175  /* Look up the subscription in the catalog */
176  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
178 
179  if (!HeapTupleIsValid(tup))
180  elog(ERROR, "cache lookup failed for subscription %u", subid);
181 
182  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
183 
184  /* Form a new tuple. */
185  memset(values, 0, sizeof(values));
186  memset(nulls, false, sizeof(nulls));
187  memset(replaces, false, sizeof(replaces));
188 
189  /* Set the subscription to disabled. */
190  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(false);
191  replaces[Anum_pg_subscription_subenabled - 1] = true;
192 
193  /* Update the catalog */
194  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
195  replaces);
196  CatalogTupleUpdate(rel, &tup->t_self, tup);
197  heap_freetuple(tup);
198 
199  table_close(rel, NoLock);
200 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define ERROR
Definition: elog.h:39
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:313
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:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
#define RelationGetDescr(relation)
Definition: rel.h:530
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:182
@ 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 153 of file pg_subscription.c.

154 {
155  pfree(sub->name);
156  pfree(sub->conninfo);
157  if (sub->slotname)
158  pfree(sub->slotname);
160  pfree(sub);
161 }
void list_free_deep(List *list)
Definition: list.c:1559
void pfree(void *pointer)
Definition: mcxt.c:1456

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

Referenced by maybe_reread_subscription().

◆ 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  sub->passwordrequired = subform->subpasswordrequired;
75  sub->runasowner = subform->subrunasowner;
76 
77  /* Get conninfo */
79  tup,
80  Anum_pg_subscription_subconninfo);
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  sub->synccommit = TextDatumGetCString(datum);
98 
99  /* Get publications */
101  tup,
102  Anum_pg_subscription_subpublications);
104 
105  /* Get origin */
107  tup,
108  Anum_pg_subscription_suborigin);
109  sub->origin = TextDatumGetCString(datum);
110 
111  ReleaseSysCache(tup);
112 
113  return sub;
114 }
#define DatumGetArrayTypeP(X)
Definition: array.h:254
#define TextDatumGetCString(d)
Definition: builtins.h:95
#define NameStr(name)
Definition: c.h:730
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * pstrdup(const char *in)
Definition: mcxt.c:1644
void * palloc(Size size)
Definition: mcxt.c:1226
static List * textarray_to_stringlist(ArrayType *textarray)
FormData_pg_subscription * Form_pg_subscription
static Name DatumGetName(Datum X)
Definition: postgres.h:360
XLogRecPtr skiplsn
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:866
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:818
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1079
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:1110

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

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

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

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 112 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 80 of file pg_subscription.h.

◆ subdisableonerr

bool subdisableonerr

Definition at line 88 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 77 of file pg_subscription.h.

◆ subname

◆ subpasswordrequired

bool subpasswordrequired

Definition at line 91 of file pg_subscription.h.

◆ subrunasowner

bool subrunasowner

Definition at line 93 of file pg_subscription.h.

◆ subskiplsn

XLogRecPtr subskiplsn

Definition at line 70 of file pg_subscription.h.

◆ substream

char substream

Definition at line 83 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 86 of file pg_subscription.h.