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))
 
 MAKE_SYSCACHE (SUBSCRIPTIONOID, pg_subscription_oid_index, 4)
 
 MAKE_SYSCACHE (SUBSCRIPTIONNAME, pg_subscription_subname_index, 4)
 
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
 
bool subfailover
 
 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 163 of file pg_subscription.h.

◆ LOGICALREP_STREAM_ON

#define LOGICALREP_STREAM_ON   't'

Definition at line 169 of file pg_subscription.h.

◆ LOGICALREP_STREAM_PARALLEL

#define LOGICALREP_STREAM_PARALLEL   'p'

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

124 {
125  int nsubs = 0;
126  Relation rel;
127  ScanKeyData scankey;
128  SysScanDesc scan;
129  HeapTuple tup;
130 
131  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
132 
133  ScanKeyInit(&scankey,
134  Anum_pg_subscription_subdbid,
135  BTEqualStrategyNumber, F_OIDEQ,
136  ObjectIdGetDatum(dbid));
137 
138  scan = systable_beginscan(rel, InvalidOid, false,
139  NULL, 1, &scankey);
140 
141  while (HeapTupleIsValid(tup = systable_getnext(scan)))
142  nsubs++;
143 
144  systable_endscan(scan);
145 
146  table_close(rel, NoLock);
147 
148  return nsubs;
149 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:596
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:503
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:384
#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 169 of file pg_subscription.c.

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

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

Referenced by DisableSubscriptionAndExit().

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)

Definition at line 155 of file pg_subscription.c.

156 {
157  pfree(sub->name);
158  pfree(sub->conninfo);
159  if (sub->slotname)
160  pfree(sub->slotname);
162  pfree(sub);
163 }
void list_free_deep(List *list)
Definition: list.c:1560
void pfree(void *pointer)
Definition: mcxt.c:1520

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

42 {
43  HeapTuple tup;
44  Subscription *sub;
45  Form_pg_subscription subform;
46  Datum datum;
47  bool isnull;
48 
49  tup = SearchSysCache1(SUBSCRIPTIONOID, ObjectIdGetDatum(subid));
50 
51  if (!HeapTupleIsValid(tup))
52  {
53  if (missing_ok)
54  return NULL;
55 
56  elog(ERROR, "cache lookup failed for subscription %u", subid);
57  }
58 
59  subform = (Form_pg_subscription) GETSTRUCT(tup);
60 
61  sub = (Subscription *) palloc(sizeof(Subscription));
62  sub->oid = subid;
63  sub->dbid = subform->subdbid;
64  sub->skiplsn = subform->subskiplsn;
65  sub->name = pstrdup(NameStr(subform->subname));
66  sub->owner = subform->subowner;
67  sub->enabled = subform->subenabled;
68  sub->binary = subform->subbinary;
69  sub->stream = subform->substream;
70  sub->twophasestate = subform->subtwophasestate;
71  sub->disableonerr = subform->subdisableonerr;
72  sub->passwordrequired = subform->subpasswordrequired;
73  sub->runasowner = subform->subrunasowner;
74  sub->failover = subform->subfailover;
75 
76  /* Get conninfo */
77  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
78  tup,
79  Anum_pg_subscription_subconninfo);
80  sub->conninfo = TextDatumGetCString(datum);
81 
82  /* Get slotname */
83  datum = SysCacheGetAttr(SUBSCRIPTIONOID,
84  tup,
85  Anum_pg_subscription_subslotname,
86  &isnull);
87  if (!isnull)
88  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
89  else
90  sub->slotname = NULL;
91 
92  /* Get synccommit */
93  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
94  tup,
95  Anum_pg_subscription_subsynccommit);
96  sub->synccommit = TextDatumGetCString(datum);
97 
98  /* Get publications */
99  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
100  tup,
101  Anum_pg_subscription_subpublications);
103 
104  /* Get origin */
105  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
106  tup,
107  Anum_pg_subscription_suborigin);
108  sub->origin = TextDatumGetCString(datum);
109 
110  /* Is the subscription owner a superuser? */
111  sub->ownersuperuser = superuser_arg(sub->owner);
112 
113  ReleaseSysCache(tup);
114 
115  return sub;
116 }
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define NameStr(name)
Definition: c.h:746
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * pstrdup(const char *in)
Definition: mcxt.c:1695
void * palloc(Size size)
Definition: mcxt.c:1316
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:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:479
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:510

References Subscription::binary, Subscription::conninfo, DatumGetArrayTypeP, DatumGetName(), Subscription::dbid, Subscription::disableonerr, elog, Subscription::enabled, ERROR, Subscription::failover, 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, superuser_arg(), Subscription::synccommit, SysCacheGetAttr(), SysCacheGetAttrNotNull(), textarray_to_stringlist(), TextDatumGetCString, and Subscription::twophasestate.

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

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( SUBSCRIPTIONNAME  ,
pg_subscription_subname_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( SUBSCRIPTIONOID  ,
pg_subscription_oid_index  ,
 
)

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

◆ subfailover

bool subfailover

Definition at line 96 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.