pg_subscription.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* -------------------------------------------------------------------------
  2. *
  3. * pg_subscription.h
  4. * definition of the "subscription" system catalog (pg_subscription)
  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_subscription.h
  10. *
  11. * NOTES
  12. * The Catalog.pm module reads this file and derives schema
  13. * information.
  14. *
  15. * -------------------------------------------------------------------------
  16. */
  17. #ifndef PG_SUBSCRIPTION_H
  18. #define PG_SUBSCRIPTION_H
  19. #include "access/xlogdefs.h"
  20. #include "catalog/genbki.h"
  21. #include "catalog/pg_subscription_d.h"
  22. #include "nodes/pg_list.h"
  23. /*
  24. * two_phase tri-state values. See comments atop worker.c to know more about
  25. * these states.
  26. */
  27. #define LOGICALREP_TWOPHASE_STATE_DISABLED 'd'
  28. #define LOGICALREP_TWOPHASE_STATE_PENDING 'p'
  29. #define LOGICALREP_TWOPHASE_STATE_ENABLED 'e'
  30. /* ----------------
  31. * pg_subscription definition. cpp turns this into
  32. * typedef struct FormData_pg_subscription
  33. * ----------------
  34. */
  35. /*
  36. * Technically, the subscriptions live inside the database, so a shared catalog
  37. * seems weird, but the replication launcher process needs to access all of
  38. * them to be able to start the workers, so we have to put them in a shared,
  39. * nailed catalog.
  40. *
  41. * CAUTION: There is a GRANT in system_views.sql to grant public select
  42. * access on all columns except subconninfo. When you add a new column
  43. * here, be sure to update that (or, if the new column is not to be publicly
  44. * readable, update associated comments and catalogs.sgml instead).
  45. */
  46. CATALOG(pg_subscription,6100,SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101,SubscriptionRelation_Rowtype_Id) BKI_SCHEMA_MACRO
  47. {
  48. Oid oid; /* oid */
  49. Oid subdbid BKI_LOOKUP(pg_database); /* Database the
  50. * subscription is in. */
  51. XLogRecPtr subskiplsn; /* All changes finished at this LSN are
  52. * skipped */
  53. NameData subname; /* Name of the subscription */
  54. Oid subowner BKI_LOOKUP(pg_authid); /* Owner of the subscription */
  55. bool subenabled; /* True if the subscription is enabled (the
  56. * worker should be running) */
  57. bool subbinary; /* True if the subscription wants the
  58. * publisher to send data in binary */
  59. bool substream; /* Stream in-progress transactions. */
  60. char subtwophasestate; /* Stream two-phase transactions */
  61. bool subdisableonerr; /* True if a worker error should cause the
  62. * subscription to be disabled */
  63. #ifdef CATALOG_VARLEN /* variable-length fields start here */
  64. /* Connection string to the publisher */
  65. text subconninfo BKI_FORCE_NOT_NULL;
  66. /* Slot name on publisher */
  67. NameData subslotname BKI_FORCE_NULL;
  68. /* Synchronous commit setting for worker */
  69. text subsynccommit BKI_FORCE_NOT_NULL;
  70. /* List of publications subscribed to */
  71. text subpublications[1] BKI_FORCE_NOT_NULL;
  72. #endif
  73. } FormData_pg_subscription;
  74. typedef FormData_pg_subscription *Form_pg_subscription;
  75. DECLARE_TOAST_WITH_MACRO(pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex);
  76. DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, on pg_subscription using btree(oid oid_ops));
  77. DECLARE_UNIQUE_INDEX(pg_subscription_subname_index, 6115, SubscriptionNameIndexId, on pg_subscription using btree(subdbid oid_ops, subname name_ops));
  78. typedef struct Subscription
  79. {
  80. Oid oid; /* Oid of the subscription */
  81. Oid dbid; /* Oid of the database which subscription is
  82. * in */
  83. XLogRecPtr skiplsn; /* All changes finished at this LSN are
  84. * skipped */
  85. char *name; /* Name of the subscription */
  86. Oid owner; /* Oid of the subscription owner */
  87. bool enabled; /* Indicates if the subscription is enabled */
  88. bool binary; /* Indicates if the subscription wants data in
  89. * binary format */
  90. bool stream; /* Allow streaming in-progress transactions. */
  91. char twophasestate; /* Allow streaming two-phase transactions */
  92. bool disableonerr; /* Indicates if the subscription should be
  93. * automatically disabled if a worker error
  94. * occurs */
  95. char *conninfo; /* Connection string to the publisher */
  96. char *slotname; /* Name of the replication slot */
  97. char *synccommit; /* Synchronous commit setting for worker */
  98. List *publications; /* List of publication names to subscribe to */
  99. } Subscription;
  100. extern Subscription *GetSubscription(Oid subid, bool missing_ok);
  101. extern void FreeSubscription(Subscription *sub);
  102. extern void DisableSubscription(Oid subid);
  103. extern Oid get_subscription_oid(const char *subname, bool missing_ok);
  104. extern char *get_subscription_name(Oid subid, bool missing_ok);
  105. extern int CountDBSubscriptions(Oid dbid);
  106. #endif /* PG_SUBSCRIPTION_H */