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

◆ LOGICALREP_STREAM_ON

#define LOGICALREP_STREAM_ON   't'

Definition at line 149 of file pg_subscription.h.

◆ LOGICALREP_STREAM_PARALLEL

#define LOGICALREP_STREAM_PARALLEL   'p'

Definition at line 155 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 127 of file pg_subscription.c.

128 {
129  int nsubs = 0;
130  Relation rel;
131  ScanKeyData scankey;
132  SysScanDesc scan;
133  HeapTuple tup;
134 
135  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
136 
137  ScanKeyInit(&scankey,
138  Anum_pg_subscription_subdbid,
139  BTEqualStrategyNumber, F_OIDEQ,
140  ObjectIdGetDatum(dbid));
141 
142  scan = systable_beginscan(rel, InvalidOid, false,
143  NULL, 1, &scankey);
144 
145  while (HeapTupleIsValid(tup = systable_getnext(scan)))
146  nsubs++;
147 
148  systable_endscan(scan);
149 
150  table_close(rel, NoLock);
151 
152  return nsubs;
153 }
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 173 of file pg_subscription.c.

174 {
175  Relation rel;
176  bool nulls[Natts_pg_subscription];
177  bool replaces[Natts_pg_subscription];
178  Datum values[Natts_pg_subscription];
179  HeapTuple tup;
180 
181  /* Look up the subscription in the catalog */
182  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
184 
185  if (!HeapTupleIsValid(tup))
186  elog(ERROR, "cache lookup failed for subscription %u", subid);
187 
188  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
189 
190  /* Form a new tuple. */
191  memset(values, 0, sizeof(values));
192  memset(nulls, false, sizeof(nulls));
193  memset(replaces, false, sizeof(replaces));
194 
195  /* Set the subscription to disabled. */
196  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(false);
197  replaces[Anum_pg_subscription_subenabled - 1] = true;
198 
199  /* Update the catalog */
200  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
201  replaces);
202  CatalogTupleUpdate(rel, &tup->t_self, tup);
203  heap_freetuple(tup);
204 
205  table_close(rel, NoLock);
206 }
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: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:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
#define RelationGetDescr(relation)
Definition: rel.h:527
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 159 of file pg_subscription.c.

160 {
161  pfree(sub->name);
162  pfree(sub->conninfo);
163  if (sub->slotname)
164  pfree(sub->slotname);
166  pfree(sub);
167 }
void list_free_deep(List *list)
Definition: list.c:1559
void pfree(void *pointer)
Definition: mcxt.c:1436

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 
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  /* Get origin */
111  tup,
112  Anum_pg_subscription_suborigin,
113  &isnull);
114  Assert(!isnull);
115  sub->origin = TextDatumGetCString(datum);
116 
117  ReleaseSysCache(tup);
118 
119  return sub;
120 }
#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
Assert(fmt[strlen(fmt) - 1] !='\n')
char * pstrdup(const char *in)
Definition: mcxt.c:1624
void * palloc(Size size)
Definition: mcxt.c:1210
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:865
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:817
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1078

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::origin, 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(), 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 107 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

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