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 conninfo_needed, bool conninfo_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 336 of file pg_subscription.c.

338{
339 Relation rel;
341 bool nulls[Natts_pg_subscription_rel];
343
345
347
348 /* Try finding existing mapping. */
350 ObjectIdGetDatum(relid),
351 ObjectIdGetDatum(subid));
353 elog(ERROR, "subscription relation %u in subscription %u already exists",
354 relid, subid);
355
356 /* Form the tuple. */
357 memset(values, 0, sizeof(values));
358 memset(nulls, false, sizeof(nulls));
364 else
365 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
366
368
369 /* Insert tuple into catalog. */
371
373
374 /* Cleanup. */
375 if (retain_lock)
376 {
377 table_close(rel, NoLock);
378 }
379 else
380 {
383 }
384}
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(), and binary_upgrade_add_sub_rel_state().

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)

Definition at line 234 of file pg_subscription.c.

235{
236 int nsubs = 0;
237 Relation rel;
239 SysScanDesc scan;
241
243
247 ObjectIdGetDatum(dbid));
248
249 scan = systable_beginscan(rel, InvalidOid, false,
250 NULL, 1, &scankey);
251
252 while (HeapTupleIsValid(tup = systable_getnext(scan)))
253 nsubs++;
254
255 systable_endscan(scan);
256
257 table_close(rel, NoLock);
258
259 return nsubs;
260}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:604
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:515
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 266 of file pg_subscription.c.

267{
268 Relation rel;
269 bool nulls[Natts_pg_subscription];
273
274 /* Look up the subscription in the catalog */
277
278 if (!HeapTupleIsValid(tup))
279 elog(ERROR, "cache lookup failed for subscription %u", subid);
280
281 /* Must only modify subscriptions belonging to the current database. */
283
285
286 /* Form a new tuple. */
287 memset(values, 0, sizeof(values));
288 memset(nulls, false, sizeof(nulls));
289 memset(replaces, false, sizeof(replaces));
290
291 /* Set the subscription to disabled. */
294
295 /* Update the catalog */
297 replaces);
298 CatalogTupleUpdate(rel, &tup->t_self, tup);
300
301 table_close(rel, NoLock);
302}
#define Assert(condition)
Definition c.h:1002
Oid MyDatabaseId
Definition globals.c:96
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1118
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
END_CATALOG_STRUCT typedef FormData_pg_subscription * Form_pg_subscription
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

References AccessShareLock, Assert, BoolGetDatum(), CatalogTupleUpdate(), elog, ERROR, fb(), Form_pg_subscription, GETSTRUCT(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, LockSharedObject(), MyDatabaseId, 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 50 of file pg_subscription.c.

51{
52 ListCell *lc;
53 bool first = true;
54
55 Assert(publications != NIL);
56
57 foreach(lc, publications)
58 {
59 char *pubname = strVal(lfirst(lc));
60
61 if (quote_literal)
62 {
63 if (!first)
64 appendStringInfoString(dest, ", ");
66 }
67 else
68 {
69 if (first)
70 appendStringInfo(dest, _("\"%s\""), pubname);
71 else
72 appendStringInfo(dest, _(", \"%s\""), pubname);
73 }
74
75 first = false;
76 }
77}
#define _(x)
Definition elog.c:96
#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 appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
#define strVal(v)
Definition value.h:82

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

Referenced by 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  conninfo_needed,
bool  conninfo_aclcheck 
)

Definition at line 88 of file pg_subscription.c.

