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);
279 foreach(lc, all_parts)
317 foreach(lc, ancestors)
327 topmost_relid = ancestor;
330 *ancestor_level = level;
337 topmost_relid = ancestor;
340 *ancestor_level = level;
348 return topmost_relid;
388 bool nulls[Natts_pg_publication_rel];
416 errmsg(
"relation \"%s\" is already member of publication \"%s\"",
427 memset(nulls,
false,
sizeof(nulls));
430 Anum_pg_publication_rel_oid);
432 values[Anum_pg_publication_rel_prpubid - 1] =
434 values[Anum_pg_publication_rel_prrelid - 1] =
441 nulls[Anum_pg_publication_rel_prqual - 1] =
true;
447 nulls[Anum_pg_publication_rel_prattrs - 1] =
true;
523 errcode(ERRCODE_UNDEFINED_COLUMN),
524 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
529 errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
530 errmsg(
"cannot use system column \"%s\" in publication column list",
535 errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
536 errmsg(
"cannot use generated column \"%s\" in publication column list",
542 errmsg(
"duplicate column \"%s\" in publication column list",
575 for (
int i = 0;
i < nelems;
i++)
593 bool nulls[Natts_pg_publication_namespace];
618 errmsg(
"schema \"%s\" is already member of publication \"%s\"",
626 memset(nulls,
false,
sizeof(nulls));
629 Anum_pg_publication_namespace_oid);
631 values[Anum_pg_publication_namespace_pnpubid - 1] =
633 values[Anum_pg_publication_namespace_pnnspid - 1] =
710 Anum_pg_publication_rel_prpubid,
715 true, NULL, 1, &scankey);
753 Anum_pg_publication_puballtables,
793 Anum_pg_class_relkind,
802 Oid relid = relForm->oid;
805 !(relForm->relispartition && pubviaroot))
814 Anum_pg_class_relkind,
823 Oid relid = relForm->oid;
826 !relForm->relispartition)
855 Anum_pg_publication_namespace_pnpubid,
860 PublicationNamespacePnnspidPnpubidIndexId,
861 true, NULL, 1, &scankey);
920 Anum_pg_class_relnamespace,
929 Oid relid = relForm->oid;
936 if (relkind == RELKIND_RELATION)
938 else if (relkind == RELKIND_PARTITIONED_TABLE)
970 foreach(cell, pubschemalist)
996 elog(
ERROR,
"cache lookup failed for publication %u", pubid);
1036 #define NUM_PUBLICATION_TABLES_ELEM 4
1049 bool viaroot =
false;
1065 for (
i = 0;
i < nelems;
i++)
1105 foreach(lc, pub_elem_tables)
1111 table_infos =
lappend(table_infos, table_info);
1137 INT2VECTOROID, -1, 0);
1139 PG_NODE_TREEOID, -1, 0);
1142 funcctx->
user_fctx = (
void *) table_infos;
1187 Anum_pg_publication_rel_prattrs,
1192 Anum_pg_publication_rel_prqual,
1216 if (att->attisdropped || att->attgenerated)
1219 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)
static void check_publication_add_schema(Oid schemaid)
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)
#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)