PostgreSQL Source Code git master
pg_subscription.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "catalog/indexing.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_subscription_rel.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "storage/lmgr.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/pg_lsn.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for pg_subscription.c:

Go to the source code of this file.

Functions

static Listtextarray_to_stringlist (ArrayType *textarray)
 
void GetPublicationsStr (List *publications, StringInfo dest, bool quote_literal)
 
SubscriptionGetSubscription (Oid subid, bool missing_ok)
 
int CountDBSubscriptions (Oid dbid)
 
void FreeSubscription (Subscription *sub)
 
void DisableSubscription (Oid subid)
 
void AddSubscriptionRelState (Oid subid, Oid relid, char state, XLogRecPtr sublsn, bool retain_lock)
 
void UpdateSubscriptionRelState (Oid subid, Oid relid, char state, XLogRecPtr sublsn)
 
char GetSubscriptionRelState (Oid subid, Oid relid, XLogRecPtr *sublsn)
 
void RemoveSubscriptionRel (Oid subid, Oid relid)
 
bool HasSubscriptionRelations (Oid subid)
 
ListGetSubscriptionRelations (Oid subid, bool not_ready)
 

Function Documentation

◆ AddSubscriptionRelState()

void AddSubscriptionRelState ( Oid  subid,
Oid  relid,
char  state,
XLogRecPtr  sublsn,
bool  retain_lock 
)

Definition at line 267 of file pg_subscription.c.

269{
270 Relation rel;
271 HeapTuple tup;
272 bool nulls[Natts_pg_subscription_rel];
273 Datum values[Natts_pg_subscription_rel];
274
275 LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
276
277 rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
278
279 /* Try finding existing mapping. */
280 tup = SearchSysCacheCopy2(SUBSCRIPTIONRELMAP,
281 ObjectIdGetDatum(relid),
282 ObjectIdGetDatum(subid));
283 if (HeapTupleIsValid(tup))
284 elog(ERROR, "subscription table %u in subscription %u already exists",
285 relid, subid);
286
287 /* Form the tuple. */
288 memset(values, 0, sizeof(values));
289 memset(nulls, false, sizeof(nulls));
290 values[Anum_pg_subscription_rel_srsubid - 1] = ObjectIdGetDatum(subid);
291 values[Anum_pg_subscription_rel_srrelid - 1] = ObjectIdGetDatum(relid);
292 values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
293 if (sublsn != InvalidXLogRecPtr)
294 values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn);
295 else
296 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
297
298 tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
299
300 /* Insert tuple into catalog. */
301 CatalogTupleInsert(rel, tup);
302
303 heap_freetuple(tup);
304
305 /* Cleanup. */
306 if (retain_lock)
307 {
308 table_close(rel, NoLock);
309 }
310 else
311 {
313 UnlockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
314 }
315}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1072
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1131
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
#define RowExclusiveLock
Definition: lockdefs.h:38
static Datum LSNGetDatum(XLogRecPtr X)
Definition: pg_lsn.h:28
uintptr_t Datum
Definition: postgres.h:69
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Datum CharGetDatum(char X)
Definition: postgres.h:127
#define RelationGetDescr(relation)
Definition: rel.h:531
Definition: regguts.h:323
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:93
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References AccessShareLock, CatalogTupleInsert(), CharGetDatum(), elog, ERROR, heap_form_tuple(), heap_freetuple(), HeapTupleIsValid, InvalidXLogRecPtr, LockSharedObject(), LSNGetDatum(), NoLock, ObjectIdGetDatum(), RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, table_close(), table_open(), UnlockSharedObject(), and values.

Referenced by AlterSubscription_refresh(), binary_upgrade_add_sub_rel_state(), and CreateSubscription().

◆ 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:606
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:513
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
#define InvalidOid
Definition: postgres_ext.h:37
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31

References BTEqualStrategyNumber, HeapTupleIsValid, InvalidOid, NoLock, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by dropdb().

◆ 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}
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition: heaptuple.c:1210
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107
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 {
64 }
65 }
66}
#define Assert(condition)
Definition: c.h:815
#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:230
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
#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;
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? */
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:703
#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:365
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().

◆ GetSubscriptionRelations()

List * GetSubscriptionRelations ( Oid  subid,
bool  not_ready 
)

Definition at line 532 of file pg_subscription.c.