90{
92 Subscription *sub;
94 Datum datum;
95 bool isnull;
96 MemoryContext cxt;
98
100
102
103 if (!HeapTupleIsValid(tup))
104 {
105 if (missing_ok)
106 return NULL;
107
108 elog(ERROR, "cache lookup failed for subscription %u", subid);
109 }
110
111 cxt = AllocSetContextCreate(CurrentMemoryContext, "subscription",
114
116
117 /*
118 * It's only safe to access subscriptions from another database from the
119 * launcher process, which does not call GetSubscription().
120 */
121 Assert(subform->subdbid == MyDatabaseId);
122
124 sub->cxt = cxt;
125 sub->oid = subid;
126 sub->dbid = subform->subdbid;
127 sub->skiplsn = subform->subskiplsn;
128 sub->name = pstrdup(NameStr(subform->subname));
129 sub->owner = subform->subowner;
130 sub->enabled = subform->subenabled;
131 sub->binary = subform->subbinary;
132 sub->stream = subform->substream;
133 sub->twophasestate = subform->subtwophasestate;
134 sub->disableonerr = subform->subdisableonerr;
135 sub->passwordrequired = subform->subpasswordrequired;
136 sub->runasowner = subform->subrunasowner;
137 sub->failover = subform->subfailover;
138 sub->retaindeadtuples = subform->subretaindeadtuples;
139 sub->maxretention = subform->submaxretention;
140 sub->retentionactive = subform->subretentionactive;
141 sub->conflictlogrelid = subform->subconflictlogrelid;
142
143 if (conninfo_needed)
144 {
145 if (OidIsValid(subform->subserver))
146 {
148 ForeignServer *server;
149
150 server = GetForeignServer(subform->subserver);
151
153 {
154 /* recheck ACL if requested */
156 subform->subserver,
157 subform->subowner, ACL_USAGE);
158
159 if (aclresult != ACLCHECK_OK)
162 errmsg("subscription owner \"%s\" does not have permission on foreign server \"%s\"",
163 GetUserNameFromId(subform->subowner, false),
164 server->servername)));
165 }
166
168 server);
169 }
170 else
171 {
173 tup,
175 sub->conninfo = TextDatumGetCString(datum);
176 }
177 }
178
179 /* Get slotname */
181 tup,
183 &isnull);
184 if (!isnull)
185 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
186 else
187 sub->slotname = NULL;
188
189 /* Get synccommit */
191 tup,
193 sub->synccommit = TextDatumGetCString(datum);
194
195 /* Get walrcvtimeout */
197 tup,
200
201 /* Get publications */
203 tup,
206
207 /* Get origin */
209 tup,
211 sub->origin = TextDatumGetCString(datum);
212
213 /* Get conflict log destination */
215 tup,
218
219 /* Is the subscription owner a superuser? */
221
223
225
226 return sub;
227}
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:3902
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:894
#define OidIsValid(objectId)
Definition c.h:917
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
#define palloc0_object(type)
Definition fe_memutils.h:90
char * ForeignServerConnectionString(Oid userid, ForeignServer *server)
Definition foreign.c:202
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:114
char * pstrdup(const char *in)
Definition mcxt.c:1910
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
#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:138
#define ACL_USAGE
Definition parsenodes.h:84
static List * textarray_to_stringlist(ArrayType *textarray)
static Name DatumGetName(Datum X)
Definition postgres.h:393
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, Assert, Subscription::binary, Subscription::conflictlogdest, Subscription::conflictlogrelid, 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(), MyDatabaseId, Subscription::name, NameStr, object_aclcheck(), ObjectIdGetDatum(), Subscription::oid, OidIsValid, Subscription::origin, Subscription::owner, Subscription::ownersuperuser, palloc0_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 634 of file pg_subscription.c.

636{
637 List *res = NIL;
638 Relation rel;
640 int nkeys = 0;
641 ScanKeyData skey[2];
642 SysScanDesc scan;
643
644 /* One or both of 'tables' and 'sequences' must be true. */
645 Assert(tables || sequences);
646
648
649 ScanKeyInit(&skey[nkeys++],
652 ObjectIdGetDatum(subid));
653
654 if (not_ready)
655 ScanKeyInit(&skey[nkeys++],
659
660 scan = systable_beginscan(rel, InvalidOid, false,
661 NULL, nkeys, skey);
662
663 while (HeapTupleIsValid(tup = systable_getnext(scan)))
664 {
666 SubscriptionRelState *relstate;
667 Datum d;
668 bool isnull;
669 char relkind;
670
672
673 /* Relation is either a sequence or a table */
674 relkind = get_rel_relkind(subrel->srrelid);
675 Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
676 relkind == RELKIND_PARTITIONED_TABLE);
677
678 /* Skip sequences if they were not requested */
679 if ((relkind == RELKIND_SEQUENCE) && !sequences)
680 continue;
681
682 /* Skip tables if they were not requested */
683 if ((relkind == RELKIND_RELATION ||
684 relkind == RELKIND_PARTITIONED_TABLE) && !tables)
685 continue;
686
688 relstate->relid = subrel->srrelid;
689 relstate->state = subrel->srsubstate;
692 if (isnull)
693 relstate->lsn = InvalidXLogRecPtr;
694 else
695 relstate->lsn = DatumGetLSN(d);
696
697 res = lappend(res, relstate);
698 }
699
700 /* Cleanup */
701 systable_endscan(scan);
703
704 return res;
705}
#define palloc_object(type)
Definition fe_memutils.h:89
List * lappend(List *list, void *datum)
Definition list.c:339
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2317
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 456 of file pg_subscription.c.

457{
459 char substate;
460 bool isnull;
461 Datum d;
462 Relation rel;
463
464 /*
465 * This is to avoid the race condition with AlterSubscription which tries
466 * to remove this relstate.
467 */
469
470 /* Try finding the mapping. */
472 ObjectIdGetDatum(relid),
473 ObjectIdGetDatum(subid));
474
475 if (!HeapTupleIsValid(tup))
476 {
480 }
481
482 /* Get the state. */
484
485 /* Get the LSN */
488 if (isnull)
490 else
491 *sublsn = DatumGetLSN(d);
492
493 /* Cleanup */
495
497
498 return substate;
499}
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 585 of file pg_subscription.c.

