PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 struct Subscription Subscription
 

Functions

BEGIN_CATALOG_STRUCT 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

END_CATALOG_STRUCT typedef FormData_pg_subscriptionForm_pg_subscription
 
BEGIN_CATALOG_STRUCT 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
 
bool subretaindeadtuples
 
int32 submaxretention
 
bool subretentionactive
 
 FormData_pg_subscription
 

Typedef Documentation

◆ Subscription

Function Documentation

◆ BKI_LOOKUP() [1/2]

Oid subowner BKI_LOOKUP ( pg_authid  )

◆ BKI_LOOKUP() [2/2]

Oid subdbid BKI_LOOKUP ( pg_database  )

◆ CATALOG()

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)
extern

Definition at line 163 of file pg_subscription.c.

164{
165 int nsubs = 0;
166 Relation rel;
168 SysScanDesc scan;
170
172
176 ObjectIdGetDatum(dbid));
177
178 scan = systable_beginscan(rel, InvalidOid, false,
179 NULL, 1, &scankey);
180
181 while (HeapTupleIsValid(tup = systable_getnext(scan)))
182 nsubs++;
183
184 systable_endscan(scan);
185
186 table_close(rel, NoLock);
187
188 return nsubs;
189}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
#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:262
#define InvalidOid
static int fb(int x)
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, fb(), 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)
extern

Definition at line 209 of file pg_subscription.c.

210{
211 Relation rel;
212 bool nulls[Natts_pg_subscription];
216
217 /* Look up the subscription in the catalog */
220
221 if (!HeapTupleIsValid(tup))
222 elog(ERROR, "cache lookup failed for subscription %u", subid);
223
225
226 /* Form a new tuple. */
227 memset(values, 0, sizeof(values));
228 memset(nulls, false, sizeof(nulls));
229 memset(replaces, false, sizeof(replaces));
230
231 /* Set the subscription to disabled. */
234
235 /* Update the catalog */
237 replaces);
238 CatalogTupleUpdate(rel, &tup->t_self, tup);
240
241 table_close(rel, NoLock);
242}
static Datum values[MAXATTR]
Definition bootstrap.c:147
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
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, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1088
#define AccessShareLock
Definition lockdefs.h:36
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
uint64_t Datum
Definition postgres.h:70
#define RelationGetDescr(relation)
Definition rel.h:540
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

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

Referenced by DisableSubscriptionAndExit().

◆ FreeSubscription()

void FreeSubscription ( Subscription sub)
extern

Definition at line 195 of file pg_subscription.c.

196{
197 pfree(sub->name);
198 pfree(sub->conninfo);
199 if (sub->slotname)
200 pfree(sub->slotname);
202 pfree(sub);
203}
void list_free_deep(List *list)
Definition list.c:1560
void pfree(void *pointer)
Definition mcxt.c:1616

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 
)
extern

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
55 appendStringInfoString(dest, ", ");
56
57 if (quote_literal)
59 else
60 {
61 appendStringInfoChar(dest, '"');
62 appendStringInfoString(dest, pubname);
63 appendStringInfoChar(dest, '"');
64 }
65 }
66}
#define Assert(condition)
Definition c.h:906
#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:101
Datum quote_literal(PG_FUNCTION_ARGS)
Definition quote.c:76
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
#define strVal(v)
Definition value.h:82

References appendStringInfoChar(), appendStringInfoString(), Assert, fb(), lfirst, NIL, quote_literal(), quote_literal_cstr(), and strVal.

Referenced by check_publications(), check_publications_origin_sequences(), check_publications_origin_tables(), fetch_relation_list(), and fetch_remote_table_info().

◆ GetSubscription()

Subscription * GetSubscription ( Oid  subid,
bool  missing_ok 
)
extern

Definition at line 72 of file pg_subscription.c.

73{
75 Subscription *sub;
77 Datum datum;
78 bool isnull;
79
81
83 {
84 if (missing_ok)
85 return NULL;
86
87 elog(ERROR, "cache lookup failed for subscription %u", subid);
88 }
89
91
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 sub->retaindeadtuples = subform->subretaindeadtuples;
107 sub->maxretention = subform->submaxretention;
108 sub->retentionactive = subform->subretentionactive;
109
110 /* Get conninfo */
112 tup,
114 sub->conninfo = TextDatumGetCString(datum);
115
116 /* Get slotname */
118 tup,
120 &isnull);
121 if (!isnull)
122 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
123 else
124 sub->slotname = NULL;
125
126 /* Get synccommit */
128 tup,
130 sub->synccommit = TextDatumGetCString(datum);
131
132 /* Get walrcvtimeout */
134 tup,
137
138 /* Get publications */
140 tup,
143
144 /* Get origin */
146 tup,
148 sub->origin = TextDatumGetCString(datum);
149
150 /* Is the subscription owner a superuser? */
152
154
155 return sub;
156}
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:798
#define palloc_object(type)
Definition fe_memutils.h:74
static void * GETSTRUCT(const HeapTupleData *tuple)
char * pstrdup(const char *in)
Definition mcxt.c:1781
static List * textarray_to_stringlist(ArrayType *textarray)
END_CATALOG_STRUCT typedef FormData_pg_subscription * Form_pg_subscription
static Name DatumGetName(Datum X)
Definition postgres.h:390
XLogRecPtr skiplsn
bool superuser_arg(Oid roleid)
Definition superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:625
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595

References Subscription::binary, Subscription::conninfo, DatumGetArrayTypeP, DatumGetName(), Subscription::dbid, Subscription::disableonerr, elog, Subscription::enabled, ERROR, Subscription::failover, fb(), Form_pg_subscription, GETSTRUCT(), HeapTupleIsValid, Subscription::maxretention, Subscription::name, NameStr, ObjectIdGetDatum(), Subscription::oid, Subscription::origin, Subscription::owner, Subscription::ownersuperuser, palloc_object, Subscription::passwordrequired, pstrdup(), Subscription::publications, ReleaseSysCache(), Subscription::retaindeadtuples, Subscription::retentionactive, Subscription::runasowner, SearchSysCache1(), Subscription::skiplsn, Subscription::slotname, Subscription::stream, superuser_arg(), Subscription::synccommit, SysCacheGetAttr(), SysCacheGetAttrNotNull(), textarray_to_stringlist(), TextDatumGetCString, Subscription::twophasestate, and Subscription::walrcvtimeout.

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

Initial value:
{
Oid oid
unsigned int Oid

Definition at line 45 of file pg_subscription.h.

◆ Form_pg_subscription

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 114 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 62 of file pg_subscription.h.

◆ subdisableonerr

bool subdisableonerr

Definition at line 70 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 59 of file pg_subscription.h.

◆ subfailover

bool subfailover

Definition at line 78 of file pg_subscription.h.

◆ submaxretention

int32 submaxretention

Definition at line 86 of file pg_subscription.h.

◆ subname

◆ subpasswordrequired

bool subpasswordrequired

Definition at line 73 of file pg_subscription.h.

◆ subretaindeadtuples

bool subretaindeadtuples

Definition at line 83 of file pg_subscription.h.

◆ subretentionactive

bool subretentionactive

Definition at line 90 of file pg_subscription.h.

◆ subrunasowner

bool subrunasowner

Definition at line 75 of file pg_subscription.h.

◆ subskiplsn

XLogRecPtr subskiplsn

Definition at line 52 of file pg_subscription.h.

◆ substream

char substream

Definition at line 65 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 68 of file pg_subscription.h.