PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
publicationcmds.h File Reference
Include dependency graph for publicationcmds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_RELCACHE_INVAL_MSGS   4096
 

Functions

ObjectAddress CreatePublication (ParseState *pstate, CreatePublicationStmt *stmt)
 
void AlterPublication (ParseState *pstate, AlterPublicationStmt *stmt)
 
void RemovePublicationById (Oid pubid)
 
void RemovePublicationRelById (Oid proid)
 
void RemovePublicationSchemaById (Oid psoid)
 
ObjectAddress AlterPublicationOwner (const char *name, Oid newOwnerId)
 
void AlterPublicationOwner_oid (Oid pubid, Oid newOwnerId)
 
void InvalidatePublicationRels (List *relids)
 
bool pub_rf_contains_invalid_column (Oid pubid, Relation relation, List *ancestors, bool pubviaroot)
 
bool pub_contains_invalid_column (Oid pubid, Relation relation, List *ancestors, bool pubviaroot, char pubgencols_type, bool *invalid_column_list, bool *invalid_gen_col)
 
void InvalidatePubRelSyncCache (Oid pubid, bool puballtables)
 

Macro Definition Documentation

◆ MAX_RELCACHE_INVAL_MSGS

#define MAX_RELCACHE_INVAL_MSGS   4096

Definition at line 23 of file publicationcmds.h.

Function Documentation

◆ AlterPublication()

void AlterPublication ( ParseState pstate,
AlterPublicationStmt stmt 
)

Definition at line 1478 of file publicationcmds.c.

1479{
1480 Relation rel;
1481 HeapTuple tup;
1482 Form_pg_publication pubform;
1483
1484 rel = table_open(PublicationRelationId, RowExclusiveLock);
1485
1486 tup = SearchSysCacheCopy1(PUBLICATIONNAME,
1487 CStringGetDatum(stmt->pubname));
1488
1489 if (!HeapTupleIsValid(tup))
1490 ereport(ERROR,
1491 (errcode(ERRCODE_UNDEFINED_OBJECT),
1492 errmsg("publication \"%s\" does not exist",
1493 stmt->pubname)));
1494
1495 pubform = (Form_pg_publication) GETSTRUCT(tup);
1496
1497 /* must be owner */
1498 if (!object_ownercheck(PublicationRelationId, pubform->oid, GetUserId()))
1500 stmt->pubname);
1501
1502 if (stmt->options)
1503 AlterPublicationOptions(pstate, stmt, rel, tup);
1504 else
1505 {
1506 List *relations = NIL;
1507 List *schemaidlist = NIL;
1508 Oid pubid = pubform->oid;
1509
1510 ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations,
1511 &schemaidlist);
1512
1513 CheckAlterPublication(stmt, tup, relations, schemaidlist);
1514
1515 heap_freetuple(tup);
1516
1517 /* Lock the publication so nobody else can do anything with it. */
1518 LockDatabaseObject(PublicationRelationId, pubid, 0,
1520
1521 /*
1522 * It is possible that by the time we acquire the lock on publication,
1523 * concurrent DDL has removed it. We can test this by checking the
1524 * existence of publication. We get the tuple again to avoid the risk
1525 * of any publication option getting changed.
1526 */
1527 tup = SearchSysCacheCopy1(PUBLICATIONOID, ObjectIdGetDatum(pubid));
1528 if (!HeapTupleIsValid(tup))
1529 ereport(ERROR,
1530 errcode(ERRCODE_UNDEFINED_OBJECT),
1531 errmsg("publication \"%s\" does not exist",
1532 stmt->pubname));
1533
1534 AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext,
1535 schemaidlist != NIL);
1536 AlterPublicationSchemas(stmt, tup, schemaidlist);
1537 }
1538
1539 /* Cleanup. */
1540 heap_freetuple(tup);
1542}
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2639
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4075
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
#define stmt
Definition: indent_codes.h:59
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1002
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:520
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2347
#define NIL
Definition: pg_list.h:68
FormData_pg_publication * Form_pg_publication
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:355
unsigned int Oid
Definition: postgres_ext.h:30
static void AlterPublicationSchemas(AlterPublicationStmt *stmt, HeapTuple tup, List *schemaidlist)
static void ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate, List **rels, List **schemas)
static void CheckAlterPublication(AlterPublicationStmt *stmt, HeapTuple tup, List *tables, List *schemaidlist)
static void AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt, Relation rel, HeapTuple tup)
static void AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup, List *tables, const char *queryString, bool publish_schema)
Definition: pg_list.h:54
const char * p_sourcetext
Definition: parse_node.h:209
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:91
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, AlterPublicationOptions(), AlterPublicationSchemas(), AlterPublicationTables(), CheckAlterPublication(), CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, GETSTRUCT(), GetUserId(), heap_freetuple(), HeapTupleIsValid, LockDatabaseObject(), NIL, object_ownercheck(), OBJECT_PUBLICATION, ObjectIdGetDatum(), ObjectsInPublicationToOids(), ParseState::p_sourcetext, RowExclusiveLock, SearchSysCacheCopy1, stmt, table_close(), and table_open().

