PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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_foreign_server.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_subscription_rel.h"
#include "catalog/pg_type.h"
#include "foreign/foreign.h"
#include "miscadmin.h"
#include "storage/lmgr.h"
#include "storage/lock.h"
#include "utils/acl.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.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, bool aclcheck)
 
int CountDBSubscriptions (Oid dbid)
 
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, bool already_locked)
 
char GetSubscriptionRelState (Oid subid, Oid relid, XLogRecPtr *sublsn)
 
void RemoveSubscriptionRel (Oid subid, Oid relid)
 
bool HasSubscriptionTables (Oid subid)
 
ListGetSubscriptionRelations (Oid subid, bool tables, bool sequences, bool not_ready)
 
void UpdateDeadTupleRetentionStatus (Oid subid, bool active)
 

Function Documentation

◆ AddSubscriptionRelState()

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

Definition at line 304 of file pg_subscription.c.

306{
307 Relation rel;
309 bool nulls[Natts_pg_subscription_rel];
311
313
315
316 /* Try finding existing mapping. */
318 ObjectIdGetDatum(relid),
319 ObjectIdGetDatum(subid));
321 elog(ERROR, "subscription relation %u in subscription %u already exists",
322 relid, subid);
323
324 /* Form the tuple. */
325 memset(values, 0, sizeof(values));
326 memset(nulls, false, sizeof(nulls));
332 else
333 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
334
336
337 /* Insert tuple into catalog. */
339
341
342 /* Cleanup. */
343 if (retain_lock)
344 {
345 table_close(rel, NoLock);
346 }
347 else
348 {
351 }
352}
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1372
#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:1088
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1148
#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:31
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static Datum CharGetDatum(char X)
Definition postgres.h:132
static int fb(int x)
#define RelationGetDescr(relation)
Definition rel.h:542
#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 XLogRecPtrIsValid(r)
Definition xlogdefs.h:29

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

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

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

Definition at line 205 of file pg_subscription.c.

206{
207 int nsubs = 0;
208 Relation rel;
210 SysScanDesc scan;
212
214
218 ObjectIdGetDatum(dbid));
219
220 scan = systable_beginscan(rel, InvalidOid, false,
221 NULL, 1, &scankey);
222
223 while (HeapTupleIsValid(tup = systable_getnext(scan)))
224 nsubs++;
225
226 systable_endscan(scan);
227
228 table_close(rel, NoLock);
229
230 return nsubs;
231}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:612
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:523
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
#define InvalidOid
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31

References BTEqualStrategyNumber, fb(), 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 237 of file pg_subscription.c.

238{
239 Relation rel;
240 bool nulls[Natts_pg_subscription];
244
245 /* Look up the subscription in the catalog */
248
249 if (!HeapTupleIsValid(tup))
250 elog(ERROR, "cache lookup failed for subscription %u", subid);
251
253
254 /* Form a new tuple. */
255 memset(values, 0, sizeof(values));
256 memset(nulls, false, sizeof(nulls));
257 memset(replaces, false, sizeof(replaces));
258
259 /* Set the subscription to disabled. */
262
263 /* Update the catalog */
265 replaces);
266 CatalogTupleUpdate(rel, &tup->t_self, tup);
268
269 table_close(rel, NoLock);
270}
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1118
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
#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().

◆ GetPublicationsStr()

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

Definition at line 46 of file pg_subscription.c.

47{
48 ListCell *lc;
49 bool first = true;
50
51 Assert(publications != NIL);
52
53 foreach(lc, publications)
54 {
55 char *pubname = strVal(lfirst(lc));
56
57 if (first)
58 first = false;
59 else
60 appendStringInfoString(dest, ", ");
61
62 if (quote_literal)
64 else
65 {
66 appendStringInfoChar(dest, '"');
67 appendStringInfoString(dest, pubname);
68 appendStringInfoChar(dest, '"');
69 }
70 }
71}
#define Assert(condition)
Definition c.h:943
#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,
bool  aclcheck 
)

Definition at line 77 of file pg_subscription.c.

