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

312{
313 Relation rel;
315 bool nulls[Natts_pg_subscription_rel];
317
319
321
322 /* Try finding existing mapping. */
324 ObjectIdGetDatum(relid),
325 ObjectIdGetDatum(subid));
327 elog(ERROR, "subscription relation %u in subscription %u already exists",
328 relid, subid);
329
330 /* Form the tuple. */
331 memset(values, 0, sizeof(values));
332 memset(nulls, false, sizeof(nulls));
338 else
339 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
340
342
343 /* Insert tuple into catalog. */
345
347
348 /* Cleanup. */
349 if (retain_lock)
350 {
351 table_close(rel, NoLock);
352 }
353 else
354 {
357 }
358}
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 211 of file pg_subscription.c.

212{
213 int nsubs = 0;
214 Relation rel;
216 SysScanDesc scan;
218
220
224 ObjectIdGetDatum(dbid));
225
226 scan = systable_beginscan(rel, InvalidOid, false,
227 NULL, 1, &scankey);
228
229 while (HeapTupleIsValid(tup = systable_getnext(scan)))
230 nsubs++;
231
232 systable_endscan(scan);
233
234 table_close(rel, NoLock);
235
236 return nsubs;
237}
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 243 of file pg_subscription.c.

244{
245 Relation rel;
246 bool nulls[Natts_pg_subscription];
250
251 /* Look up the subscription in the catalog */
254
255 if (!HeapTupleIsValid(tup))
256 elog(ERROR, "cache lookup failed for subscription %u", subid);
257
259
260 /* Form a new tuple. */
261 memset(values, 0, sizeof(values));
262 memset(nulls, false, sizeof(nulls));
263 memset(replaces, false, sizeof(replaces));
264
265 /* Set the subscription to disabled. */
268
269 /* Update the catalog */
271 replaces);
272 CatalogTupleUpdate(rel, &tup->t_self, tup);
274
275 table_close(rel, NoLock);
276}
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:943
#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(), 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 83 of file pg_subscription.c.

84{
86 Subscription *sub;
88 Datum datum;
89 bool isnull;
90 MemoryContext cxt;
92
94
96 {
97 if (missing_ok)
98 return NULL;
99
100 elog(ERROR, "cache lookup failed for subscription %u", subid);
101 }
102
103 cxt = AllocSetContextCreate(CurrentMemoryContext, "subscription",
106
108
110 sub->cxt = cxt;
111 sub->oid = subid;
112 sub->dbid = subform->subdbid;
113 sub->skiplsn = subform->subskiplsn;
114 sub->name = pstrdup(NameStr(subform->subname));
115 sub->owner = subform->subowner;
116 sub->enabled = subform->subenabled;
117 sub->binary = subform->subbinary;
118 sub->stream = subform->substream;
119 sub->twophasestate = subform->subtwophasestate;
120 sub->disableonerr = subform->subdisableonerr;
121 sub->passwordrequired = subform->subpasswordrequired;
122 sub->runasowner = subform->subrunasowner;
123 sub->failover = subform->subfailover;
124 sub->retaindeadtuples = subform->subretaindeadtuples;
125 sub->maxretention = subform->submaxretention;
126 sub->retentionactive = subform->subretentionactive;
127
128 /* Get conninfo */
129 if (OidIsValid(subform->subserver))
130 {
132 ForeignServer *server;
133
134 server = GetForeignServer(subform->subserver);
135
136 /* recheck ACL if requested */
137 if (aclcheck)
138 {
140 subform->subserver,
141 subform->subowner, ACL_USAGE);
142
143 if (aclresult != ACLCHECK_OK)
146 errmsg("subscription owner \"%s\" does not have permission on foreign server \"%s\"",
147 GetUserNameFromId(subform->subowner, false),
148 server->servername)));
149 }
150
152 server);
153 }
154 else
155 {
157 tup,
159 sub->conninfo = TextDatumGetCString(datum);
160 }
161
162 /* Get slotname */
164 tup,
166 &isnull);
167 if (!isnull)
168 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
169 else
170 sub->slotname = NULL;
171
172 /* Get synccommit */
174 tup,
176 sub->synccommit = TextDatumGetCString(datum);
177
178 /* Get walrcvtimeout */
180 tup,
183
184 /* Get publications */
186 tup,
189
190 /* Get origin */
192 tup,
194 sub->origin = TextDatumGetCString(datum);
195
196 /* Is the subscription owner a superuser? */
198
200
202
203 return sub;
204}
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:3880
#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:875
#define ereport(elevel,...)
Definition elog.h:152
#define palloc_object(type)
Definition fe_memutils.h:89
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, 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 608 of file pg_subscription.c.