Referenced by ProcessUtilitySlow().

◆ AlterPublicationOwner()

ObjectAddress AlterPublicationOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 2053 of file publicationcmds.c.

2054{
2055 Oid pubid;
2056 HeapTuple tup;
2057 Relation rel;
2058 ObjectAddress address;
2059 Form_pg_publication pubform;
2060
2061 rel = table_open(PublicationRelationId, RowExclusiveLock);
2062
2063 tup = SearchSysCacheCopy1(PUBLICATIONNAME, CStringGetDatum(name));
2064
2065 if (!HeapTupleIsValid(tup))
2066 ereport(ERROR,
2067 (errcode(ERRCODE_UNDEFINED_OBJECT),
2068 errmsg("publication \"%s\" does not exist", name)));
2069
2070 pubform = (Form_pg_publication) GETSTRUCT(tup);
2071 pubid = pubform->oid;
2072
2073 AlterPublicationOwner_internal(rel, tup, newOwnerId);
2074
2075 ObjectAddressSet(address, PublicationRelationId, pubid);
2076
2077 heap_freetuple(tup);
2078
2080
2081 return address;
2082}
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
static void AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
const char * name

References AlterPublicationOwner_internal(), CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, name, ObjectAddressSet, RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by ExecAlterOwnerStmt().

◆ AlterPublicationOwner_oid()

void AlterPublicationOwner_oid ( Oid  pubid,
Oid  newOwnerId 
)

Definition at line 2088 of file publicationcmds.c.

2089{
2090 HeapTuple tup;
2091 Relation rel;
2092
2093 rel = table_open(PublicationRelationId, RowExclusiveLock);
2094
2095 tup = SearchSysCacheCopy1(PUBLICATIONOID, ObjectIdGetDatum(pubid));
2096
2097 if (!HeapTupleIsValid(tup))
2098 ereport(ERROR,
2099 (errcode(ERRCODE_UNDEFINED_OBJECT),
2100 errmsg("publication with OID %u does not exist", pubid)));
2101
2102 AlterPublicationOwner_internal(rel, tup, newOwnerId);
2103
2104 heap_freetuple(tup);
2105
2107}

References AlterPublicationOwner_internal(), ereport, errcode(), errmsg(), ERROR, heap_freetuple(), HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by shdepReassignOwned_Owner().

◆ CreatePublication()

ObjectAddress CreatePublication ( ParseState pstate,
CreatePublicationStmt stmt 
)

Definition at line 827 of file publicationcmds.c.

