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 "lib/stringinfo.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
 

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)
 
void GetPublicationsStr (List *publications, StringInfo dest, bool quote_literal)
 

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
 

Typedef Documentation

◆ Form_pg_subscription

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

155 {
156  int nsubs = 0;
157  Relation rel;
158  ScanKeyData scankey;
159  SysScanDesc scan;
160  HeapTuple tup;
161 
162  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
163 
164  ScanKeyInit(&scankey,
165  Anum_pg_subscription_subdbid,
166  BTEqualStrategyNumber, F_OIDEQ,
167  ObjectIdGetDatum(dbid));
168 
169  scan = systable_beginscan(rel, InvalidOid, false,
170  NULL, 1, &scankey);
171 
172  while (HeapTupleIsValid(tup = systable_getnext(scan)))
173  nsubs++;
174 
175  systable_endscan(scan);
176 
177  table_close(rel, NoLock);
178 
179  return nsubs;
180 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:604
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:511
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 200 of file pg_subscription.c.

201 {
202  Relation rel;
203  bool nulls[Natts_pg_subscription];
204  bool replaces[Natts_pg_subscription];
205  Datum values[Natts_pg_subscription];
206  HeapTuple tup;
207 
208  /* Look up the subscription in the catalog */
209  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
210  tup = SearchSysCacheCopy1(SUBSCRIPTIONOID, ObjectIdGetDatum(subid));
211 
212  if (!HeapTupleIsValid(tup))
213  elog(ERROR, "cache lookup failed for subscription %u", subid);
214 
215  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
216 
217  /* Form a new tuple. */
218  memset(values, 0, sizeof(values));
219  memset(nulls, false, sizeof(nulls));
220  memset(replaces, false, sizeof(replaces));
221 
222  /* Set the subscription to disabled. */
223  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(false);
224  replaces[Anum_pg_subscription_subenabled - 1] = true;
225 
226  /* Update the catalog */
227  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
228  replaces);
229  CatalogTupleUpdate(rel, &tup->t_self, tup);
230  heap_freetuple(tup);
231 
232  table_close(rel, NoLock);
233 }
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
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:1072
#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:91

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

187 {
188  pfree(sub->name);
189  pfree(sub->conninfo);
190  if (sub->slotname)
191  pfree(sub->slotname);
193  pfree(sub);
194 }
void list_free_deep(List *list)
Definition: list.c:1560
void pfree(void *pointer)
Definition: mcxt.c:1521

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

Referenced by maybe_reread_subscription().

◆ GetPublicationsStr()

void GetPublicationsStr ( List publications,
StringInfo  dest,
bool  quote_literal 
)

Definition at line 41 of file pg_subscription.c.

42 {
43  ListCell *lc;
44  bool first = true;
45 
46  Assert(publications != NIL);
47 
48  foreach(lc, publications)
49  {
50  char *pubname = strVal(lfirst(lc));
51 
52  if (first)
53  first = false;
54  else
56 
57  if (quote_literal)
59  else
60  {
62  appendStringInfoString(dest, pubname);
64  }
65  }
66 }
#define Assert(condition)
Definition: c.h:837
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
char * quote_literal_cstr(const char *rawstr)
Definition: quote.c:103
Datum quote_literal(PG_FUNCTION_ARGS)
Definition: quote.c:78
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:191
#define strVal(v)
Definition: value.h:82

References appendStringInfoChar(), appendStringInfoString(), Assert, generate_unaccent_rules::dest, lfirst, NIL, quote_literal(), quote_literal_cstr(), and strVal.

Referenced by check_publications(), check_publications_origin(), fetch_remote_table_info(), and fetch_table_list().

◆ GetSubscription()

Subscription* GetSubscription ( Oid  subid,
bool  missing_ok 
)

Definition at line 72 of file pg_subscription.c.

73 {
74  HeapTuple tup;
75  Subscription *sub;
76  Form_pg_subscription subform;
77  Datum datum;
78  bool isnull;
79 
80  tup = SearchSysCache1(SUBSCRIPTIONOID, ObjectIdGetDatum(subid));
81 
82  if (!HeapTupleIsValid(tup))
83  {
84  if (missing_ok)
85  return NULL;
86 
87  elog(ERROR, "cache lookup failed for subscription %u", subid);
88  }
89 
90  subform = (Form_pg_subscription) GETSTRUCT(tup);
91 
92  sub = (Subscription *) palloc(sizeof(Subscription));
93  sub->oid = subid;
94  sub->dbid = subform->subdbid;
95  sub->skiplsn = subform->subskiplsn;
96  sub->name = pstrdup(NameStr(subform->subname));
97  sub->owner = subform->subowner;
98  sub->enabled = subform->subenabled;
99  sub->binary = subform->subbinary;
100  sub->stream = subform->substream;
101  sub->twophasestate = subform->subtwophasestate;
102  sub->disableonerr = subform->subdisableonerr;
103  sub->passwordrequired = subform->subpasswordrequired;
104  sub->runasowner = subform->subrunasowner;
105  sub->failover = subform->subfailover;
106 
107  /* Get conninfo */
108  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
109  tup,
110  Anum_pg_subscription_subconninfo);
111  sub->conninfo = TextDatumGetCString(datum);
112 
113  /* Get slotname */
114  datum = SysCacheGetAttr(SUBSCRIPTIONOID,
115  tup,
116  Anum_pg_subscription_subslotname,
117  &isnull);
118  if (!isnull)
119  sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
120  else
121  sub->slotname = NULL;
122 
123  /* Get synccommit */
124  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
125  tup,
126  Anum_pg_subscription_subsynccommit);
127  sub->synccommit = TextDatumGetCString(datum);
128 
129  /* Get publications */
130  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
131  tup,
132  Anum_pg_subscription_subpublications);
134 
135  /* Get origin */
136  datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
137  tup,
138  Anum_pg_subscription_suborigin);
139  sub->origin = TextDatumGetCString(datum);
140 
141  /* Is the subscription owner a superuser? */
142  sub->ownersuperuser = superuser_arg(sub->owner);
143 
144  ReleaseSysCache(tup);
145 
146  return sub;
147 }
#define DatumGetArrayTypeP(X)
Definition: array.h:261
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define NameStr(name)
Definition: c.h:725
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * pstrdup(const char *in)
Definition: mcxt.c:1696
void * palloc(Size size)
Definition: mcxt.c:1317
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:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:600
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:631

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

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 97 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 60 of file pg_subscription.h.

◆ subdisableonerr

bool subdisableonerr

Definition at line 68 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 57 of file pg_subscription.h.

◆ subfailover

bool subfailover

Definition at line 76 of file pg_subscription.h.

◆ subname

◆ subpasswordrequired

bool subpasswordrequired

Definition at line 71 of file pg_subscription.h.

◆ subrunasowner

bool subrunasowner

Definition at line 73 of file pg_subscription.h.

◆ subskiplsn

XLogRecPtr subskiplsn

Definition at line 50 of file pg_subscription.h.

◆ substream

char substream

Definition at line 63 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 66 of file pg_subscription.h.