38 #include "utils/fmgroids.h"
62 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
63 errmsg(
"cannot add relation \"%s\" to publication",
70 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
71 errmsg(
"cannot add relation \"%s\" to publication",
73 errdetail(
"This operation is not supported for system tables.")));
76 if (targetrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
78 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
79 errmsg(
"cannot add relation \"%s\" to publication",
81 errdetail(
"This operation is not supported for temporary tables.")));
82 else if (targetrel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
84 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
85 errmsg(
"cannot add relation \"%s\" to publication",
87 errdetail(
"This operation is not supported for unlogged tables.")));
100 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
101 errmsg(
"cannot add schema \"%s\" to publication",
103 errdetail(
"This operation is not supported for system schemas.")));
108 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
109 errmsg(
"cannot add schema \"%s\" to publication",
111 errdetail(
"Temporary schemas cannot be replicated.")));
136 return (reltuple->relkind == RELKIND_RELATION ||
137 reltuple->relkind == RELKIND_PARTITIONED_TABLE) &&
139 reltuple->relpersistence == RELPERSISTENCE_PERMANENT &&
183 foreach(lc, table_infos)
187 if (relid == ancestor)
202 foreach(lc, table_infos)
212 foreach(lc2, ancestors)
243 Anum_pg_publication_namespace_pnpubid,
248 PublicationNamespacePnnspidPnpubidIndexId,
249 true, NULL, 1, &scankey);
287 Anum_pg_publication_rel_prattrs, &isnull);
325 foreach(lc, all_parts)
363 foreach(lc, ancestors)
373 topmost_relid = ancestor;
376 *ancestor_level = level;
383 topmost_relid = ancestor;
386 *ancestor_level = level;
394 return topmost_relid;
434 bool nulls[Natts_pg_publication_rel];
462 errmsg(
"relation \"%s\" is already member of publication \"%s\"",
473 memset(nulls,
false,
sizeof(nulls));
476 Anum_pg_publication_rel_oid);
478 values[Anum_pg_publication_rel_prpubid - 1] =
480 values[Anum_pg_publication_rel_prrelid - 1] =
487 nulls[Anum_pg_publication_rel_prqual - 1] =
true;
493 nulls[Anum_pg_publication_rel_prattrs - 1] =
true;
567 errcode(ERRCODE_UNDEFINED_COLUMN),
568 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
573 errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
574 errmsg(
"cannot use system column \"%s\" in publication column list",
580 errmsg(
"duplicate column \"%s\" in publication column list",
613 for (
int i = 0;
i < nelems;
i++)
633 for (
int i = 0;
i < desc->
natts;
i++)
637 if (att->attisdropped || (att->attgenerated && !include_gencols))
655 bool nulls[Natts_pg_publication_namespace];
680 errmsg(
"schema \"%s\" is already member of publication \"%s\"",
688 memset(nulls,
false,
sizeof(nulls));
691 Anum_pg_publication_namespace_oid);
693 values[Anum_pg_publication_namespace_pnpubid - 1] =
695 values[Anum_pg_publication_namespace_pnnspid - 1] =
772 Anum_pg_publication_rel_prpubid,
777 true, NULL, 1, &scankey);
815 Anum_pg_publication_puballtables,
855 Anum_pg_class_relkind,
864 Oid relid = relForm->oid;
867 !(relForm->relispartition && pubviaroot))
876 Anum_pg_class_relkind,
885 Oid relid = relForm->oid;
888 !relForm->relispartition)
917 Anum_pg_publication_namespace_pnpubid,
922 PublicationNamespacePnnspidPnpubidIndexId,
923 true, NULL, 1, &scankey);
982 Anum_pg_class_relnamespace,
991 Oid relid = relForm->oid;
998 if (relkind == RELKIND_RELATION)
1000 else if (relkind == RELKIND_PARTITIONED_TABLE)
1032 foreach(cell, pubschemalist)
1058 elog(
ERROR,
"cache lookup failed for publication %u", pubid);
1099 #define NUM_PUBLICATION_TABLES_ELEM 4
1112 bool viaroot =
false;
1128 for (
i = 0;
i < nelems;
i++)
1168 foreach(lc, pub_elem_tables)
1174 table_infos =
lappend(table_infos, table_info);
1200 INT2VECTOROID, -1, 0);
1202 PG_NODE_TREEOID, -1, 0);
1250 Anum_pg_publication_rel_prattrs,
1255 Anum_pg_publication_rel_prqual,
1279 if (att->attisdropped || (att->attgenerated && !pub->
pubgencols))
1282 attnums[nattnums++] = att->attnum;
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define Assert(condition)
#define OidIsValid(objectId)
bool IsToastNamespace(Oid namespaceId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
bool IsCatalogNamespace(Oid namespaceId)
bool IsCatalogRelation(Relation relation)
bool IsCatalogRelationOid(Oid relid)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define PG_RETURN_BOOL(x)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
int2vector * buildint2vector(const int16 *int2s, int n)
if(TABLE==NULL||TABLE_index==NULL)
void list_sort(List *list, list_sort_comparator cmp)
List * list_concat_unique_oid(List *list1, const List *list2)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
void list_deduplicate_oid(List *list)
int list_oid_cmp(const ListCell *p1, const ListCell *p2)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
bool get_rel_relispartition(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
char * get_namespace_name(Oid nspid)
char get_rel_relkind(Oid relid)
Oid get_publication_oid(const char *pubname, bool missing_ok)
Oid get_rel_namespace(Oid relid)
char * pstrdup(const char *in)
bool isAnyTempNamespace(Oid namespaceId)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
char * nodeToString(const void *obj)
List * get_partition_ancestors(Oid relid)
FormData_pg_attribute * Form_pg_attribute
static const struct exclude_list_item skip[]
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
static int list_length(const List *l)
#define foreach_delete_current(lst, var_or_cell)
static void * list_nth(const List *list, int n)
static int2vector * attnumstoint2vector(Bitmapset *attrs)
bool is_schema_publication(Oid pubid)
List * GetPublicationSchemas(Oid pubid)
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
List * GetSchemaPublications(Oid schemaid)
Publication * GetPublication(Oid pubid)
List * GetRelationPublications(Oid relid)
ObjectAddress publication_add_schema(Oid pubid, Oid schemaid, bool if_not_exists)
ObjectAddress publication_add_relation(Oid pubid, PublicationRelInfo *pri, bool if_not_exists)
List * GetPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
Bitmapset * pub_collist_validate(Relation targetrel, List *columns)
Datum pg_get_publication_tables(PG_FUNCTION_ARGS)
List * GetAllTablesPublications(void)
static void check_publication_add_relation(Relation targetrel)
static void filter_partitions(List *table_infos)
List * GetAllTablesPublicationRelations(bool pubviaroot)
Oid GetTopMostAncestorInPublication(Oid puboid, List *ancestors, int *ancestor_level)
List * GetPubPartitionOptionRelations(List *result, PublicationPartOpt pub_partopt, Oid relid)
static bool is_publishable_class(Oid relid, Form_pg_class reltuple)
#define NUM_PUBLICATION_TABLES_ELEM
static bool is_ancestor_member_tableinfos(Oid ancestor, List *table_infos)
bool check_and_fetch_column_list(Publication *pub, Oid relid, MemoryContext mcxt, Bitmapset **cols)
static void check_publication_add_schema(Oid schemaid)
Bitmapset * pub_form_cols_map(Relation relation, bool include_gencols)
List * GetSchemaPublicationRelations(Oid schemaid, PublicationPartOpt pub_partopt)
Bitmapset * pub_collist_to_bitmapset(Bitmapset *columns, Datum pubcols, MemoryContext mcxt)
Datum pg_relation_is_publishable(PG_FUNCTION_ARGS)
bool is_publishable_relation(Relation rel)
List * GetAllSchemaPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
FormData_pg_publication * Form_pg_publication
FormData_pg_publication_namespace * Form_pg_publication_namespace
FormData_pg_publication_rel * Form_pg_publication_rel
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CharGetDatum(char X)
void InvalidatePublicationRels(List *relids)
MemoryContextSwitchTo(old_ctx)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
MemoryContext multi_call_memory_ctx
PublicationActions pubactions
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
int16 values[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define SearchSysCacheCopy2(cacheId, key1, key2)
#define ReleaseSysCacheList(x)
#define SearchSysCacheExists2(cacheId, key1, key2)
#define SearchSysCacheList1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
#define FirstNormalObjectId
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
#define TupleDescAttr(tupdesc, i)