828{
829 Relation rel;
830 ObjectAddress myself;
831 Oid puboid;
832 bool nulls[Natts_pg_publication];
833 Datum values[Natts_pg_publication];
834 HeapTuple tup;
835 bool publish_given;
836 PublicationActions pubactions;
837 bool publish_via_partition_root_given;
838 bool publish_via_partition_root;
839 bool publish_generated_columns_given;
840 char publish_generated_columns;
841 AclResult aclresult;
842 List *relations = NIL;
843 List *schemaidlist = NIL;
844
845 /* must have CREATE privilege on database */
846 aclresult = object_aclcheck(DatabaseRelationId, MyDatabaseId, GetUserId(), ACL_CREATE);
847 if (aclresult != ACLCHECK_OK)
850
851 /* FOR ALL TABLES requires superuser */
852 if (stmt->for_all_tables && !superuser())
854 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
855 errmsg("must be superuser to create FOR ALL TABLES publication")));
856
857 rel = table_open(PublicationRelationId, RowExclusiveLock);
858
859 /* Check if name is used */
860 puboid = GetSysCacheOid1(PUBLICATIONNAME, Anum_pg_publication_oid,
861 CStringGetDatum(stmt->pubname));
862 if (OidIsValid(puboid))
865 errmsg("publication \"%s\" already exists",
866 stmt->pubname)));
867
868 /* Form a tuple. */
869 memset(values, 0, sizeof(values));
870 memset(nulls, false, sizeof(nulls));
871
872 values[Anum_pg_publication_pubname - 1] =
874 values[Anum_pg_publication_pubowner - 1] = ObjectIdGetDatum(GetUserId());
875
877 stmt->options,
878 &publish_given, &pubactions,
879 &publish_via_partition_root_given,
880 &publish_via_partition_root,
881 &publish_generated_columns_given,
882 &publish_generated_columns);
883
884 puboid = GetNewOidWithIndex(rel, PublicationObjectIndexId,
885 Anum_pg_publication_oid);
886 values[Anum_pg_publication_oid - 1] = ObjectIdGetDatum(puboid);
887 values[Anum_pg_publication_puballtables - 1] =
888 BoolGetDatum(stmt->for_all_tables);
889 values[Anum_pg_publication_pubinsert - 1] =
890 BoolGetDatum(pubactions.pubinsert);
891 values[Anum_pg_publication_pubupdate - 1] =
892 BoolGetDatum(pubactions.pubupdate);
893 values[Anum_pg_publication_pubdelete - 1] =
894 BoolGetDatum(pubactions.pubdelete);
895 values[Anum_pg_publication_pubtruncate - 1] =
896 BoolGetDatum(pubactions.pubtruncate);
897 values[Anum_pg_publication_pubviaroot - 1] =
898 BoolGetDatum(publish_via_partition_root);
899 values[Anum_pg_publication_pubgencols - 1] =
900 CharGetDatum(publish_generated_columns);
901
902 tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
903
904 /* Insert tuple into catalog. */
905 CatalogTupleInsert(rel, tup);
906 heap_freetuple(tup);
907
908 recordDependencyOnOwner(PublicationRelationId, puboid, GetUserId());
909
910 ObjectAddressSet(myself, PublicationRelationId, puboid);
911
912 /* Make the changes visible. */
914
915 /* Associate objects with the publication. */
916 if (stmt->for_all_tables)
917 {
918 /* Invalidate relcache so that publication info is rebuilt. */
920 }
921 else
922 {
923 ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations,
924 &schemaidlist);
925
926 /* FOR TABLES IN SCHEMA requires superuser */
927 if (schemaidlist != NIL && !superuser())
929 errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
930 errmsg("must be superuser to create FOR TABLES IN SCHEMA publication"));
931
932 if (relations != NIL)
933 {
934 List *rels;
935
936 rels = OpenTableList(relations);
938 publish_via_partition_root);
939
940 CheckPubRelationColumnList(stmt->pubname, rels,
941 schemaidlist != NIL,
942 publish_via_partition_root);
943
944 PublicationAddTables(puboid, rels, true, NULL);
945 CloseTableList(rels);
946 }
947
948 if (schemaidlist != NIL)
949 {
950 /*
951 * Schema lock is held until the publication is created to prevent
952 * concurrent schema deletion.
953 */
954 LockSchemaList(schemaidlist);
955 PublicationAddSchemas(puboid, schemaidlist, true, NULL);
956 }
957 }
958
960
961 InvokeObjectPostCreateHook(PublicationRelationId, puboid, 0);
962
965 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
966 errmsg("\"wal_level\" is insufficient to publish logical changes"),
967 errhint("Set \"wal_level\" to \"logical\" before creating subscriptions.")));
968
969 return myself;
970}
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3821
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define OidIsValid(objectId)
Definition: c.h:746
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:450
char * get_database_name(Oid dbid)
Definition: dbcommands.c:3188
int errhint(const char *fmt,...)
Definition: elog.c:1318
#define WARNING
Definition: elog.h:36
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:682
Oid MyDatabaseId
Definition: globals.c:95
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
void CacheInvalidateRelcacheAll(void)
Definition: inval.c:1654
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:48
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:173
@ OBJECT_DATABASE
Definition: parsenodes.h:2326
#define ACL_CREATE
Definition: parsenodes.h:85
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:168
uintptr_t Datum
Definition: postgres.h:69
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107
static Datum CharGetDatum(char X)
Definition: postgres.h:127
static void PublicationAddSchemas(Oid pubid, List *schemas, bool if_not_exists, AlterPublicationStmt *stmt)
static void PublicationAddTables(Oid pubid, List *rels, bool if_not_exists, AlterPublicationStmt *stmt)
static void CloseTableList(List *rels)
static void TransformPubWhereClauses(List *tables, const char *queryString, bool pubviaroot)
static List * OpenTableList(List *tables)
static void parse_publication_options(ParseState *pstate, List *options, bool *publish_given, PublicationActions *pubactions, bool *publish_via_partition_root_given, bool *publish_via_partition_root, bool *publish_generated_columns_given, char *publish_generated_columns)
static void CheckPubRelationColumnList(char *pubname, List *tables, bool publish_schema, bool pubviaroot)
static void LockSchemaList(List *schemalist)
#define RelationGetDescr(relation)
Definition: rel.h:542
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:30
bool superuser(void)
Definition: superuser.c:46
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:109
void CommandCounterIncrement(void)
Definition: xact.c:1100
int wal_level
Definition: xlog.c:131
@ WAL_LEVEL_LOGICAL
Definition: xlog.h:76