533{
534 List *res = NIL;
535 Relation rel;
536 HeapTuple tup;
537 int nkeys = 0;
538 ScanKeyData skey[2];
539 SysScanDesc scan;
540
541 rel = table_open(SubscriptionRelRelationId, AccessShareLock);
542
543 ScanKeyInit(&skey[nkeys++],
544 Anum_pg_subscription_rel_srsubid,
545 BTEqualStrategyNumber, F_OIDEQ,
546 ObjectIdGetDatum(subid));
547
548 if (not_ready)
549 ScanKeyInit(&skey[nkeys++],
550 Anum_pg_subscription_rel_srsubstate,
551 BTEqualStrategyNumber, F_CHARNE,
552 CharGetDatum(SUBREL_STATE_READY));
553
554 scan = systable_beginscan(rel, InvalidOid, false,
555 NULL, nkeys, skey);
556
557 while (HeapTupleIsValid(tup = systable_getnext(scan)))
558 {
560 SubscriptionRelState *relstate;
561 Datum d;
562 bool isnull;
563
564 subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
565
566 relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState));
567 relstate->relid = subrel->srrelid;
568 relstate->state = subrel->srsubstate;
569 d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
570 Anum_pg_subscription_rel_srsublsn, &isnull);
571 if (isnull)
572 relstate->lsn = InvalidXLogRecPtr;
573 else
574 relstate->lsn = DatumGetLSN(d);
575
576 res = lappend(res, relstate);
577 }
578
579 /* Cleanup */
580 systable_endscan(scan);
582
583 return res;
584}
List * lappend(List *list, void *datum)
Definition: list.c:339
static XLogRecPtr DatumGetLSN(Datum X)
Definition: pg_lsn.h:22
FormData_pg_subscription_rel * Form_pg_subscription_rel
Definition: pg_list.h:54

References AccessShareLock, BTEqualStrategyNumber, CharGetDatum(), DatumGetLSN(), GETSTRUCT, HeapTupleIsValid, InvalidOid, InvalidXLogRecPtr, lappend(), SubscriptionRelState::lsn, NIL, ObjectIdGetDatum(), palloc(), SubscriptionRelState::relid, res, ScanKeyInit(), SubscriptionRelState::state, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by AlterSubscription_refresh(), DropSubscription(), and FetchTableStates().

◆ GetSubscriptionRelState()

char GetSubscriptionRelState ( Oid  subid,
Oid  relid,
XLogRecPtr sublsn 
)

Definition at line 372 of file pg_subscription.c.

373{
374 HeapTuple tup;
375 char substate;
376 bool isnull;
377 Datum d;
378 Relation rel;
379
380 /*
381 * This is to avoid the race condition with AlterSubscription which tries
382 * to remove this relstate.
383 */
384 rel = table_open(SubscriptionRelRelationId, AccessShareLock);
385
386 /* Try finding the mapping. */
387 tup = SearchSysCache2(SUBSCRIPTIONRELMAP,
388 ObjectIdGetDatum(relid),
389 ObjectIdGetDatum(subid));
390
391 if (!HeapTupleIsValid(tup))
392 {
394 *sublsn = InvalidXLogRecPtr;
395 return SUBREL_STATE_UNKNOWN;
396 }
397
398 /* Get the state. */
399 substate = ((Form_pg_subscription_rel) GETSTRUCT(tup))->srsubstate;
400
401 /* Get the LSN */
402 d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
403 Anum_pg_subscription_rel_srsublsn, &isnull);
404 if (isnull)
405 *sublsn = InvalidXLogRecPtr;
406 else
407 *sublsn = DatumGetLSN(d);
408
409 /* Cleanup */
410 ReleaseSysCache(tup);
411
413
414 return substate;
415}
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:232

References AccessShareLock, DatumGetLSN(), GETSTRUCT, HeapTupleIsValid, InvalidXLogRecPtr, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), table_close(), and table_open().

Referenced by AlterSubscription_refresh(), logicalrep_rel_open(), LogicalRepSyncTableStart(), and wait_for_relation_state_change().

◆ HasSubscriptionRelations()

bool HasSubscriptionRelations ( Oid  subid)

Definition at line 497 of file pg_subscription.c.

498{
499 Relation rel;
500 ScanKeyData skey[1];
501 SysScanDesc scan;
502 bool has_subrels;
503
504 rel = table_open(SubscriptionRelRelationId, AccessShareLock);
505
506 ScanKeyInit(&skey[0],
507 Anum_pg_subscription_rel_srsubid,
508 BTEqualStrategyNumber, F_OIDEQ,
509 ObjectIdGetDatum(subid));
510
511 scan = systable_beginscan(rel, InvalidOid, false,
512 NULL, 1, skey);
513
514 /* If even a single tuple exists then the subscription has tables. */
515 has_subrels = HeapTupleIsValid(systable_getnext(scan));
516
517 /* Cleanup */
518 systable_endscan(scan);
520
521 return has_subrels;
522}

References AccessShareLock, BTEqualStrategyNumber, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by FetchTableStates().

◆ RemoveSubscriptionRel()

void RemoveSubscriptionRel ( Oid  subid,
Oid  relid 
)

Definition at line 422 of file pg_subscription.c.

