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, pg_subscription, btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_subscription_subname_index, 6115, SubscriptionNameIndexId, pg_subscription, 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 151 of file pg_subscription.h.

◆ LOGICALREP_STREAM_ON

#define LOGICALREP_STREAM_ON   't'

Definition at line 157 of file pg_subscription.h.

◆ LOGICALREP_STREAM_PARALLEL

#define LOGICALREP_STREAM_PARALLEL   'p'

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

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

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_subscription_oid_index  ,
6114  ,
SubscriptionObjectIndexId  ,
pg_subscription  ,
btree(oid oid_ops)   
)

◆ DisableSubscription()

void DisableSubscription ( Oid  subid)

Definition at line 170 of file pg_subscription.c.

171 {
172  Relation rel;
173  bool nulls[Natts_pg_subscription];
174  bool replaces[Natts_pg_subscription];
175  Datum values[Natts_pg_subscription];
176  HeapTuple tup;
177 
178  /* Look up the subscription in the catalog */
179  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
181 
182  if (!HeapTupleIsValid(tup))
183  elog(ERROR, "cache lookup failed for subscription %u", subid);
184 
185  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
186 
187  /* Form a new tuple. */
188  memset(values, 0, sizeof(values));
189  memset(nulls, false, sizeof(nulls));
190  memset(replaces, false, sizeof(replaces));
191 
192  /* Set the subscription to disabled. */
193  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(false);
194  replaces[Anum_pg_subscription_subenabled - 1] = true;
195 
196  /* Update the catalog */
197  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
198  replaces);
199  CatalogTupleUpdate(rel, &tup->t_self, tup);
200  heap_freetuple(tup);
201 
202  table_close(rel, NoLock);
203 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define ERROR
Definition: elog.h:39
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition: heaptuple.c:1210
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
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 156 of file pg_subscription.c.

157 {
158  pfree(sub->name);
159  pfree(sub->conninfo);
160  if (sub->slotname)
161  pfree(sub->slotname);
163  pfree(sub);
164 }
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  /* Is the subscription owner a superuser? */
112  sub->ownersuperuser = superuser_arg(sub->owner);
113 
114  ReleaseSysCache(tup);
115 
116  return sub;
117 }
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define TextDatumGetCString(d)
Definition: builtins.h:95
#define NameStr(name)
Definition: c.h:735
#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
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:868
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:820
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1081
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:1112

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, Subscription::ownersuperuser, palloc(), Subscription::passwordrequired, pstrdup(), Subscription::publications, ReleaseSysCache(), Subscription::runasowner, SearchSysCache1(), Subscription::skiplsn, Subscription::slotname, Subscription::stream, SUBSCRIPTIONOID, superuser_arg(), Subscription::synccommit, SysCacheGetAttr(), SysCacheGetAttrNotNull(), textarray_to_stringlist(), TextDatumGetCString, and Subscription::twophasestate.

Referenced by AlterSubscription(), InitializeLogRepWorker(), 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.