References ACL_CREATE, aclcheck_error(), ACLCHECK_OK, BoolGetDatum(), CacheInvalidateRelcacheAll(), CatalogTupleInsert(), CharGetDatum(), CheckPubRelationColumnList(), CloseTableList(), CommandCounterIncrement(), CStringGetDatum(), DirectFunctionCall1, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, get_database_name(), GetNewOidWithIndex(), GetSysCacheOid1, GetUserId(), heap_form_tuple(), heap_freetuple(), InvokeObjectPostCreateHook, LockSchemaList(), MyDatabaseId, namein(), NIL, object_aclcheck(), OBJECT_DATABASE, ObjectAddressSet, ObjectIdGetDatum(), ObjectsInPublicationToOids(), OidIsValid, OpenTableList(), ParseState::p_sourcetext, parse_publication_options(), PublicationActions::pubdelete, PublicationActions::pubinsert, PublicationAddSchemas(), PublicationAddTables(), PublicationActions::pubtruncate, PublicationActions::pubupdate, recordDependencyOnOwner(), RelationGetDescr, RowExclusiveLock, stmt, superuser(), table_close(), table_open(), TransformPubWhereClauses(), values, wal_level, WAL_LEVEL_LOGICAL, and WARNING.

Referenced by ProcessUtilitySlow().

◆ InvalidatePublicationRels()

void InvalidatePublicationRels ( List relids)

Definition at line 1173 of file publicationcmds.c.

