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

329{
330 Relation rel;
332 bool nulls[Natts_pg_subscription_rel];
334
336
338
339 /* Try finding existing mapping. */
341 ObjectIdGetDatum(relid),
342 ObjectIdGetDatum(subid));
344 elog(ERROR, "subscription relation %u in subscription %u already exists",
345 relid, subid);
346
347 /* Form the tuple. */
348 memset(values, 0, sizeof(values));
349 memset(nulls, false, sizeof(nulls));
355 else
356 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
357
359
360 /* Insert tuple into catalog. */
362
364
365 /* Cleanup. */
366 if (retain_lock)
367 {
368 table_close(rel, NoLock);
369 }
370 else
371 {
374 }
375}
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 228 of file pg_subscription.c.

229{
230 int nsubs = 0;
231 Relation rel;
233 SysScanDesc scan;
235
237
241 ObjectIdGetDatum(dbid));
242
243 scan = systable_beginscan(rel, InvalidOid, false,
244 NULL, 1, &scankey);
245
246 while (HeapTupleIsValid(tup = systable_getnext(scan)))
247 nsubs++;
248
249 systable_endscan(scan);
250
251 table_close(rel, NoLock);
252
253 return nsubs;
254}
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 260 of file pg_subscription.c.

261{
262 Relation rel;
263 bool nulls[Natts_pg_subscription];
267
268 /* Look up the subscription in the catalog */
271
272 if (!HeapTupleIsValid(tup))
273 elog(ERROR, "cache lookup failed for subscription %u", subid);
274
276
277 /* Form a new tuple. */
278 memset(values, 0, sizeof(values));
279 memset(nulls, false, sizeof(nulls));
280 memset(replaces, false, sizeof(replaces));
281
282 /* Set the subscription to disabled. */
285
286 /* Update the catalog */
288 replaces);
289 CatalogTupleUpdate(rel, &tup->t_self, tup);
291
292 table_close(rel, NoLock);
293}
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 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 Assert(condition)
Definition c.h:1002
#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
118 sub->cxt = cxt;
119 sub->oid = subid;
120 sub->dbid = subform->subdbid;
121 sub->skiplsn = subform->subskiplsn;
122 sub->name = pstrdup(NameStr(subform->subname));
123 sub->owner = subform->subowner;
124 sub->enabled = subform->subenabled;
125 sub->binary = subform->subbinary;
126 sub->stream = subform->substream;
127 sub->twophasestate = subform->subtwophasestate;
128 sub->disableonerr = subform->subdisableonerr;
129 sub->passwordrequired = subform->subpasswordrequired;
130 sub->runasowner = subform->subrunasowner;
131 sub->failover = subform->subfailover;
132 sub->retaindeadtuples = subform->subretaindeadtuples;
133 sub->maxretention = subform->submaxretention;
134 sub->retentionactive = subform->subretentionactive;
135 sub->conflictlogrelid = subform->subconflictlogrelid;
136
137 if (conninfo_needed)
138 {
139 if (OidIsValid(subform->subserver))
140 {
142 ForeignServer *server;
143
144 server = GetForeignServer(subform->subserver);
145
147 {
148 /* recheck ACL if requested */
150 subform->subserver,
151 subform->subowner, ACL_USAGE);
152
153 if (aclresult != ACLCHECK_OK)
156 errmsg("subscription owner \"%s\" does not have permission on foreign server \"%s\"",
157 GetUserNameFromId(subform->subowner, false),
158 server->servername)));
159 }
160
162 server);
163 }
164 else
165 {
167 tup,
169 sub->conninfo = TextDatumGetCString(datum);
170 }
171 }
172
173 /* Get slotname */
175 tup,
177 &isnull);
178 if (!isnull)
179 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
180 else
181 sub->slotname = NULL;
182
183 /* Get synccommit */
185 tup,
187 sub->synccommit = TextDatumGetCString(datum);
188
189 /* Get walrcvtimeout */
191 tup,
194
195 /* Get publications */
197 tup,
200
201 /* Get origin */
203 tup,
205 sub->origin = TextDatumGetCString(datum);
206
207 /* Get conflict log destination */
209 tup,
212
213 /* Is the subscription owner a superuser? */
215
217
219
220 return sub;
221}
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
static void * GETSTRUCT(const HeapTupleData *tuple)
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)
END_CATALOG_STRUCT typedef FormData_pg_subscription * Form_pg_subscription
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(), 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 625 of file pg_subscription.c.

