42 #include "utils/fmgroids.h"
70 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
71 errmsg(
"cannot add relation \"%s\" to publication",
78 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
79 errmsg(
"cannot add relation \"%s\" to publication",
81 errdetail(
"This operation is not supported for system tables.")));
84 if (targetrel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
86 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
87 errmsg(
"cannot add relation \"%s\" to publication",
89 errdetail(
"This operation is not supported for temporary tables.")));
90 else if (targetrel->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
92 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
93 errmsg(
"cannot add relation \"%s\" to publication",
95 errdetail(
"This operation is not supported for unlogged tables.")));
108 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
109 errmsg(
"cannot add schema \"%s\" to publication",
111 errdetail(
"This operation is not supported for system schemas.")));
116 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
117 errmsg(
"cannot add schema \"%s\" to publication",
119 errdetail(
"Temporary schemas cannot be replicated.")));
144 return (reltuple->relkind == RELKIND_RELATION ||
145 reltuple->relkind == RELKIND_PARTITIONED_TABLE) &&
147 reltuple->relpersistence == RELPERSISTENCE_PERMANENT &&
191 foreach(lc, table_infos)
195 if (relid == ancestor)
210 foreach(lc, table_infos)
220 foreach(lc2, ancestors)
251 Anum_pg_publication_namespace_pnpubid,
256 PublicationNamespacePnnspidPnpubidIndexId,
257 true, NULL, 1, &scankey);
287 foreach(lc, all_parts)
325 foreach(lc, ancestors)
335 topmost_relid = ancestor;
338 *ancestor_level = level;
345 topmost_relid = ancestor;
348 *ancestor_level = level;
356 return topmost_relid;
369 bool nulls[Natts_pg_publication_rel];
397 errmsg(
"relation \"%s\" is already member of publication \"%s\"",
413 memset(nulls,
false,
sizeof(nulls));
416 Anum_pg_publication_rel_oid);
418 values[Anum_pg_publication_rel_prpubid - 1] =
420 values[Anum_pg_publication_rel_prrelid - 1] =
427 nulls[Anum_pg_publication_rel_prqual - 1] =
true;
433 nulls[Anum_pg_publication_rel_prattrs - 1] =
true;
459 for (
int i = 0;
i < natts;
i++)
489 int bv = *(
const int16 *)
b;
532 errcode(ERRCODE_UNDEFINED_COLUMN),
533 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
538 errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
539 errmsg(
"cannot use system column \"%s\" in publication column list",
544 errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
545 errmsg(
"cannot use generated column \"%s\" in publication column list",
551 errmsg(
"duplicate column \"%s\" in publication column list",
598 for (
int i = 0;
i < nelems;
i++)
616 bool nulls[Natts_pg_publication_namespace];
641 errmsg(
"schema \"%s\" is already member of publication \"%s\"",
649 memset(nulls,
false,
sizeof(nulls));
652 Anum_pg_publication_namespace_oid);
654 values[Anum_pg_publication_namespace_pnpubid - 1] =
656 values[Anum_pg_publication_namespace_pnnspid - 1] =
733 Anum_pg_publication_rel_prpubid,
738 true, NULL, 1, &scankey);
776 Anum_pg_publication_puballtables,
816 Anum_pg_class_relkind,
825 Oid relid = relForm->oid;
828 !(relForm->relispartition && pubviaroot))
837 Anum_pg_class_relkind,
846 Oid relid = relForm->oid;
849 !relForm->relispartition)
878 Anum_pg_publication_namespace_pnpubid,
883 PublicationNamespacePnnspidPnpubidIndexId,
884 true, NULL, 1, &scankey);
943 Anum_pg_class_relnamespace,
952 Oid relid = relForm->oid;
959 if (relkind == RELKIND_RELATION)
961 else if (relkind == RELKIND_PARTITIONED_TABLE)
993 foreach(cell, pubschemalist)
1019 elog(
ERROR,
"cache lookup failed for publication %u", pubid);
1059 #define NUM_PUBLICATION_TABLES_ELEM 4
1072 bool viaroot =
false;
1086 &elems, NULL, &nelems);
1089 for (
i = 0;
i < nelems;
i++)
1129 foreach(lc, pub_elem_tables)
1135 table_infos =
lappend(table_infos, table_info);
1161 INT2VECTOROID, -1, 0);
1163 PG_NODE_TREEOID, -1, 0);
1166 funcctx->
user_fctx = (
void *) table_infos;
1211 Anum_pg_publication_rel_prattrs,
1216 Anum_pg_publication_rel_prqual,
1240 if (att->attisdropped || att->attgenerated)
1243 attnums[nattnums++] = att->attnum;
#define PG_GETARG_ARRAYTYPE_P(n)
#define DatumGetArrayTypeP(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
#define InvalidAttrNumber
void bms_free(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 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)
elog(ERROR, "%s: %s", p2, msg)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
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)
static void * list_nth(const List *list, int n)
#define foreach_delete_current(lst, cell)
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)
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)
static int compare_int16(const void *a, const void *b)
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)
static void publication_translate_columns(Relation targetrel, List *columns, int *natts, AttrNumber **attrs)
FormData_pg_publication * Form_pg_publication
FormData_pg_publication_namespace * Form_pg_publication_namespace
FormData_pg_publication_rel * Form_pg_publication_rel
#define qsort(a, b, c, d)
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)
#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]
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)
@ PUBLICATIONNAMESPACEMAP
#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)