1174{
1175 /*
1176 * We don't want to send too many individual messages, at some point it's
1177 * cheaper to just reset whole relcache.
1178 */
1180 {
1181 ListCell *lc;
1182
1183 foreach(lc, relids)
1185 }
1186 else
1188}
void CacheInvalidateRelcacheByRelid(Oid relid)
Definition: inval.c:1687
static int list_length(const List *l)
Definition: pg_list.h:152
#define lfirst_oid(lc)
Definition: pg_list.h:174
#define MAX_RELCACHE_INVAL_MSGS

References CacheInvalidateRelcacheAll(), CacheInvalidateRelcacheByRelid(), lfirst_oid, list_length(), and MAX_RELCACHE_INVAL_MSGS.

Referenced by AlterPublicationOptions(), publication_add_relation(), publication_add_schema(), RemovePublicationRelById(), and RemovePublicationSchemaById().

◆ InvalidatePubRelSyncCache()

void InvalidatePubRelSyncCache ( Oid  pubid,
bool  puballtables 
)

Definition at line 501 of file publicationcmds.c.

502{
503 if (puballtables)
504 {
506 }
507 else
508 {
509 List *relids = NIL;
510 List *schemarelids = NIL;
511
512 /*
513 * For partitioned tables, we must invalidate all partitions and
514 * itself. WAL records for INSERT/UPDATE/DELETE specify leaf tables as
515 * a target. However, WAL records for TRUNCATE specify both a root and
516 * its leaves.
517 */
518 relids = GetPublicationRelations(pubid,
520 schemarelids = GetAllSchemaPublicationRelations(pubid,
522
523 relids = list_concat_unique_oid(relids, schemarelids);
524
525 /* Invalidate the relsyncache */
526 foreach_oid(relid, relids)
528 }
529
530 return;
531}
void CacheInvalidateRelSyncAll(void)
Definition: inval.c:1720
void CacheInvalidateRelSync(Oid relid)
Definition: inval.c:1708
List * list_concat_unique_oid(List *list1, const List *list2)
Definition: list.c:1469
#define foreach_oid(var, lst)
Definition: pg_list.h:471
List * GetAllSchemaPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
List * GetPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
@ PUBLICATION_PART_ALL

References CacheInvalidateRelSync(), CacheInvalidateRelSyncAll(), foreach_oid, GetAllSchemaPublicationRelations(), GetPublicationRelations(), list_concat_unique_oid(), NIL, and PUBLICATION_PART_ALL.

Referenced by AlterObjectRename_internal().

◆ pub_contains_invalid_column()

bool pub_contains_invalid_column ( Oid  pubid,
Relation  relation,
List ancestors,
bool  pubviaroot,
char  pubgencols_type,
bool *  invalid_column_list,
bool *  invalid_gen_col 
)

Definition at line 357 of file publicationcmds.c.

361{
362 Oid relid = RelationGetRelid(relation);
363 Oid publish_as_relid = RelationGetRelid(relation);
364 Bitmapset *idattrs;
365 Bitmapset *columns = NULL;
366 TupleDesc desc = RelationGetDescr(relation);
367 Publication *pub;
368 int x;
369
370 *invalid_column_list = false;
371 *invalid_gen_col = false;
372
373 /*
374 * For a partition, if pubviaroot is true, find the topmost ancestor that
375 * is published via this publication as we need to use its column list for
376 * the changes.
377 *
378 * Note that even though the column list used is for an ancestor, the
379 * REPLICA IDENTITY used will be for the actual child table.
380 */
381 if (pubviaroot && relation->rd_rel->relispartition)
382 {
383 publish_as_relid = GetTopMostAncestorInPublication(pubid, ancestors, NULL);
384
385 if (!OidIsValid(publish_as_relid))
386 publish_as_relid = relid;
387 }
388
389 /* Fetch the column list */
390 pub = GetPublication(pubid);
391 check_and_fetch_column_list(pub, publish_as_relid, NULL, &columns);
392
393 if (relation->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
394 {
395 /* With REPLICA IDENTITY FULL, no column list is allowed. */
396 *invalid_column_list = (columns != NULL);
397
398 /*
399 * As we don't allow a column list with REPLICA IDENTITY FULL, the
400 * publish_generated_columns option must be set to stored if the table
401 * has any stored generated columns.
402 */
403 if (pubgencols_type != PUBLISH_GENCOLS_STORED &&
404 relation->rd_att->constr &&
406 *invalid_gen_col = true;
407
408 /*
409 * Virtual generated columns are currently not supported for logical
410 * replication at all.
411 */
412 if (relation->rd_att->constr &&
414 *invalid_gen_col = true;
415
416 if (*invalid_gen_col && *invalid_column_list)
417 return true;
418 }
419
420 /* Remember columns that are part of the REPLICA IDENTITY */
421 idattrs = RelationGetIndexAttrBitmap(relation,
423
424 /*
425 * Attnums in the bitmap returned by RelationGetIndexAttrBitmap are offset
426 * (to handle system columns the usual way), while column list does not
427 * use offset, so we can't do bms_is_subset(). Instead, we have to loop
428 * over the idattrs and check all of them are in the list.
429 */
430 x = -1;
431 while ((x = bms_next_member(idattrs, x)) >= 0)
432 {
434 Form_pg_attribute att = TupleDescAttr(desc, attnum - 1);
435
436 if (columns == NULL)
437 {
438 /*
439 * The publish_generated_columns option must be set to stored if
440 * the REPLICA IDENTITY contains any stored generated column.
441 */
442 if (att->attgenerated == ATTRIBUTE_GENERATED_STORED && pubgencols_type != PUBLISH_GENCOLS_STORED)
443 {
444 *invalid_gen_col = true;
445 break;
446 }
447
448 /*
449 * The equivalent setting for virtual generated columns does not
450 * exist yet.
451 */
452 if (att->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
453 {
454 *invalid_gen_col = true;
455 break;
456 }
457
458 /* Skip validating the column list since it is not defined */
459 continue;
460 }
461
462 /*
463 * If pubviaroot is true, we are validating the column list of the
464 * parent table, but the bitmap contains the replica identity
465 * information of the child table. The parent/child attnums may not
466 * match, so translate them to the parent - get the attname from the
467 * child, and look it up in the parent.
468 */
469 if (pubviaroot)
470 {
471 /* attribute name in the child table */
472 char *colname = get_attname(relid, attnum, false);
473
474 /*
475 * Determine the attnum for the attribute name in parent (we are
476 * using the column list defined on the parent).
477 */
478 attnum = get_attnum(publish_as_relid, colname);
479 }
480
481 /* replica identity column, not covered by the column list */
482 *invalid_column_list |= !bms_is_member(attnum, columns);
483
484 if (*invalid_column_list && *invalid_gen_col)
485 break;
486 }
487
488 bms_free(columns);
489 bms_free(idattrs);
490
491 return *invalid_column_list || *invalid_gen_col;
492}
int16 AttrNumber
Definition: attnum.h:21
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1306
void bms_free(Bitmapset *a)
Definition: bitmapset.c:239
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
int x
Definition: isn.c:75
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:950
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:919
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
Oid GetTopMostAncestorInPublication(Oid puboid, List *ancestors, int *ancestor_level)
Publication * GetPublication(Oid pubid)
bool check_and_fetch_column_list(Publication *pub, Oid relid, MemoryContext mcxt, Bitmapset **cols)
#define RelationGetRelid(relation)
Definition: rel.h:516
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:5300
@ INDEX_ATTR_BITMAP_IDENTITY_KEY
Definition: relcache.h:71
TupleDesc rd_att
Definition: rel.h:112
Form_pg_class rd_rel
Definition: rel.h:111
bool has_generated_virtual
Definition: tupdesc.h:47
bool has_generated_stored
Definition: tupdesc.h:46
TupleConstr * constr
Definition: tupdesc.h:141
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160

References attnum, bms_free(), bms_is_member(), bms_next_member(), check_and_fetch_column_list(), TupleDescData::constr, FirstLowInvalidHeapAttributeNumber, get_attname(), get_attnum(), GetPublication(), GetTopMostAncestorInPublication(), TupleConstr::has_generated_stored, TupleConstr::has_generated_virtual, INDEX_ATTR_BITMAP_IDENTITY_KEY, OidIsValid, RelationData::rd_att, RelationData::rd_rel, RelationGetDescr, RelationGetIndexAttrBitmap(), RelationGetRelid, TupleDescAttr(), and x.

Referenced by RelationBuildPublicationDesc().

◆ pub_rf_contains_invalid_column()

bool pub_rf_contains_invalid_column ( Oid  pubid,
Relation  relation,
List ancestors,
bool  pubviaroot 
)

Definition at line 271 of file publicationcmds.c.

273{
274 HeapTuple rftuple;
275 Oid relid = RelationGetRelid(relation);
276 Oid publish_as_relid = RelationGetRelid(relation);
277 bool result = false;
278 Datum rfdatum;
279 bool rfisnull;
280
281 /*
282 * FULL means all columns are in the REPLICA IDENTITY, so all columns are
283 * allowed in the row filter and we can skip the validation.
284 */
285 if (relation->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
286 return false;
287
288 /*
289 * For a partition, if pubviaroot is true, find the topmost ancestor that
290 * is published via this publication as we need to use its row filter
291 * expression to filter the partition's changes.
292 *
293 * Note that even though the row filter used is for an ancestor, the
294 * REPLICA IDENTITY used will be for the actual child table.
295 */
296 if (pubviaroot && relation->rd_rel->relispartition)
297 {
298 publish_as_relid
299 = GetTopMostAncestorInPublication(pubid, ancestors, NULL);
300
301 if (!OidIsValid(publish_as_relid))
302 publish_as_relid = relid;
303 }
304
305 rftuple = SearchSysCache2(PUBLICATIONRELMAP,
306 ObjectIdGetDatum(publish_as_relid),
307 ObjectIdGetDatum(pubid));
308
309 if (!HeapTupleIsValid(rftuple))
310 return false;
311
312 rfdatum = SysCacheGetAttr(PUBLICATIONRELMAP, rftuple,
313 Anum_pg_publication_rel_prqual,
314 &rfisnull);
315
316 if (!rfisnull)
317 {
318 rf_context context = {0};
319 Node *rfnode;
320 Bitmapset *bms = NULL;
321
322 context.pubviaroot = pubviaroot;
323 context.parentid = publish_as_relid;
324 context.relid = relid;
325
326 /* Remember columns that are part of the REPLICA IDENTITY */
327 bms = RelationGetIndexAttrBitmap(relation,
329
330 context.bms_replident = bms;
331 rfnode = stringToNode(TextDatumGetCString(rfdatum));
332 result = contain_invalid_rfcolumn_walker(rfnode, &context);
333 }
334
335 ReleaseSysCache(rftuple);
336
337 return result;
338}
#define TextDatumGetCString(d)
Definition: builtins.h:98
static bool contain_invalid_rfcolumn_walker(Node *node, rf_context *context)
void * stringToNode(const char *str)
Definition: read.c:90
Definition: nodes.h:135
Bitmapset * bms_replident
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:600
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:232

References rf_context::bms_replident, contain_invalid_rfcolumn_walker(), GetTopMostAncestorInPublication(), HeapTupleIsValid, INDEX_ATTR_BITMAP_IDENTITY_KEY, ObjectIdGetDatum(), OidIsValid, rf_context::parentid, rf_context::pubviaroot, RelationData::rd_rel, RelationGetIndexAttrBitmap(), RelationGetRelid, ReleaseSysCache(), rf_context::relid, SearchSysCache2(), stringToNode(), SysCacheGetAttr(), and TextDatumGetCString.

Referenced by RelationBuildPublicationDesc().

◆ RemovePublicationById()

void RemovePublicationById ( Oid  pubid)

Definition at line 1589 of file publicationcmds.c.

1590{
1591 Relation rel;
1592 HeapTuple tup;
1593 Form_pg_publication pubform;
1594
1595 rel = table_open(PublicationRelationId, RowExclusiveLock);
1596
1597 tup = SearchSysCache1(PUBLICATIONOID, ObjectIdGetDatum(pubid));
1598 if (!HeapTupleIsValid(tup))
1599 elog(ERROR, "cache lookup failed for publication %u", pubid);
1600
1601 pubform = (Form_pg_publication) GETSTRUCT(tup);
1602
1603 /* Invalidate relcache so that publication info is rebuilt. */
1604 if (pubform->puballtables)
1606
1607 CatalogTupleDelete(rel, &tup->t_self);
1608
1609 ReleaseSysCache(tup);
1610
1612}
#define elog(elevel,...)
Definition: elog.h:225
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:365
ItemPointerData t_self
Definition: htup.h:65
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References CacheInvalidateRelcacheAll(), CatalogTupleDelete(), elog, ERROR, GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

◆ RemovePublicationRelById()

void RemovePublicationRelById ( Oid  proid)

Definition at line 1548 of file publicationcmds.c.

1549{
1550 Relation rel;
1551 HeapTuple tup;
1553 List *relids = NIL;
1554
1555 rel = table_open(PublicationRelRelationId, RowExclusiveLock);
1556
1557 tup = SearchSysCache1(PUBLICATIONREL, ObjectIdGetDatum(proid));
1558
1559 if (!HeapTupleIsValid(tup))
1560 elog(ERROR, "cache lookup failed for publication table %u",
1561 proid);
1562
1563 pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
1564
1565 /*
1566 * Invalidate relcache so that publication info is rebuilt.
1567 *
1568 * For the partitioned tables, we must invalidate all partitions contained
1569 * in the respective partition hierarchies, not just the one explicitly
1570 * mentioned in the publication. This is required because we implicitly
1571 * publish the child tables when the parent table is published.
1572 */
1574 pubrel->prrelid);
1575
1577
1578 CatalogTupleDelete(rel, &tup->t_self);
1579
1580 ReleaseSysCache(tup);
1581
1583}
List * GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt, Oid relid)
FormData_pg_publication_rel * Form_pg_publication_rel
void InvalidatePublicationRels(List *relids)

References CatalogTupleDelete(), elog, ERROR, GetPubPartitionOptionRelations(), GETSTRUCT(), HeapTupleIsValid, InvalidatePublicationRels(), NIL, ObjectIdGetDatum(), PUBLICATION_PART_ALL, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

◆ RemovePublicationSchemaById()

void RemovePublicationSchemaById ( Oid  psoid)

Definition at line 1618 of file publicationcmds.c.

1619{
1620 Relation rel;
1621 HeapTuple tup;
1622 List *schemaRels = NIL;
1624
1625 rel = table_open(PublicationNamespaceRelationId, RowExclusiveLock);
1626
1627 tup = SearchSysCache1(PUBLICATIONNAMESPACE, ObjectIdGetDatum(psoid));
1628
1629 if (!HeapTupleIsValid(tup))
1630 elog(ERROR, "cache lookup failed for publication schema %u", psoid);
1631
1633
1634 /*
1635 * Invalidate relcache so that publication info is rebuilt. See
1636 * RemovePublicationRelById for why we need to consider all the
1637 * partitions.
1638 */
1639 schemaRels = GetSchemaPublicationRelations(pubsch->pnnspid,
1641 InvalidatePublicationRels(schemaRels);
1642
1643 CatalogTupleDelete(rel, &tup->t_self);
1644
1645 ReleaseSysCache(tup);
1646
1648}
List * GetSchemaPublicationRelations(Oid schemaid, PublicationPartOpt pub_partopt)
FormData_pg_publication_namespace * Form_pg_publication_namespace

References CatalogTupleDelete(), elog, ERROR, GetSchemaPublicationRelations(), GETSTRUCT(), HeapTupleIsValid, InvalidatePublicationRels(), NIL, ObjectIdGetDatum(), PUBLICATION_PART_ALL, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().