PostgreSQL Source Code  git master
subscriptioncmds.h File Reference
Include dependency graph for subscriptioncmds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress CreateSubscription (ParseState *pstate, CreateSubscriptionStmt *stmt, bool isTopLevel)
 
ObjectAddress AlterSubscription (ParseState *pstate, AlterSubscriptionStmt *stmt, bool isTopLevel)
 
void DropSubscription (DropSubscriptionStmt *stmt, bool isTopLevel)
 
ObjectAddress AlterSubscriptionOwner (const char *name, Oid newOwnerId)
 
void AlterSubscriptionOwner_oid (Oid subid, Oid newOwnerId)
 

Function Documentation

◆ AlterSubscription()

ObjectAddress AlterSubscription ( ParseState pstate,
AlterSubscriptionStmt stmt,
bool  isTopLevel 
)

Definition at line 821 of file subscriptioncmds.c.

References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, ALTER_SUBSCRIPTION_ADD_PUBLICATION, ALTER_SUBSCRIPTION_CONNECTION, ALTER_SUBSCRIPTION_DROP_PUBLICATION, ALTER_SUBSCRIPTION_ENABLED, ALTER_SUBSCRIPTION_OPTIONS, ALTER_SUBSCRIPTION_REFRESH, ALTER_SUBSCRIPTION_SET_PUBLICATION, AlterSubscription_refresh(), ApplyLauncherWakeupAtCommit(), Assert, SubOpts::binary, BoolGetDatum, CatalogTupleUpdate(), AlterSubscriptionStmt::conninfo, SubOpts::copy_data, CStringGetDatum, CStringGetTextDatum, DirectFunctionCall1, elog, SubOpts::enabled, Subscription::enabled, ereport, errcode(), errhint(), errmsg(), ERROR, GETSTRUCT, GetSubscription(), GetUserId(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, IsSet, AlterSubscriptionStmt::kind, load_file(), LockSharedObject(), LOGICALREP_TWOPHASE_STATE_ENABLED, merge_publications(), MyDatabaseId, namein(), OBJECT_SUBSCRIPTION, ObjectAddressSet, AlterSubscriptionStmt::options, opts, parse_subscription_options(), pg_subscription_ownercheck(), PreventInTransactionBlock(), AlterSubscriptionStmt::publication, publicationListToArray(), Subscription::publications, SubOpts::refresh, RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, SubOpts::slot_name, Subscription::slotname, SubOpts::specified_opts, SubOpts::streaming, AlterSubscriptionStmt::subname, SUBOPT_BINARY, SUBOPT_COPY_DATA, SUBOPT_ENABLED, SUBOPT_REFRESH, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBSCRIPTIONNAME, SubOpts::synchronous_commit, HeapTupleData::t_self, table_close(), table_open(), Subscription::twophasestate, values, and walrcv_check_conninfo.

Referenced by ProcessUtilitySlow().

823 {
824  Relation rel;
825  ObjectAddress myself;
826  bool nulls[Natts_pg_subscription];
827  bool replaces[Natts_pg_subscription];
828  Datum values[Natts_pg_subscription];
829  HeapTuple tup;
830  Oid subid;
831  bool update_tuple = false;
832  Subscription *sub;
834  bits32 supported_opts;
835  SubOpts opts = {0};
836 
837  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
838 
839  /* Fetch the existing tuple. */
841  CStringGetDatum(stmt->subname));
842 
843  if (!HeapTupleIsValid(tup))
844  ereport(ERROR,
845  (errcode(ERRCODE_UNDEFINED_OBJECT),
846  errmsg("subscription \"%s\" does not exist",
847  stmt->subname)));
848 
849  form = (Form_pg_subscription) GETSTRUCT(tup);
850  subid = form->oid;
851 
852  /* must be owner */
853  if (!pg_subscription_ownercheck(subid, GetUserId()))
855  stmt->subname);
856 
857  sub = GetSubscription(subid, false);
858 
859  /* Lock the subscription so nobody else can do anything with it. */
860  LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
861 
862  /* Form a new tuple. */
863  memset(values, 0, sizeof(values));
864  memset(nulls, false, sizeof(nulls));
865  memset(replaces, false, sizeof(replaces));
866 
867  switch (stmt->kind)
868  {
870  {
871  supported_opts = (SUBOPT_SLOT_NAME |
874 
875  parse_subscription_options(pstate, stmt->options,
876  supported_opts, &opts);
877 
879  {
880  /*
881  * The subscription must be disabled to allow slot_name as
882  * 'none', otherwise, the apply worker will repeatedly try
883  * to stream the data using that slot_name which neither
884  * exists on the publisher nor the user will be allowed to
885  * create it.
886  */
887  if (sub->enabled && !opts.slot_name)
888  ereport(ERROR,
889  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
890  errmsg("cannot set %s for enabled subscription",
891  "slot_name = NONE")));
892 
893  if (opts.slot_name)
894  values[Anum_pg_subscription_subslotname - 1] =
896  else
897  nulls[Anum_pg_subscription_subslotname - 1] = true;
898  replaces[Anum_pg_subscription_subslotname - 1] = true;
899  }
900 
901  if (opts.synchronous_commit)
902  {
903  values[Anum_pg_subscription_subsynccommit - 1] =
905  replaces[Anum_pg_subscription_subsynccommit - 1] = true;
906  }
907 
909  {
910  values[Anum_pg_subscription_subbinary - 1] =
911  BoolGetDatum(opts.binary);
912  replaces[Anum_pg_subscription_subbinary - 1] = true;
913  }
914 
916  {
917  values[Anum_pg_subscription_substream - 1] =
918  BoolGetDatum(opts.streaming);
919  replaces[Anum_pg_subscription_substream - 1] = true;
920  }
921 
922  update_tuple = true;
923  break;
924  }
925 
927  {
928  parse_subscription_options(pstate, stmt->options,
929  SUBOPT_ENABLED, &opts);
931 
932  if (!sub->slotname && opts.enabled)
933  ereport(ERROR,
934  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
935  errmsg("cannot enable subscription that does not have a slot name")));
936 
937  values[Anum_pg_subscription_subenabled - 1] =
938  BoolGetDatum(opts.enabled);
939  replaces[Anum_pg_subscription_subenabled - 1] = true;
940 
941  if (opts.enabled)
943 
944  update_tuple = true;
945  break;
946  }
947 
949  /* Load the library providing us libpq calls. */
950  load_file("libpqwalreceiver", false);
951  /* Check the connection info string. */
953 
954  values[Anum_pg_subscription_subconninfo - 1] =
956  replaces[Anum_pg_subscription_subconninfo - 1] = true;
957  update_tuple = true;
958  break;
959 
961  {
962  supported_opts = SUBOPT_COPY_DATA | SUBOPT_REFRESH;
963  parse_subscription_options(pstate, stmt->options,
964  supported_opts, &opts);
965 
966  values[Anum_pg_subscription_subpublications - 1] =
968  replaces[Anum_pg_subscription_subpublications - 1] = true;
969 
970  update_tuple = true;
971 
972  /* Refresh if user asked us to. */
973  if (opts.refresh)
974  {
975  if (!sub->enabled)
976  ereport(ERROR,
977  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
978  errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
979  errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
980 
981  /*
982  * See ALTER_SUBSCRIPTION_REFRESH for details why this is
983  * not allowed.
984  */
986  ereport(ERROR,
987  (errcode(ERRCODE_SYNTAX_ERROR),
988  errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
989  errhint("Use ALTER SUBSCRIPTION ...SET PUBLICATION with refresh = false, or with copy_data = false"
990  ", or use DROP/CREATE SUBSCRIPTION.")));
991 
992  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
993 
994  /* Make sure refresh sees the new list of publications. */
995  sub->publications = stmt->publication;
996 
998  }
999 
1000  break;
1001  }
1002 
1005  {
1006  List *publist;
1007  bool isadd = stmt->kind == ALTER_SUBSCRIPTION_ADD_PUBLICATION;
1008 
1009  supported_opts = SUBOPT_REFRESH | SUBOPT_COPY_DATA;
1010  parse_subscription_options(pstate, stmt->options,
1011  supported_opts, &opts);
1012 
1013  publist = merge_publications(sub->publications, stmt->publication, isadd, stmt->subname);
1014  values[Anum_pg_subscription_subpublications - 1] =
1015  publicationListToArray(publist);
1016  replaces[Anum_pg_subscription_subpublications - 1] = true;
1017 
1018  update_tuple = true;
1019 
1020  /* Refresh if user asked us to. */
1021  if (opts.refresh)
1022  {
1023  if (!sub->enabled)
1024  ereport(ERROR,
1025  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1026  errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
1027  errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
1028 
1029  /*
1030  * See ALTER_SUBSCRIPTION_REFRESH for details why this is
1031  * not allowed.
1032  */
1034  ereport(ERROR,
1035  (errcode(ERRCODE_SYNTAX_ERROR),
1036  errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
1037  errhint("Use ALTER SUBSCRIPTION ...SET PUBLICATION with refresh = false, or with copy_data = false"
1038  ", or use DROP/CREATE SUBSCRIPTION.")));
1039 
1040  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
1041 
1042  /* Refresh the new list of publications. */
1043  sub->publications = publist;
1044 
1046  }
1047 
1048  break;
1049  }
1050 
1052  {
1053  if (!sub->enabled)
1054  ereport(ERROR,
1055  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1056  errmsg("ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions")));
1057 
1058  parse_subscription_options(pstate, stmt->options,
1059  SUBOPT_COPY_DATA, &opts);
1060 
1061  /*
1062  * The subscription option "two_phase" requires that
1063  * replication has passed the initial table synchronization
1064  * phase before the two_phase becomes properly enabled.
1065  *
1066  * But, having reached this two-phase commit "enabled" state
1067  * we must not allow any subsequent table initialization to
1068  * occur. So the ALTER SUBSCRIPTION ... REFRESH is disallowed
1069  * when the user had requested two_phase = on mode.
1070  *
1071  * The exception to this restriction is when copy_data =
1072  * false, because when copy_data is false the tablesync will
1073  * start already in READY state and will exit directly without
1074  * doing anything.
1075  *
1076  * For more details see comments atop worker.c.
1077  */
1079  ereport(ERROR,
1080  (errcode(ERRCODE_SYNTAX_ERROR),
1081  errmsg("ALTER SUBSCRIPTION ... REFRESH with copy_data is not allowed when two_phase is enabled"),
1082  errhint("Use ALTER SUBSCRIPTION ... REFRESH with copy_data = false"
1083  ", or use DROP/CREATE SUBSCRIPTION.")));
1084 
1085  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION ... REFRESH");
1086 
1088 
1089  break;
1090  }
1091 
1092  default:
1093  elog(ERROR, "unrecognized ALTER SUBSCRIPTION kind %d",
1094  stmt->kind);
1095  }
1096 
1097  /* Update the catalog if needed. */
1098  if (update_tuple)
1099  {
1100  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
1101  replaces);
1102 
1103  CatalogTupleUpdate(rel, &tup->t_self, tup);
1104 
1105  heap_freetuple(tup);
1106  }
1107 
1109 
1110  ObjectAddressSet(myself, SubscriptionRelationId, subid);
1111 
1112  InvokeObjectPostAlterHook(SubscriptionRelationId, subid, 0);
1113 
1114  return myself;
1115 }
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:48
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int errhint(const char *fmt,...)
Definition: elog.c:1156
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
bool copy_data
#define RelationGetDescr(relation)
Definition: rel.h:503
Oid GetUserId(void)
Definition: miscinit.c:495
#define walrcv_check_conninfo(conninfo)
Definition: walreceiver.h:406
bits32 specified_opts
int errcode(int sqlerrcode)
Definition: elog.c:698
#define SUBOPT_ENABLED
static Datum publicationListToArray(List *publist)
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:626
FormData_pg_subscription * Form_pg_subscription
#define SUBOPT_SYNCHRONOUS_COMMIT
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
static void parse_subscription_options(ParseState *pstate, List *stmt_options, bits32 supported_opts, SubOpts *opts)
#define SUBOPT_STREAMING
#define LOGICALREP_TWOPHASE_STATE_ENABLED
Subscription * GetSubscription(Oid subid, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
bool streaming
#define ERROR
Definition: elog.h:46
#define SUBOPT_BINARY
ItemPointerData t_self
Definition: htup.h:65
AlterSubscriptionType kind
Definition: parsenodes.h:3691
#define SUBOPT_REFRESH
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:622
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3389
char * slot_name
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
static AmcheckOptions opts
Definition: pg_amcheck.c:110
uintptr_t Datum
Definition: postgres.h:411
Oid MyDatabaseId
Definition: globals.c:88
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1017
#define BoolGetDatum(X)
Definition: postgres.h:446
#define ereport(elevel,...)
Definition: elog.h:157
uint32 bits32
Definition: c.h:450
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define SUBOPT_COPY_DATA
#define Assert(condition)
Definition: c.h:804
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
#define SUBOPT_SLOT_NAME
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define AccessExclusiveLock
Definition: lockdefs.h:45
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
#define CStringGetTextDatum(s)
Definition: builtins.h:86
void ApplyLauncherWakeupAtCommit(void)
Definition: launcher.c:785
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:177
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113
Definition: pg_list.h:50
#define IsSet(val, bits)
char * synchronous_commit
static void AlterSubscription_refresh(Subscription *sub, bool copy_data)
static List * merge_publications(List *oldpublist, List *newpublist, bool addpub, const char *subname)
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5382

◆ AlterSubscriptionOwner()

ObjectAddress AlterSubscriptionOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 1483 of file subscriptioncmds.c.

References AlterSubscriptionOwner_internal(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, heap_freetuple(), HeapTupleIsValid, MyDatabaseId, ObjectAddressSet, RowExclusiveLock, SearchSysCacheCopy2, SUBSCRIPTIONNAME, table_close(), and table_open().

Referenced by ExecAlterOwnerStmt().

1484 {
1485  Oid subid;
1486  HeapTuple tup;
1487  Relation rel;
1488  ObjectAddress address;
1489  Form_pg_subscription form;
1490 
1491  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
1492 
1495 
1496  if (!HeapTupleIsValid(tup))
1497  ereport(ERROR,
1498  (errcode(ERRCODE_UNDEFINED_OBJECT),
1499  errmsg("subscription \"%s\" does not exist", name)));
1500 
1501  form = (Form_pg_subscription) GETSTRUCT(tup);
1502  subid = form->oid;
1503 
1504  AlterSubscriptionOwner_internal(rel, tup, newOwnerId);
1505 
1506  ObjectAddressSet(address, SubscriptionRelationId, subid);
1507 
1508  heap_freetuple(tup);
1509 
1511 
1512  return address;
1513 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
int errcode(int sqlerrcode)
Definition: elog.c:698
FormData_pg_subscription * Form_pg_subscription
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:46
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:622
Oid MyDatabaseId
Definition: globals.c:88
#define ereport(elevel,...)
Definition: elog.h:157
static void AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
const char * name
Definition: encode.c:561
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:177
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterSubscriptionOwner_oid()

void AlterSubscriptionOwner_oid ( Oid  subid,
Oid  newOwnerId 
)

Definition at line 1519 of file subscriptioncmds.c.

References AlterSubscriptionOwner_internal(), ereport, errcode(), errmsg(), ERROR, heap_freetuple(), HeapTupleIsValid, ObjectIdGetDatum, RowExclusiveLock, SearchSysCacheCopy1, SUBSCRIPTIONOID, table_close(), and table_open().

Referenced by shdepReassignOwned().

1520 {
1521  HeapTuple tup;
1522  Relation rel;
1523 
1524  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
1525 
1527 
1528  if (!HeapTupleIsValid(tup))
1529  ereport(ERROR,
1530  (errcode(ERRCODE_UNDEFINED_OBJECT),
1531  errmsg("subscription with OID %u does not exist", subid)));
1532 
1533  AlterSubscriptionOwner_internal(rel, tup, newOwnerId);
1534 
1535  heap_freetuple(tup);
1536 
1538 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int errcode(int sqlerrcode)
Definition: elog.c:698
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel,...)
Definition: elog.h:157
static void AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:175
int errmsg(const char *fmt,...)
Definition: elog.c:909
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ CreateSubscription()

ObjectAddress CreateSubscription ( ParseState pstate,
CreateSubscriptionStmt stmt,
bool  isTopLevel 
)

Definition at line 375 of file subscriptioncmds.c.

References AccessShareLock, AddSubscriptionRelState(), ApplyLauncherWakeupAtCommit(), Assert, SubOpts::binary, BoolGetDatum, CatalogTupleInsert(), CharGetDatum, CheckSubscriptionRelkind(), SubOpts::connect, CreateSubscriptionStmt::conninfo, SubOpts::copy_data, SubOpts::create_slot, CRS_NOEXPORT_SNAPSHOT, CStringGetDatum, CStringGetTextDatum, DirectFunctionCall1, elog, SubOpts::enabled, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, fetch_table_list(), get_rel_relkind(), GetNewOidWithIndex(), GetSysCacheOid2, GetUserId(), heap_form_tuple(), heap_freetuple(), InvalidXLogRecPtr, InvokeObjectPostCreateHook, IsSet, lfirst, load_file(), LOGICALREP_TWOPHASE_STATE_DISABLED, LOGICALREP_TWOPHASE_STATE_ENABLED, LOGICALREP_TWOPHASE_STATE_PENDING, MyDatabaseId, NAMEDATALEN, namein(), NIL, NOTICE, ObjectAddressSet, ObjectIdGetDatum, OidIsValid, CreateSubscriptionStmt::options, opts, parse_subscription_options(), PG_END_TRY, PG_FINALLY, PG_TRY, PreventInTransactionBlock(), CreateSubscriptionStmt::publication, publicationListToArray(), RangeVarGetRelid, recordDependencyOnOwner(), RelationGetDescr, RangeVar::relname, replorigin_create(), RowExclusiveLock, RangeVar::schemaname, SubOpts::slot_name, snprintf, SubOpts::specified_opts, SubOpts::streaming, CreateSubscriptionStmt::subname, SUBOPT_BINARY, SUBOPT_CONNECT, SUBOPT_COPY_DATA, SUBOPT_CREATE_SLOT, SUBOPT_ENABLED, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, SUBSCRIPTIONNAME, superuser(), SubOpts::synchronous_commit, table_close(), table_open(), SubOpts::twophase, UpdateTwoPhaseState(), values, walrcv_check_conninfo, walrcv_connect, walrcv_create_slot, walrcv_disconnect, WARNING, and wrconn.

Referenced by ProcessUtilitySlow().

377 {
378  Relation rel;
379  ObjectAddress myself;
380  Oid subid;
381  bool nulls[Natts_pg_subscription];
382  Datum values[Natts_pg_subscription];
383  Oid owner = GetUserId();
384  HeapTuple tup;
385  char *conninfo;
386  char originname[NAMEDATALEN];
387  List *publications;
388  bits32 supported_opts;
389  SubOpts opts = {0};
390 
391  /*
392  * Parse and check options.
393  *
394  * Connection and publication should not be specified here.
395  */
396  supported_opts = (SUBOPT_CONNECT | SUBOPT_ENABLED | SUBOPT_CREATE_SLOT |
400  parse_subscription_options(pstate, stmt->options, supported_opts, &opts);
401 
402  /*
403  * Since creating a replication slot is not transactional, rolling back
404  * the transaction leaves the created replication slot. So we cannot run
405  * CREATE SUBSCRIPTION inside a transaction block if creating a
406  * replication slot.
407  */
408  if (opts.create_slot)
409  PreventInTransactionBlock(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");
410 
411  if (!superuser())
412  ereport(ERROR,
413  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
414  errmsg("must be superuser to create subscriptions")));
415 
416  /*
417  * If built with appropriate switch, whine when regression-testing
418  * conventions for subscription names are violated.
419  */
420 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
421  if (strncmp(stmt->subname, "regress_", 8) != 0)
422  elog(WARNING, "subscriptions created by regression test cases should have names starting with \"regress_\"");
423 #endif
424 
425  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
426 
427  /* Check if name is used */
428  subid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
430  if (OidIsValid(subid))
431  {
432  ereport(ERROR,
434  errmsg("subscription \"%s\" already exists",
435  stmt->subname)));
436  }
437 
438  if (!IsSet(opts.specified_opts, SUBOPT_SLOT_NAME) &&
439  opts.slot_name == NULL)
440  opts.slot_name = stmt->subname;
441 
442  /* The default for synchronous_commit of subscriptions is off. */
443  if (opts.synchronous_commit == NULL)
444  opts.synchronous_commit = "off";
445 
446  conninfo = stmt->conninfo;
447  publications = stmt->publication;
448 
449  /* Load the library providing us libpq calls. */
450  load_file("libpqwalreceiver", false);
451 
452  /* Check the connection info string. */
453  walrcv_check_conninfo(conninfo);
454 
455  /* Everything ok, form a new tuple. */
456  memset(values, 0, sizeof(values));
457  memset(nulls, false, sizeof(nulls));
458 
459  subid = GetNewOidWithIndex(rel, SubscriptionObjectIndexId,
460  Anum_pg_subscription_oid);
461  values[Anum_pg_subscription_oid - 1] = ObjectIdGetDatum(subid);
462  values[Anum_pg_subscription_subdbid - 1] = ObjectIdGetDatum(MyDatabaseId);
463  values[Anum_pg_subscription_subname - 1] =
465  values[Anum_pg_subscription_subowner - 1] = ObjectIdGetDatum(owner);
466  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(opts.enabled);
467  values[Anum_pg_subscription_subbinary - 1] = BoolGetDatum(opts.binary);
468  values[Anum_pg_subscription_substream - 1] = BoolGetDatum(opts.streaming);
469  values[Anum_pg_subscription_subtwophasestate - 1] =
470  CharGetDatum(opts.twophase ?
473  values[Anum_pg_subscription_subconninfo - 1] =
474  CStringGetTextDatum(conninfo);
475  if (opts.slot_name)
476  values[Anum_pg_subscription_subslotname - 1] =
478  else
479  nulls[Anum_pg_subscription_subslotname - 1] = true;
480  values[Anum_pg_subscription_subsynccommit - 1] =
482  values[Anum_pg_subscription_subpublications - 1] =
483  publicationListToArray(publications);
484 
485  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
486 
487  /* Insert tuple into catalog. */
488  CatalogTupleInsert(rel, tup);
489  heap_freetuple(tup);
490 
491  recordDependencyOnOwner(SubscriptionRelationId, subid, owner);
492 
493  snprintf(originname, sizeof(originname), "pg_%u", subid);
494  replorigin_create(originname);
495 
496  /*
497  * Connect to remote side to execute requested commands and fetch table
498  * info.
499  */
500  if (opts.connect)
501  {
502  char *err;
504  List *tables;
505  ListCell *lc;
506  char table_state;
507 
508  /* Try to connect to the publisher. */
509  wrconn = walrcv_connect(conninfo, true, stmt->subname, &err);
510  if (!wrconn)
511  ereport(ERROR,
512  (errcode(ERRCODE_CONNECTION_FAILURE),
513  errmsg("could not connect to the publisher: %s", err)));
514 
515  PG_TRY();
516  {
517  /*
518  * Set sync state based on if we were asked to do data copy or
519  * not.
520  */
521  table_state = opts.copy_data ? SUBREL_STATE_INIT : SUBREL_STATE_READY;
522 
523  /*
524  * Get the table list from publisher and build local table status
525  * info.
526  */
527  tables = fetch_table_list(wrconn, publications);
528  foreach(lc, tables)
529  {
530  RangeVar *rv = (RangeVar *) lfirst(lc);
531  Oid relid;
532 
533  relid = RangeVarGetRelid(rv, AccessShareLock, false);
534 
535  /* Check for supported relkind. */
537  rv->schemaname, rv->relname);
538 
539  AddSubscriptionRelState(subid, relid, table_state,
541  }
542 
543  /*
544  * If requested, create permanent slot for the subscription. We
545  * won't use the initial snapshot for anything, so no need to
546  * export it.
547  */
548  if (opts.create_slot)
549  {
550  bool twophase_enabled = false;
551 
552  Assert(opts.slot_name);
553 
554  /*
555  * Even if two_phase is set, don't create the slot with
556  * two-phase enabled. Will enable it once all the tables are
557  * synced and ready. This avoids race-conditions like prepared
558  * transactions being skipped due to changes not being applied
559  * due to checks in should_apply_changes_for_rel() when
560  * tablesync for the corresponding tables are in progress. See
561  * comments atop worker.c.
562  *
563  * Note that if tables were specified but copy_data is false
564  * then it is safe to enable two_phase up-front because those
565  * tables are already initially in READY state. When the
566  * subscription has no tables, we leave the twophase state as
567  * PENDING, to allow ALTER SUBSCRIPTION ... REFRESH
568  * PUBLICATION to work.
569  */
570  if (opts.twophase && !opts.copy_data && tables != NIL)
571  twophase_enabled = true;
572 
573  walrcv_create_slot(wrconn, opts.slot_name, false, twophase_enabled,
574  CRS_NOEXPORT_SNAPSHOT, NULL);
575 
576  if (twophase_enabled)
578 
579  ereport(NOTICE,
580  (errmsg("created replication slot \"%s\" on publisher",
581  opts.slot_name)));
582  }
583  }
584  PG_FINALLY();
585  {
586  walrcv_disconnect(wrconn);
587  }
588  PG_END_TRY();
589  }
590  else
592  /* translator: %s is an SQL ALTER statement */
593  (errmsg("tables were not subscribed, you will have to run %s to subscribe the tables",
594  "ALTER SUBSCRIPTION ... REFRESH PUBLICATION")));
595 
597 
598  if (opts.enabled)
600 
601  ObjectAddressSet(myself, SubscriptionRelationId, subid);
602 
603  InvokeObjectPostCreateHook(SubscriptionRelationId, subid, 0);
604 
605  return myself;
606 }
#define NIL
Definition: pg_list.h:65
static List * fetch_table_list(WalReceiverConn *wrconn, List *publications)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:381
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:48
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:151
bool copy_data
#define RelationGetDescr(relation)
Definition: rel.h:503
Oid GetUserId(void)
Definition: miscinit.c:495
#define LOGICALREP_TWOPHASE_STATE_DISABLED
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
#define walrcv_check_conninfo(conninfo)
Definition: walreceiver.h:406
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1974
bool create_slot
bits32 specified_opts
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
#define SUBOPT_ENABLED
RepOriginId replorigin_create(const char *roname)
Definition: origin.c:240
static Datum publicationListToArray(List *publist)
#define SUBOPT_CREATE_SLOT
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:626
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:163
#define SUBOPT_SYNCHRONOUS_COMMIT
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
static void parse_subscription_options(ParseState *pstate, List *stmt_options, bits32 supported_opts, SubOpts *opts)
#define SUBOPT_STREAMING
#define OidIsValid(objectId)
Definition: c.h:710
static WalReceiverConn * wrconn
Definition: walreceiver.c:94
char * schemaname
Definition: primnodes.h:67
#define LOGICALREP_TWOPHASE_STATE_ENABLED
#define NAMEDATALEN
char * relname
Definition: primnodes.h:68
#define SUBOPT_TWOPHASE_COMMIT
bool streaming
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define SUBOPT_CONNECT
#define SUBOPT_BINARY
void AddSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn)
#define RowExclusiveLock
Definition: lockdefs.h:38
#define LOGICALREP_TWOPHASE_STATE_PENDING
#define CStringGetDatum(X)
Definition: postgres.h:622
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3389
char * slot_name
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
static AmcheckOptions opts
Definition: pg_amcheck.c:110
#define WARNING
Definition: elog.h:40
#define PG_FINALLY()
Definition: elog.h:330
uintptr_t Datum
Definition: postgres.h:411
void UpdateTwoPhaseState(Oid suboid, char new_state)
Definition: tablesync.c:1255
Oid MyDatabaseId
Definition: globals.c:88
#define BoolGetDatum(X)
Definition: postgres.h:446
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
uint32 bits32
Definition: c.h:450
#define SUBOPT_COPY_DATA
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:195
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
#define walrcv_disconnect(conn)
Definition: walreceiver.h:432
#define SUBOPT_SLOT_NAME
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define CharGetDatum(X)
Definition: postgres.h:460
static Datum values[MAXATTR]
Definition: bootstrap.c:156
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
#define CStringGetTextDatum(s)
Definition: builtins.h:86
void ApplyLauncherWakeupAtCommit(void)
Definition: launcher.c:785
#define PG_TRY()
Definition: elog.h:313
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
Definition: pg_list.h:50
#define snprintf
Definition: port.h:216
#define IsSet(val, bits)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:221
#define PG_END_TRY()
Definition: elog.h:338
char * synchronous_commit
#define walrcv_create_slot(conn, slotname, temporary, two_phase, snapshot_action, lsn)
Definition: walreceiver.h:426
#define walrcv_connect(conninfo, logical, appname, err)
Definition: walreceiver.h:404

◆ DropSubscription()

void DropSubscription ( DropSubscriptionStmt stmt,
bool  isTopLevel 
)

Definition at line 1121 of file subscriptioncmds.c.

References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, Assert, CatalogTupleDelete(), CStringGetDatum, DatumGetName, deleteSharedDependencyRecordsFor(), ereport, errcode(), errmsg(), ERROR, EventTriggerSQLDropAddObject(), GETSTRUCT, GetSubscriptionNotReadyRelations(), GetUserId(), HeapTupleIsValid, InvalidOid, InvokeObjectDropHook, lfirst, list_free(), load_file(), LockSharedObject(), logicalrep_worker_stop(), logicalrep_workers_find(), LW_SHARED, LWLockAcquire(), LWLockRelease(), DropSubscriptionStmt::missing_ok, MyDatabaseId, NAMEDATALEN, NameStr, NIL, NoLock, NOTICE, OBJECT_SUBSCRIPTION, ObjectAddressSet, OidIsValid, PG_END_TRY, PG_FINALLY, pg_subscription_ownercheck(), PG_TRY, PreventInTransactionBlock(), pstrdup(), ReleaseSysCache(), LogicalRepWorker::relid, SubscriptionRelState::relid, RemoveSubscriptionRel(), ReplicationOriginNameForTablesync(), ReplicationSlotDropAtPubNode(), ReplicationSlotNameForTablesync(), replorigin_drop_by_name(), ReportSlotConnectionError(), SearchSysCache2(), snprintf, SubscriptionRelState::state, LogicalRepWorker::subid, subname, DropSubscriptionStmt::subname, SUBSCRIPTIONNAME, SUBSCRIPTIONOID, SysCacheGetAttr(), HeapTupleData::t_self, table_close(), table_open(), TextDatumGetCString, walrcv_connect, walrcv_disconnect, and wrconn.

Referenced by ProcessUtilitySlow().

1122 {
1123  Relation rel;
1124  ObjectAddress myself;
1125  HeapTuple tup;
1126  Oid subid;
1127  Datum datum;
1128  bool isnull;
1129  char *subname;
1130  char *conninfo;
1131  char *slotname;
1132  List *subworkers;
1133  ListCell *lc;
1134  char originname[NAMEDATALEN];
1135  char *err = NULL;
1137  Form_pg_subscription form;
1138  List *rstates;
1139 
1140  /*
1141  * Lock pg_subscription with AccessExclusiveLock to ensure that the
1142  * launcher doesn't restart new worker during dropping the subscription
1143  */
1144  rel = table_open(SubscriptionRelationId, AccessExclusiveLock);
1145 
1147  CStringGetDatum(stmt->subname));
1148 
1149  if (!HeapTupleIsValid(tup))
1150  {
1151  table_close(rel, NoLock);
1152 
1153  if (!stmt->missing_ok)
1154  ereport(ERROR,
1155  (errcode(ERRCODE_UNDEFINED_OBJECT),
1156  errmsg("subscription \"%s\" does not exist",
1157  stmt->subname)));
1158  else
1159  ereport(NOTICE,
1160  (errmsg("subscription \"%s\" does not exist, skipping",
1161  stmt->subname)));
1162 
1163  return;
1164  }
1165 
1166  form = (Form_pg_subscription) GETSTRUCT(tup);
1167  subid = form->oid;
1168 
1169  /* must be owner */
1170  if (!pg_subscription_ownercheck(subid, GetUserId()))
1172  stmt->subname);
1173 
1174  /* DROP hook for the subscription being removed */
1175  InvokeObjectDropHook(SubscriptionRelationId, subid, 0);
1176 
1177  /*
1178  * Lock the subscription so nobody else can do anything with it (including
1179  * the replication workers).
1180  */
1181  LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
1182 
1183  /* Get subname */
1184  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1185  Anum_pg_subscription_subname, &isnull);
1186  Assert(!isnull);
1187  subname = pstrdup(NameStr(*DatumGetName(datum)));
1188 
1189  /* Get conninfo */
1190  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1191  Anum_pg_subscription_subconninfo, &isnull);
1192  Assert(!isnull);
1193  conninfo = TextDatumGetCString(datum);
1194 
1195  /* Get slotname */
1196  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1197  Anum_pg_subscription_subslotname, &isnull);
1198  if (!isnull)
1199  slotname = pstrdup(NameStr(*DatumGetName(datum)));
1200  else
1201  slotname = NULL;
1202 
1203  /*
1204  * Since dropping a replication slot is not transactional, the replication
1205  * slot stays dropped even if the transaction rolls back. So we cannot
1206  * run DROP SUBSCRIPTION inside a transaction block if dropping the
1207  * replication slot.
1208  *
1209  * XXX The command name should really be something like "DROP SUBSCRIPTION
1210  * of a subscription that is associated with a replication slot", but we
1211  * don't have the proper facilities for that.
1212  */
1213  if (slotname)
1214  PreventInTransactionBlock(isTopLevel, "DROP SUBSCRIPTION");
1215 
1216  ObjectAddressSet(myself, SubscriptionRelationId, subid);
1217  EventTriggerSQLDropAddObject(&myself, true, true);
1218 
1219  /* Remove the tuple from catalog. */
1220  CatalogTupleDelete(rel, &tup->t_self);
1221 
1222  ReleaseSysCache(tup);
1223 
1224  /*
1225  * Stop all the subscription workers immediately.
1226  *
1227  * This is necessary if we are dropping the replication slot, so that the
1228  * slot becomes accessible.
1229  *
1230  * It is also necessary if the subscription is disabled and was disabled
1231  * in the same transaction. Then the workers haven't seen the disabling
1232  * yet and will still be running, leading to hangs later when we want to
1233  * drop the replication origin. If the subscription was disabled before
1234  * this transaction, then there shouldn't be any workers left, so this
1235  * won't make a difference.
1236  *
1237  * New workers won't be started because we hold an exclusive lock on the
1238  * subscription till the end of the transaction.
1239  */
1240  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
1241  subworkers = logicalrep_workers_find(subid, false);
1242  LWLockRelease(LogicalRepWorkerLock);
1243  foreach(lc, subworkers)
1244  {
1246 
1248  }
1249  list_free(subworkers);
1250 
1251  /*
1252  * Cleanup of tablesync replication origins.
1253  *
1254  * Any READY-state relations would already have dealt with clean-ups.
1255  *
1256  * Note that the state can't change because we have already stopped both
1257  * the apply and tablesync workers and they can't restart because of
1258  * exclusive lock on the subscription.
1259  */
1260  rstates = GetSubscriptionNotReadyRelations(subid);
1261  foreach(lc, rstates)
1262  {
1264  Oid relid = rstate->relid;
1265 
1266  /* Only cleanup resources of tablesync workers */
1267  if (!OidIsValid(relid))
1268  continue;
1269 
1270  /*
1271  * Drop the tablesync's origin tracking if exists.
1272  *
1273  * It is possible that the origin is not yet created for tablesync
1274  * worker so passing missing_ok = true. This can happen for the states
1275  * before SUBREL_STATE_FINISHEDCOPY.
1276  */
1277  ReplicationOriginNameForTablesync(subid, relid, originname,
1278  sizeof(originname));
1279  replorigin_drop_by_name(originname, true, false);
1280  }
1281 
1282  /* Clean up dependencies */
1283  deleteSharedDependencyRecordsFor(SubscriptionRelationId, subid, 0);
1284 
1285  /* Remove any associated relation synchronization states. */
1287 
1288  /* Remove the origin tracking if exists. */
1289  snprintf(originname, sizeof(originname), "pg_%u", subid);
1290  replorigin_drop_by_name(originname, true, false);
1291 
1292  /*
1293  * If there is no slot associated with the subscription, we can finish
1294  * here.
1295  */
1296  if (!slotname && rstates == NIL)
1297  {
1298  table_close(rel, NoLock);
1299  return;
1300  }
1301 
1302  /*
1303  * Try to acquire the connection necessary for dropping slots.
1304  *
1305  * Note: If the slotname is NONE/NULL then we allow the command to finish
1306  * and users need to manually cleanup the apply and tablesync worker slots
1307  * later.
1308  *
1309  * This has to be at the end because otherwise if there is an error while
1310  * doing the database operations we won't be able to rollback dropped
1311  * slot.
1312  */
1313  load_file("libpqwalreceiver", false);
1314 
1315  wrconn = walrcv_connect(conninfo, true, subname, &err);
1316  if (wrconn == NULL)
1317  {
1318  if (!slotname)
1319  {
1320  /* be tidy */
1321  list_free(rstates);
1322  table_close(rel, NoLock);
1323  return;
1324  }
1325  else
1326  {
1327  ReportSlotConnectionError(rstates, subid, slotname, err);
1328  }
1329  }
1330 
1331  PG_TRY();
1332  {
1333  foreach(lc, rstates)
1334  {
1336  Oid relid = rstate->relid;
1337 
1338  /* Only cleanup resources of tablesync workers */
1339  if (!OidIsValid(relid))
1340  continue;
1341 
1342  /*
1343  * Drop the tablesync slots associated with removed tables.
1344  *
1345  * For SYNCDONE/READY states, the tablesync slot is known to have
1346  * already been dropped by the tablesync worker.
1347  *
1348  * For other states, there is no certainty, maybe the slot does
1349  * not exist yet. Also, if we fail after removing some of the
1350  * slots, next time, it will again try to drop already dropped
1351  * slots and fail. For these reasons, we allow missing_ok = true
1352  * for the drop.
1353  */
1354  if (rstate->state != SUBREL_STATE_SYNCDONE)
1355  {
1356  char syncslotname[NAMEDATALEN] = {0};
1357 
1358  ReplicationSlotNameForTablesync(subid, relid, syncslotname,
1359  sizeof(syncslotname));
1360  ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
1361  }
1362  }
1363 
1364  list_free(rstates);
1365 
1366  /*
1367  * If there is a slot associated with the subscription, then drop the
1368  * replication slot at the publisher.
1369  */
1370  if (slotname)
1371  ReplicationSlotDropAtPubNode(wrconn, slotname, false);
1372 
1373  }
1374  PG_FINALLY();
1375  {
1376  walrcv_disconnect(wrconn);
1377  }
1378  PG_END_TRY();
1379 
1380  table_close(rel, NoLock);
1381 }
#define NIL
Definition: pg_list.h:65
List * logicalrep_workers_find(Oid subid, bool only_running)
Definition: launcher.c:243
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
void RemoveSubscriptionRel(Oid subid, Oid relid)
void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok)
Oid GetUserId(void)
Definition: miscinit.c:495
char * pstrdup(const char *in)
Definition: mcxt.c:1299
#define InvokeObjectDropHook(classId, objectId, subId)
Definition: objectaccess.h:160
void replorigin_drop_by_name(const char *name, bool missing_ok, bool nowait)
Definition: origin.c:414
static void ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
int errcode(int sqlerrcode)
Definition: elog.c:698
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:350
FormData_pg_subscription * Form_pg_subscription
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
#define OidIsValid(objectId)
Definition: c.h:710
static WalReceiverConn * wrconn
Definition: walreceiver.c:94
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define NAMEDATALEN
#define DatumGetName(X)
Definition: postgres.h:629
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
#define ERROR
Definition: elog.h:46
ItemPointerData t_self
Definition: htup.h:65
#define NoLock
Definition: lockdefs.h:34
void logicalrep_worker_stop(Oid subid, Oid relid)
Definition: launcher.c:437
#define CStringGetDatum(X)
Definition: postgres.h:622
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3389
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:997
#define PG_FINALLY()
Definition: elog.h:330
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
Oid MyDatabaseId
Definition: globals.c:88
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1017
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1138
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname, int szorgname)
Definition: tablesync.c:905
#define walrcv_disconnect(conn)
Definition: walreceiver.h:432
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define AccessExclusiveLock
Definition: lockdefs.h:45
int errmsg(const char *fmt,...)
Definition: elog.c:909
void list_free(List *list)
Definition: list.c:1391
#define NameStr(name)
Definition: c.h:681
#define PG_TRY()
Definition: elog.h:313
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
List * GetSubscriptionNotReadyRelations(Oid subid)
#define snprintf
Definition: port.h:216
#define PG_END_TRY()
Definition: elog.h:338
void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot)
Definition: tablesync.c:892
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5382
#define walrcv_connect(conninfo, logical, appname, err)
Definition: walreceiver.h:404