610{
611 List *res = NIL;
612 Relation rel;
614 int nkeys = 0;
615 ScanKeyData skey[2];
616 SysScanDesc scan;
617
618 /* One or both of 'tables' and 'sequences' must be true. */
619 Assert(tables || sequences);
620
622
623 ScanKeyInit(&skey[nkeys++],
626 ObjectIdGetDatum(subid));
627
628 if (not_ready)
629 ScanKeyInit(&skey[nkeys++],
633
634 scan = systable_beginscan(rel, InvalidOid, false,
635 NULL, nkeys, skey);
636
637 while (HeapTupleIsValid(tup = systable_getnext(scan)))
638 {
640 SubscriptionRelState *relstate;
641 Datum d;
642 bool isnull;
643 char relkind;
644
646
647 /* Relation is either a sequence or a table */
648 relkind = get_rel_relkind(subrel->srrelid);
649 Assert(relkind == RELKIND_SEQUENCE || relkind == RELKIND_RELATION ||
650 relkind == RELKIND_PARTITIONED_TABLE);
651
652 /* Skip sequences if they were not requested */
653 if ((relkind == RELKIND_SEQUENCE) && !sequences)
654 continue;
655
656 /* Skip tables if they were not requested */
657 if ((relkind == RELKIND_RELATION ||
658 relkind == RELKIND_PARTITIONED_TABLE) && !tables)
659 continue;
660
662 relstate->relid = subrel->srrelid;
663 relstate->state = subrel->srsubstate;
666 if (isnull)
667 relstate->lsn = InvalidXLogRecPtr;
668 else
669 relstate->lsn = DatumGetLSN(d);
670
671 res = lappend(res, relstate);
672 }
673
674 /* Cleanup */
675 systable_endscan(scan);
677
678 return res;
679}
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 430 of file pg_subscription.c.

431{
433 char substate;
434 bool isnull;
435 Datum d;
436 Relation rel;
437
438 /*
439 * This is to avoid the race condition with AlterSubscription which tries
440 * to remove this relstate.
441 */
443
444 /* Try finding the mapping. */
446 ObjectIdGetDatum(relid),
447 ObjectIdGetDatum(subid));
448
449 if (!HeapTupleIsValid(tup))
450 {
454 }
455
456 /* Get the state. */
458
459 /* Get the LSN */
462 if (isnull)
464 else
465 *sublsn = DatumGetLSN(d);
466
467 /* Cleanup */
469
471
472 return substate;
473}
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 559 of file pg_subscription.c.

560{
561 Relation rel;
562 ScanKeyData skey[1];
563 SysScanDesc scan;
565 bool has_subtables = false;
566
568
569 ScanKeyInit(&skey[0],
572 ObjectIdGetDatum(subid));
573
574 scan = systable_beginscan(rel, InvalidOid, false,
575 NULL, 1, skey);
576
577 while (HeapTupleIsValid(tup = systable_getnext(scan)))
578 {
580 char relkind;
581
583 relkind = get_rel_relkind(subrel->srrelid);
584
585 if (relkind == RELKIND_RELATION ||
586 relkind == RELKIND_PARTITIONED_TABLE)
587 {
588 has_subtables = true;
589 break;
590 }
591 }
592
593 /* Cleanup */
594 systable_endscan(scan);
596
597 return has_subtables;
598}

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