586{
587 Relation rel;
588 ScanKeyData skey[1];
589 SysScanDesc scan;
591 bool has_subtables = false;
592
594
595 ScanKeyInit(&skey[0],
598 ObjectIdGetDatum(subid));
599
600 scan = systable_beginscan(rel, InvalidOid, false,
601 NULL, 1, skey);
602
603 while (HeapTupleIsValid(tup = systable_getnext(scan)))
604 {
606 char relkind;
607
609 relkind = get_rel_relkind(subrel->srrelid);
610
611 if (relkind == RELKIND_RELATION ||
612 relkind == RELKIND_PARTITIONED_TABLE)
613 {
614 has_subtables = true;
615 break;
616 }
617 }
618
619 /* Cleanup */
620 systable_endscan(scan);
622
623 return has_subtables;
624}

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

507{
508 Relation rel;
509 TableScanDesc scan;
510 ScanKeyData skey[2];
512 int nkeys = 0;
513
515
516 if (OidIsValid(subid))
517 {
518 ScanKeyInit(&skey[nkeys++],
521 F_OIDEQ,
522 ObjectIdGetDatum(subid));
523 }
524
525 if (OidIsValid(relid))
526 {
527 ScanKeyInit(&skey[nkeys++],
530 F_OIDEQ,
531 ObjectIdGetDatum(relid));
532 }
533
534 /* Do the search and delete what we found. */
535 scan = table_beginscan_catalog(rel, nkeys, skey);
537 {
539
541
542 /*
543 * We don't allow to drop the relation mapping when the table
544 * synchronization is in progress unless the caller updates the
545 * corresponding subscription as well. This is to ensure that we don't
546 * leave tablesync slots or origins in the system when the
547 * corresponding table is dropped. For sequences, however, it's ok to
548 * drop them since no separate slots or origins are created during
549 * synchronization.
550 */
551 if (!OidIsValid(subid) &&
552 subrel->srsubstate != SUBREL_STATE_READY &&
554 {
557 errmsg("could not drop relation mapping for subscription \"%s\"",
558 get_subscription_name(subrel->srsubid, false)),
559 errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
560 get_rel_name(relid), subrel->srsubstate),
561
562 /*
563 * translator: first %s is a SQL ALTER command and second %s is a
564 * SQL DROP command
565 */
566 errhint("Use %s to enable subscription if not already enabled or use %s to drop the subscription.",
567 "ALTER SUBSCRIPTION ... ENABLE",
568 "DROP SUBSCRIPTION ...")));
569 }
570
571 CatalogTupleDelete(rel, &tup->t_self);
572 }
573 table_endscan(scan);
574
576}
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:1436
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
char * get_rel_name(Oid relid)
Definition lsyscache.c:2242
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:4056
@ 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 310 of file pg_subscription.c.

311{
312 Datum *elems;
313 int nelems,
314 i;
315 List *res = NIL;
316
318
319 if (nelems == 0)
320 return NIL;
321
322 for (i = 0; i < nelems; i++)
323 res = lappend(res, makeString(TextDatumGetCString(elems[i])));
324
325 return res;
326}
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 711 of file pg_subscription.c.

712{
713 Relation rel;
714 bool nulls[Natts_pg_subscription];
718
719 /* Look up the subscription in the catalog */
722
723 if (!HeapTupleIsValid(tup))
724 elog(ERROR, "cache lookup failed for subscription %u", subid);
725
726 /* Must only modify subscriptions belonging to the current database. */
728
730
731 /* Form a new tuple. */
732 memset(values, 0, sizeof(values));
733 memset(nulls, false, sizeof(nulls));
734 memset(replaces, false, sizeof(replaces));
735
736 /* Set the subscription to disabled. */
739
740 /* Update the catalog */
742 replaces);
743 CatalogTupleUpdate(rel, &tup->t_self, tup);
745
746 table_close(rel, NoLock);
747}

References AccessShareLock, Assert, BoolGetDatum(), CatalogTupleUpdate(), elog, ERROR, fb(), Form_pg_subscription, GETSTRUCT(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, LockSharedObject(), MyDatabaseId, 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 390 of file pg_subscription.c.

392{
393 Relation rel;
395 bool nulls[Natts_pg_subscription_rel];
398
399 if (already_locked)
400 {
401#ifdef USE_ASSERT_CHECKING
402 LOCKTAG tag;
403
405 RowExclusiveLock, true));
407 Assert(LockHeldByMe(&tag, AccessShareLock, true));
408#endif
409
411 }
412 else
413 {
416 }
417
418 /* Try finding existing mapping. */
420 ObjectIdGetDatum(relid),
421 ObjectIdGetDatum(subid));
422 if (!HeapTupleIsValid(tup))
423 elog(ERROR, "subscription relation %u in subscription %u does not exist",
424 relid, subid);
425
426 /* Update the tuple. */
427 memset(values, 0, sizeof(values));
428 memset(nulls, false, sizeof(nulls));
429 memset(replaces, false, sizeof(replaces));
430
433
437 else
438 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
439
441 replaces);
442
443 /* Update the catalog. */
444 CatalogTupleUpdate(rel, &tup->t_self, tup);
445
446 /* Cleanup. */
447 table_close(rel, NoLock);
448}
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
Definition lmgr.c:351
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
Definition lock.c:640
#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().