pg_publication.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pg_publication.h
  4. * definition of the "publication" system catalog (pg_publication)
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/catalog/pg_publication.h
  10. *
  11. * NOTES
  12. * The Catalog.pm module reads this file and derives schema
  13. * information.
  14. *
  15. *-------------------------------------------------------------------------
  16. */
  17. #ifndef PG_PUBLICATION_H
  18. #define PG_PUBLICATION_H
  19. #include "catalog/genbki.h"
  20. #include "catalog/objectaddress.h"
  21. #include "catalog/pg_publication_d.h"
  22. /* ----------------
  23. * pg_publication definition. cpp turns this into
  24. * typedef struct FormData_pg_publication
  25. * ----------------
  26. */
  27. CATALOG(pg_publication,6104,PublicationRelationId)
  28. {
  29. Oid oid; /* oid */
  30. NameData pubname; /* name of the publication */
  31. Oid pubowner BKI_LOOKUP(pg_authid); /* publication owner */
  32. /*
  33. * indicates that this is special publication which should encompass all
  34. * tables in the database (except for the unlogged and temp ones)
  35. */
  36. bool puballtables;
  37. /* true if inserts are published */
  38. bool pubinsert;
  39. /* true if updates are published */
  40. bool pubupdate;
  41. /* true if deletes are published */
  42. bool pubdelete;
  43. /* true if truncates are published */
  44. bool pubtruncate;
  45. /* true if partition changes are published using root schema */
  46. bool pubviaroot;
  47. } FormData_pg_publication;
  48. /* ----------------
  49. * Form_pg_publication corresponds to a pointer to a tuple with
  50. * the format of pg_publication relation.
  51. * ----------------
  52. */
  53. typedef FormData_pg_publication *Form_pg_publication;
  54. DECLARE_UNIQUE_INDEX_PKEY(pg_publication_oid_index, 6110, PublicationObjectIndexId, on pg_publication using btree(oid oid_ops));
  55. DECLARE_UNIQUE_INDEX(pg_publication_pubname_index, 6111, PublicationNameIndexId, on pg_publication using btree(pubname name_ops));
  56. typedef struct PublicationActions
  57. {
  58. bool pubinsert;
  59. bool pubupdate;
  60. bool pubdelete;
  61. bool pubtruncate;
  62. } PublicationActions;
  63. typedef struct PublicationDesc
  64. {
  65. PublicationActions pubactions;
  66. /*
  67. * true if the columns referenced in row filters which are used for UPDATE
  68. * or DELETE are part of the replica identity or the publication actions
  69. * do not include UPDATE or DELETE.
  70. */
  71. bool rf_valid_for_update;
  72. bool rf_valid_for_delete;
  73. /*
  74. * true if the columns are part of the replica identity or the publication
  75. * actions do not include UPDATE or DELETE.
  76. */
  77. bool cols_valid_for_update;
  78. bool cols_valid_for_delete;
  79. } PublicationDesc;
  80. typedef struct Publication
  81. {
  82. Oid oid;
  83. char *name;
  84. bool alltables;
  85. bool pubviaroot;
  86. PublicationActions pubactions;
  87. } Publication;
  88. typedef struct PublicationRelInfo
  89. {
  90. Relation relation;
  91. Node *whereClause;
  92. List *columns;
  93. } PublicationRelInfo;
  94. extern Publication *GetPublication(Oid pubid);
  95. extern Publication *GetPublicationByName(const char *pubname, bool missing_ok);
  96. extern List *GetRelationPublications(Oid relid);
  97. /*---------
  98. * Expected values for pub_partopt parameter of GetRelationPublications(),
  99. * which allows callers to specify which partitions of partitioned tables
  100. * mentioned in the publication they expect to see.
  101. *
  102. * ROOT: only the table explicitly mentioned in the publication
  103. * LEAF: only leaf partitions in given tree
  104. * ALL: all partitions in given tree
  105. */
  106. typedef enum PublicationPartOpt
  107. {
  108. PUBLICATION_PART_ROOT,
  109. PUBLICATION_PART_LEAF,
  110. PUBLICATION_PART_ALL,
  111. } PublicationPartOpt;
  112. extern List *GetPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt);
  113. extern List *GetAllTablesPublications(void);
  114. extern List *GetAllTablesPublicationRelations(bool pubviaroot);
  115. extern List *GetPublicationSchemas(Oid pubid);
  116. extern List *GetSchemaPublications(Oid schemaid);
  117. extern List *GetSchemaPublicationRelations(Oid schemaid,
  118. PublicationPartOpt pub_partopt);
  119. extern List *GetAllSchemaPublicationRelations(Oid puboid,
  120. PublicationPartOpt pub_partopt);
  121. extern List *GetPubPartitionOptionRelations(List *result,
  122. PublicationPartOpt pub_partopt,
  123. Oid relid);
  124. extern Oid GetTopMostAncestorInPublication(Oid puboid, List *ancestors,
  125. int *ancestor_level);
  126. extern bool is_publishable_relation(Relation rel);
  127. extern bool is_schema_publication(Oid pubid);
  128. extern ObjectAddress publication_add_relation(Oid pubid, PublicationRelInfo *pri,
  129. bool if_not_exists);
  130. extern ObjectAddress publication_add_schema(Oid pubid, Oid schemaid,
  131. bool if_not_exists);
  132. extern Bitmapset *pub_collist_to_bitmapset(Bitmapset *columns, Datum pubcols,
  133. MemoryContext mcxt);
  134. extern Oid get_publication_oid(const char *pubname, bool missing_ok);
  135. extern char *get_publication_name(Oid pubid, bool missing_ok);
  136. #endif /* PG_PUBLICATION_H */