78{
80 Subscription *sub;
82 Datum datum;
83 bool isnull;
84 MemoryContext cxt;
86
88
90 {
91 if (missing_ok)
92 return NULL;
93
94 elog(ERROR, "cache lookup failed for subscription %u", subid);
95 }
96
97 cxt = AllocSetContextCreate(CurrentMemoryContext, "subscription",
100
102
104 sub->cxt = cxt;
105 sub->oid = subid;
106 sub->dbid = subform->subdbid;
107 sub->skiplsn = subform->subskiplsn;
108 sub->name = pstrdup(NameStr(subform->subname));
109 sub->owner = subform->subowner;
110 sub->enabled = subform->subenabled;
111 sub->binary = subform->subbinary;
112 sub->stream = subform->substream;
113 sub->twophasestate = subform->subtwophasestate;
114 sub->disableonerr = subform->subdisableonerr;
115 sub->passwordrequired = subform->subpasswordrequired;
116 sub->runasowner = subform->subrunasowner;
117 sub->failover = subform->subfailover;
118 sub->retaindeadtuples = subform->subretaindeadtuples;
119 sub->maxretention = subform->submaxretention;
120 sub->retentionactive = subform->subretentionactive;
121
122 /* Get conninfo */
123 if (OidIsValid(subform->subserver))
124 {
126 ForeignServer *server;
127
128 server = GetForeignServer(subform->subserver);
129
130 /* recheck ACL if requested */
131 if (aclcheck)
132 {
134 subform->subserver,
135 subform->subowner, ACL_USAGE);
136
137 if (aclresult != ACLCHECK_OK)
140 errmsg("subscription owner \"%s\" does not have permission on foreign server \"%s\"",
141 GetUserNameFromId(subform->subowner, false),
142 server->servername)));
143 }
144
146 server);
147 }
148 else
149 {
151 tup,
153 sub->conninfo = TextDatumGetCString(datum);
154 }
155
156 /* Get slotname */
158 tup,
160 &isnull);
161 if (!isnull)
162 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
163 else
164 sub->slotname = NULL;
165
166 /* Get synccommit */
168 tup,
170 sub->synccommit = TextDatumGetCString(datum);
171
172 /* Get walrcvtimeout */
174 tup,
177
178 /* Get publications */
180 tup,
183
184 /* Get origin */
186 tup,
188 sub->origin = TextDatumGetCString(datum);
189
190 /* Is the subscription owner a superuser? */
192
194
196
197 return sub;
198}
AclResult
Definition acl.h:183
@ ACLCHECK_OK
Definition acl.h:184
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3879
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:835
#define OidIsValid(objectId)
Definition c.h:858
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereport(elevel,...)
Definition elog.h:152
#define palloc_object(type)
Definition fe_memutils.h:74
char * ForeignServerConnectionString(Oid userid, ForeignServer *server)
Definition foreign.c:202
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:114
static void * GETSTRUCT(const HeapTupleData *tuple)
char * pstrdup(const char *in)
Definition mcxt.c:1781
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_SMALL_SIZES
Definition memutils.h:170
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:990
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define ACL_USAGE
Definition parsenodes.h:84
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:380
char * servername
Definition foreign.h:40
MemoryContext cxt
XLogRecPtr skiplsn
bool superuser_arg(Oid roleid)
Definition superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References ACL_USAGE, ACLCHECK_OK, ALLOCSET_SMALL_SIZES, AllocSetContextCreate, Subscription::binary, Subscription::conninfo, CurrentMemoryContext, Subscription::cxt, DatumGetArrayTypeP, DatumGetName(), Subscription::dbid, Subscription::disableonerr, elog, Subscription::enabled, ereport, errcode(), errmsg, ERROR, Subscription::failover, fb(), ForeignServerConnectionString(), Form_pg_subscription, GetForeignServer(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, Subscription::maxretention, MemoryContextSwitchTo(), Subscription::name, NameStr, object_aclcheck(), ObjectIdGetDatum(), Subscription::oid, OidIsValid, Subscription::origin, Subscription::owner, Subscription::ownersuperuser, palloc_object, Subscription::passwordrequired, pstrdup(), Subscription::publications, ReleaseSysCache(), Subscription::retaindeadtuples, Subscription::retentionactive, Subscription::runasowner, SearchSysCache1(), ForeignServer::servername, 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().

◆ GetSubscriptionRelations()

List * GetSubscriptionRelations ( Oid  subid,
bool  tables,
bool  sequences,
bool  not_ready 
)

Definition at line 602 of file pg_subscription.c.

604{
605 List *res = NIL;
606 Relation rel;
608 int nkeys = 0;
609 ScanKeyData skey[2];
610 SysScanDesc scan;
611
612 /* One or both of 'tables' and 'sequences' must be true. */
613 Assert(tables || sequences);
614
616
617 ScanKeyInit(&skey[nkeys++],
620 ObjectIdGetDatum(subid));
621
622 if (not_ready)
623 ScanKeyInit(&skey[nkeys++],
627
628 scan = systable_beginscan(rel, InvalidOid, false,
629 NULL, nkeys, skey);
630
631 while (HeapTupleIsValid(tup = systable_getnext(scan)))
632 {
634 SubscriptionRelState *relstate;
635 Datum d;
636 bool isnull;
637 char relkind;
638
640
641 /* Relation is either a sequence or a table */
642 relkind = get_rel_relkind(subrel->srrelid);
643 Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
644 relkind == RELKIND_PARTITIONED_TABLE);
645
646 /* Skip sequences if they were not requested */
647 if ((relkind == RELKIND_SEQUENCE) && !sequences)
648 continue;
649
650 /* Skip tables if they were not requested */
651 if ((relkind == RELKIND_RELATION ||
652 relkind == RELKIND_PARTITIONED_TABLE) && !tables)
653 continue;
654
656 relstate->relid = subrel->srrelid;
657 relstate->state = subrel->srsubstate;
660 if (isnull)
661 relstate->lsn = InvalidXLogRecPtr;
662 else
663 relstate->lsn = DatumGetLSN(d);
664
665 res = lappend(res, relstate);
666 }
667
668 /* Cleanup */
669 systable_endscan(scan);
671
672 return res;
673}
List * lappend(List *list, void *datum)
Definition list.c:339
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2223
static SequenceItem * sequences
Definition pg_dump.c:214
static XLogRecPtr DatumGetLSN(Datum X)
Definition pg_lsn.h:25
END_CATALOG_STRUCT typedef FormData_pg_subscription_rel * Form_pg_subscription_rel
Definition pg_list.h:54
#define InvalidXLogRecPtr
Definition xlogdefs.h:28

References AccessShareLock, Assert, BTEqualStrategyNumber, CharGetDatum(), DatumGetLSN(), fb(), Form_pg_subscription_rel, get_rel_relkind(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, InvalidXLogRecPtr, lappend(), SubscriptionRelState::lsn, NIL, ObjectIdGetDatum(), palloc_object, SubscriptionRelState::relid, ScanKeyInit(), sequences, SubscriptionRelState::state, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by AlterSubscription_refresh(), AlterSubscription_refresh_seq(), DropSubscription(), and FetchRelationStates().

◆ GetSubscriptionRelState()

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

Definition at line 424 of file pg_subscription.c.

425{
427 char substate;
428 bool isnull;
429 Datum d;
430 Relation rel;
431
432 /*
433 * This is to avoid the race condition with AlterSubscription which tries
434 * to remove this relstate.
435 */
437
438 /* Try finding the mapping. */
440 ObjectIdGetDatum(relid),
441 ObjectIdGetDatum(subid));
442
443 if (!HeapTupleIsValid(tup))
444 {
448 }
449
450 /* Get the state. */
452
453 /* Get the LSN */
456 if (isnull)
458 else
459 *sublsn = DatumGetLSN(d);
460
461 /* Cleanup */
463
465
466 return substate;
467}
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231

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

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

◆ HasSubscriptionTables()

bool HasSubscriptionTables ( Oid  subid)

Definition at line 553 of file pg_subscription.c.

554{
555 Relation rel;
556 ScanKeyData skey[1];
557 SysScanDesc scan;
559 bool has_subtables = false;
560
562
563 ScanKeyInit(&skey[0],
566 ObjectIdGetDatum(subid));
567
568 scan = systable_beginscan(rel, InvalidOid, false,
569 NULL, 1, skey);
570
571 while (HeapTupleIsValid(tup = systable_getnext(scan)))
572 {
574 char relkind;
575
577 relkind = get_rel_relkind(subrel->srrelid);
578
579 if (relkind == RELKIND_RELATION ||
580 relkind == RELKIND_PARTITIONED_TABLE)
581 {
582 has_subtables = true;
583 break;
584 }
585 }
586
587 /* Cleanup */
588 systable_endscan(scan);
590
591 return has_subtables;
592}

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

Referenced by FetchRelationStates().

◆ RemoveSubscriptionRel()

void RemoveSubscriptionRel ( Oid  subid,
Oid  relid 
)

Definition at line 474 of file pg_subscription.c.

475{
476 Relation rel;
477 TableScanDesc scan;
478 ScanKeyData skey[2];
480 int nkeys = 0;
481
483
484 if (OidIsValid(subid))
485 {
486 ScanKeyInit(&skey[nkeys++],
489 F_OIDEQ,
490 ObjectIdGetDatum(subid));
491 }
492
493 if (OidIsValid(relid))
494 {
495 ScanKeyInit(&skey[nkeys++],
498 F_OIDEQ,
499 ObjectIdGetDatum(relid));
500 }
501
502 /* Do the search and delete what we found. */
503 scan = table_beginscan_catalog(rel, nkeys, skey);
505 {
507
509
510 /*
511 * We don't allow to drop the relation mapping when the table
512 * synchronization is in progress unless the caller updates the
513 * corresponding subscription as well. This is to ensure that we don't
514 * leave tablesync slots or origins in the system when the
515 * corresponding table is dropped. For sequences, however, it's ok to
516 * drop them since no separate slots or origins are created during
517 * synchronization.
518 */
519 if (!OidIsValid(subid) &&
520 subrel->srsubstate != SUBREL_STATE_READY &&
522 {
525 errmsg("could not drop relation mapping for subscription \"%s\"",
526 get_subscription_name(subrel->srsubid, false)),
527 errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
528 get_rel_name(relid), subrel->srsubstate),
529
530 /*
531 * translator: first %s is a SQL ALTER command and second %s is a
532 * SQL DROP command
533 */
534 errhint("Use %s to enable subscription if not already enabled or use %s to drop the subscription.",
535 "ALTER SUBSCRIPTION ... ENABLE",
536 "DROP SUBSCRIPTION ...")));
537 }
538
539 CatalogTupleDelete(rel, &tup->t_self);
540 }
541 table_endscan(scan);
542
544}
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition heapam.c:1435
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
char * get_rel_name(Oid relid)
Definition lsyscache.c:2148
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:3942
@ ForwardScanDirection
Definition sdir.h:28
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, ScanKeyData *key)
Definition tableam.c:113
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1061

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errdetail(), errhint(), errmsg, ERROR, fb(), Form_pg_subscription_rel, ForwardScanDirection, get_rel_name(), get_rel_relkind(), get_subscription_name(), GETSTRUCT(), heap_getnext(), HeapTupleIsValid, ObjectIdGetDatum(), OidIsValid, RowExclusiveLock, ScanKeyInit(), 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 278 of file pg_subscription.c.