423{
424 Relation rel;
425 TableScanDesc scan;
426 ScanKeyData skey[2];
427 HeapTuple tup;
428 int nkeys = 0;
429
430 rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
431
432 if (OidIsValid(subid))
433 {
434 ScanKeyInit(&skey[nkeys++],
435 Anum_pg_subscription_rel_srsubid,
437 F_OIDEQ,
438 ObjectIdGetDatum(subid));
439 }
440
441 if (OidIsValid(relid))
442 {
443 ScanKeyInit(&skey[nkeys++],
444 Anum_pg_subscription_rel_srrelid,
446 F_OIDEQ,
447 ObjectIdGetDatum(relid));
448 }
449
450 /* Do the search and delete what we found. */
451 scan = table_beginscan_catalog(rel, nkeys, skey);
453 {
455
456 subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
457
458 /*
459 * We don't allow to drop the relation mapping when the table
460 * synchronization is in progress unless the caller updates the
461 * corresponding subscription as well. This is to ensure that we don't
462 * leave tablesync slots or origins in the system when the
463 * corresponding table is dropped.
464 */
465 if (!OidIsValid(subid) && subrel->srsubstate != SUBREL_STATE_READY)
466 {
468 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
469 errmsg("could not drop relation mapping for subscription \"%s\"",
470 get_subscription_name(subrel->srsubid, false)),
471 errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
472 get_rel_name(relid), subrel->srsubstate),
473
474 /*
475 * translator: first %s is a SQL ALTER command and second %s is a
476 * SQL DROP command
477 */
478 errhint("Use %s to enable subscription if not already enabled or use %s to drop the subscription.",
479 "ALTER SUBSCRIPTION ... ENABLE",
480 "DROP SUBSCRIPTION ...")));
481 }
482
483 CatalogTupleDelete(rel, &tup->t_self);
484 }
485 table_endscan(scan);
486
488}
#define OidIsValid(objectId)
Definition: c.h:732
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1264
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:365
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1928
char * get_subscription_name(Oid subid, bool missing_ok)
Definition: lsyscache.c:3695
@ ForwardScanDirection
Definition: sdir.h:28
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:112
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1024

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, ForwardScanDirection, get_rel_name(), get_subscription_name(), GETSTRUCT, heap_getnext(), HeapTupleIsValid, ObjectIdGetDatum(), OidIsValid, RowExclusiveLock, ScanKeyInit(), HeapTupleData::t_self, table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by AlterSubscription_refresh(), DropSubscription(), and heap_drop_with_catalog().

◆ textarray_to_stringlist()

static List * textarray_to_stringlist ( ArrayType textarray)
static

Definition at line 241 of file pg_subscription.c.

242{
243 Datum *elems;
244 int nelems,
245 i;
246 List *res = NIL;
247
248 deconstruct_array_builtin(textarray, TEXTOID, &elems, NULL, &nelems);
249
250 if (nelems == 0)
251 return NIL;
252
253 for (i = 0; i < nelems; i++)
255
256 return res;
257}
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Definition: arrayfuncs.c:3697
int i
Definition: isn.c:72
String * makeString(char *str)
Definition: value.c:63

References deconstruct_array_builtin(), i, lappend(), makeString(), NIL, res, and TextDatumGetCString.

Referenced by GetSubscription().

◆ UpdateSubscriptionRelState()

void UpdateSubscriptionRelState ( Oid  subid,
Oid  relid,
char  state,
XLogRecPtr  sublsn 
)

Definition at line 321 of file pg_subscription.c.

323{
324 Relation rel;
325 HeapTuple tup;
326 bool nulls[Natts_pg_subscription_rel];
327 Datum values[Natts_pg_subscription_rel];
328 bool replaces[Natts_pg_subscription_rel];
329
330 LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
331
332 rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
333
334 /* Try finding existing mapping. */
335 tup = SearchSysCacheCopy2(SUBSCRIPTIONRELMAP,
336 ObjectIdGetDatum(relid),
337 ObjectIdGetDatum(subid));
338 if (!HeapTupleIsValid(tup))
339 elog(ERROR, "subscription table %u in subscription %u does not exist",
340 relid, subid);
341
342 /* Update the tuple. */
343 memset(values, 0, sizeof(values));
344 memset(nulls, false, sizeof(nulls));
345 memset(replaces, false, sizeof(replaces));
346
347 replaces[Anum_pg_subscription_rel_srsubstate - 1] = true;
348 values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
349
350 replaces[Anum_pg_subscription_rel_srsublsn - 1] = true;
351 if (sublsn != InvalidXLogRecPtr)
352 values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn);
353 else
354 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
355
356 tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
357 replaces);
358
359 /* Update the catalog. */
360 CatalogTupleUpdate(rel, &tup->t_self, tup);
361
362 /* Cleanup. */
363 table_close(rel, NoLock);
364}

References AccessShareLock, CatalogTupleUpdate(), CharGetDatum(), elog, ERROR, heap_modify_tuple(), HeapTupleIsValid, InvalidXLogRecPtr, LockSharedObject(), LSNGetDatum(), NoLock, ObjectIdGetDatum(), RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, HeapTupleData::t_self, table_close(), table_open(), and values.

Referenced by LogicalRepSyncTableStart(), process_syncing_tables_for_apply(), and process_syncing_tables_for_sync().