627{
628 List *res = NIL;
629 Relation rel;
631 int nkeys = 0;
632 ScanKeyData skey[2];
633 SysScanDesc scan;
634
635 /* One or both of 'tables' and 'sequences' must be true. */
636 Assert(tables || sequences);
637
639
640 ScanKeyInit(&skey[nkeys++],
643 ObjectIdGetDatum(subid));
644
645 if (not_ready)
646 ScanKeyInit(&skey[nkeys++],
650
651 scan = systable_beginscan(rel, InvalidOid, false,
652 NULL, nkeys, skey);
653
654 while (HeapTupleIsValid(tup = systable_getnext(scan)))
655 {
657 SubscriptionRelState *relstate;
658 Datum d;
659 bool isnull;
660 char relkind;
661
663
664 /* Relation is either a sequence or a table */
665 relkind = get_rel_relkind(subrel->srrelid);
666 Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
667 relkind == RELKIND_PARTITIONED_TABLE);
668
669 /* Skip sequences if they were not requested */
670 if ((relkind == RELKIND_SEQUENCE) && !sequences)
671 continue;
672
673 /* Skip tables if they were not requested */
674 if ((relkind == RELKIND_RELATION ||
675 relkind == RELKIND_PARTITIONED_TABLE) && !tables)
676 continue;
677
679 relstate->relid = subrel->srrelid;
680 relstate->state = subrel->srsubstate;
683 if (isnull)
684 relstate->lsn = InvalidXLogRecPtr;
685 else
686 relstate->lsn = DatumGetLSN(d);
687
688 res = lappend(res, relstate);
689 }
690
691 /* Cleanup */
692 systable_endscan(scan);
694
695 return res;
696}
#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:2309
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 447 of file pg_subscription.c.

448{
450 char substate;
451 bool isnull;
452 Datum d;
453 Relation rel;
454
455 /*
456 * This is to avoid the race condition with AlterSubscription which tries
457 * to remove this relstate.
458 */
460
461 /* Try finding the mapping. */
463 ObjectIdGetDatum(relid),
464 ObjectIdGetDatum(subid));
465
466 if (!HeapTupleIsValid(tup))
467 {
471 }
472
473 /* Get the state. */
475
476 /* Get the LSN */
479 if (isnull)
481 else
482 *sublsn = DatumGetLSN(d);
483
484 /* Cleanup */
486
488
489 return substate;
490}
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 576 of file pg_subscription.c.

577{
578 Relation rel;
579 ScanKeyData skey[1];
580 SysScanDesc scan;
582 bool has_subtables = false;
583
585
586 ScanKeyInit(&skey[0],
589 ObjectIdGetDatum(subid));
590
591 scan = systable_beginscan(rel, InvalidOid, false,
592 NULL, 1, skey);
593
594 while (HeapTupleIsValid(tup = systable_getnext(scan)))
595 {
597 char relkind;
598
600 relkind = get_rel_relkind(subrel->srrelid);
601
602 if (relkind == RELKIND_RELATION ||
603 relkind == RELKIND_PARTITIONED_TABLE)
604 {
605 has_subtables = true;
606 break;
607 }
608 }
609
610 /* Cleanup */
611 systable_endscan(scan);
613
614 return has_subtables;
615}

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

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

302{
303 Datum *elems;
304 int nelems,
305 i;
306 List *res = NIL;
307
309
310 if (nelems == 0)
311 return NIL;
312
313 for (i = 0; i < nelems; i++)
314 res = lappend(res, makeString(TextDatumGetCString(elems[i])));
315
316 return res;
317}
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 702 of file pg_subscription.c.

703{
704 Relation rel;
705 bool nulls[Natts_pg_subscription];
709
710 /* Look up the subscription in the catalog */
713
714 if (!HeapTupleIsValid(tup))
715 elog(ERROR, "cache lookup failed for subscription %u", subid);
716
718
719 /* Form a new tuple. */
720 memset(values, 0, sizeof(values));
721 memset(nulls, false, sizeof(nulls));
722 memset(replaces, false, sizeof(replaces));
723
724 /* Set the subscription to disabled. */
727
728 /* Update the catalog */
730 replaces);
731 CatalogTupleUpdate(rel, &tup->t_self, tup);
733
734 table_close(rel, NoLock);
735}

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 update_retention_status().

◆ UpdateSubscriptionRelState()

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

Definition at line 381 of file pg_subscription.c.

383{
384 Relation rel;
386 bool nulls[Natts_pg_subscription_rel];
389
390 if (already_locked)
391 {
392#ifdef USE_ASSERT_CHECKING
393 LOCKTAG tag;
394
396 RowExclusiveLock, true));
398 Assert(LockHeldByMe(&tag, AccessShareLock, true));
399#endif
400
402 }
403 else
404 {
407 }
408
409 /* Try finding existing mapping. */
411 ObjectIdGetDatum(relid),
412 ObjectIdGetDatum(subid));
413 if (!HeapTupleIsValid(tup))
414 elog(ERROR, "subscription relation %u in subscription %u does not exist",
415 relid, subid);
416
417 /* Update the tuple. */
418 memset(values, 0, sizeof(values));
419 memset(nulls, false, sizeof(nulls));
420 memset(replaces, false, sizeof(replaces));
421
424
428 else
429 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
430
432 replaces);
433
434 /* Update the catalog. */
435 CatalogTupleUpdate(rel, &tup->t_self, tup);
436
437 /* Cleanup. */
438 table_close(rel, NoLock);
439}
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().