279{
280 Datum *elems;
281 int nelems,
282 i;
283 List *res = NIL;
284
286
287 if (nelems == 0)
288 return NIL;
289
290 for (i = 0; i < nelems; i++)
291 res = lappend(res, makeString(TextDatumGetCString(elems[i])));
292
293 return res;
294}
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
int i
Definition isn.c:77
String * makeString(char *str)
Definition value.c:63

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

Referenced by GetSubscription().

◆ UpdateDeadTupleRetentionStatus()

void UpdateDeadTupleRetentionStatus ( Oid  subid,
bool  active 
)

Definition at line 679 of file pg_subscription.c.

680{
681 Relation rel;
682 bool nulls[Natts_pg_subscription];
686
687 /* Look up the subscription in the catalog */
690
691 if (!HeapTupleIsValid(tup))
692 elog(ERROR, "cache lookup failed for subscription %u", subid);
693
695
696 /* Form a new tuple. */
697 memset(values, 0, sizeof(values));
698 memset(nulls, false, sizeof(nulls));
699 memset(replaces, false, sizeof(replaces));
700
701 /* Set the subscription to disabled. */
704
705 /* Update the catalog */
707 replaces);
708 CatalogTupleUpdate(rel, &tup->t_self, tup);
710
711 table_close(rel, NoLock);
712}

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