481{
482 Relation rel;
483 TableScanDesc scan;
484 ScanKeyData skey[2];
486 int nkeys = 0;
487
489
490 if (OidIsValid(subid))
491 {
492 ScanKeyInit(&skey[nkeys++],
495 F_OIDEQ,
496 ObjectIdGetDatum(subid));
497 }
498
499 if (OidIsValid(relid))
500 {
501 ScanKeyInit(&skey[nkeys++],
504 F_OIDEQ,
505 ObjectIdGetDatum(relid));
506 }
507
508 /* Do the search and delete what we found. */
509 scan = table_beginscan_catalog(rel, nkeys, skey);
511 {
513
515
516 /*
517 * We don't allow to drop the relation mapping when the table
518 * synchronization is in progress unless the caller updates the
519 * corresponding subscription as well. This is to ensure that we don't
520 * leave tablesync slots or origins in the system when the
521 * corresponding table is dropped. For sequences, however, it's ok to
522 * drop them since no separate slots or origins are created during
523 * synchronization.
524 */
525 if (!OidIsValid(subid) &&
526 subrel->srsubstate != SUBREL_STATE_READY &&
528 {
531 errmsg("could not drop relation mapping for subscription \"%s\"",
532 get_subscription_name(subrel->srsubid, false)),
533 errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
534 get_rel_name(relid), subrel->srsubstate),
535
536 /*
537 * translator: first %s is a SQL ALTER command and second %s is a
538 * SQL DROP command
539 */
540 errhint("Use %s to enable subscription if not already enabled or use %s to drop the subscription.",
541 "ALTER SUBSCRIPTION ... ENABLE",
542 "DROP SUBSCRIPTION ...")));
543 }
544
545 CatalogTupleDelete(rel, &tup->t_self);
546 }
547 table_endscan(scan);
548
550}
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 284 of file pg_subscription.c.

285{
286 Datum *elems;
287 int nelems,
288 i;
289 List *res = NIL;
290
292
293 if (nelems == 0)
294 return NIL;
295
296 for (i = 0; i < nelems; i++)
297 res = lappend(res, makeString(TextDatumGetCString(elems[i])));
298
299 return res;
300}
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 685 of file pg_subscription.c.

686{
687 Relation rel;
688 bool nulls[Natts_pg_subscription];
692
693 /* Look up the subscription in the catalog */
696
697 if (!HeapTupleIsValid(tup))
698 elog(ERROR, "cache lookup failed for subscription %u", subid);
699
701
702 /* Form a new tuple. */
703 memset(values, 0, sizeof(values));
704 memset(nulls, false, sizeof(nulls));
705 memset(replaces, false, sizeof(replaces));
706
707 /* Set the subscription to disabled. */
710
711 /* Update the catalog */
713 replaces);
714 CatalogTupleUpdate(rel, &tup->t_self, tup);
716
717 table_close(rel, NoLock);
718}

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

366{
367 Relation rel;
369 bool nulls[Natts_pg_subscription_rel];
372
373 if (already_locked)
374 {
375#ifdef USE_ASSERT_CHECKING
376 LOCKTAG tag;
377
379 RowExclusiveLock, true));
381 Assert(LockHeldByMe(&tag, AccessShareLock, true));
382#endif
383
385 }
386 else
387 {
390 }
391
392 /* Try finding existing mapping. */
394 ObjectIdGetDatum(relid),
395 ObjectIdGetDatum(subid));
396 if (!HeapTupleIsValid(tup))
397 elog(ERROR, "subscription relation %u in subscription %u does not exist",
398 relid, subid);
399
400 /* Update the tuple. */
401 memset(values, 0, sizeof(values));
402 memset(nulls, false, sizeof(nulls));
403 memset(replaces, false, sizeof(replaces));
404
407
411 else
412 nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
413
415 replaces);
416
417 /* Update the catalog. */
418 CatalogTupleUpdate(rel, &tup->t_self, tup);
419
420 /* Cleanup. */
421 table_close(rel, NoLock);
422}
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().