Referenced by update_retention_status().

◆ UpdateSubscriptionRelState()

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

Definition at line 358 of file pg_subscription.c.

360{
361 Relation rel;
363 bool nulls[Natts_pg_subscription_rel];
366
367 if (already_locked)
368 {
369#ifdef USE_ASSERT_CHECKING
370 LOCKTAG tag;
371
373 RowExclusiveLock, true));
375 Assert(LockHeldByMe(&tag, AccessShareLock, true));
376#endif
377
379 }
380 else
381 {
384 }
385
386 /* Try finding existing mapping. */
388 ObjectIdGetDatum(relid),
389 ObjectIdGetDatum(subid));
390 if (!HeapTupleIsValid(tup))
391 elog(ERROR, "subscription relation %u in subscription %u does not exist",
392 relid, subid);
393
394 /* Update the tuple. */
395 memset(values, 0, sizeof(values));
396 memset(nulls, false, sizeof(nulls));
397 memset(replaces, false, sizeof(replaces));
398
401
405 else
406 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
407
409 replaces);
410
411 /* Update the catalog. */
412 CatalogTupleUpdate(rel, &tup->t_self, tup);
413
414 /* Cleanup. */
415 table_close(rel, NoLock);
416}
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
Definition lmgr.c:351
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
Definition lock.c:641
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition locktag.h:162

References AccessShareLock, Assert, CatalogTupleUpdate(), CharGetDatum(), CheckRelationOidLockedByMe(), elog, ERROR, fb(), heap_modify_tuple(), HeapTupleIsValid, InvalidOid, LockHeldByMe(), LockSharedObject(), LSNGetDatum(), NoLock, ObjectIdGetDatum(), RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, SET_LOCKTAG_OBJECT, table_close(), table_open(), values, and XLogRecPtrIsValid.

Referenced by AlterSubscription_refresh_seq(), copy_sequence(), LogicalRepSyncTableStart(), ProcessSyncingTablesForApply(), and ProcessSyncingTablesForSync().