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 965 of file subscriptioncmds.c.

967 {
968  Relation rel;
969  ObjectAddress myself;
970  bool nulls[Natts_pg_subscription];
971  bool replaces[Natts_pg_subscription];
972  Datum values[Natts_pg_subscription];
973  HeapTuple tup;
974  Oid subid;
975  bool update_tuple = false;
976  Subscription *sub;
978  bits32 supported_opts;
979  SubOpts opts = {0};
980 
981  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
982 
983  /* Fetch the existing tuple. */
985  CStringGetDatum(stmt->subname));
986 
987  if (!HeapTupleIsValid(tup))
988  ereport(ERROR,
989  (errcode(ERRCODE_UNDEFINED_OBJECT),
990  errmsg("subscription \"%s\" does not exist",
991  stmt->subname)));
992 
993  form = (Form_pg_subscription) GETSTRUCT(tup);
994  subid = form->oid;
995 
996  /* must be owner */
997  if (!pg_subscription_ownercheck(subid, GetUserId()))
999  stmt->subname);
1000 
1001  sub = GetSubscription(subid, false);
1002 
1003  /* Lock the subscription so nobody else can do anything with it. */
1004  LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
1005 
1006  /* Form a new tuple. */
1007  memset(values, 0, sizeof(values));
1008  memset(nulls, false, sizeof(nulls));
1009  memset(replaces, false, sizeof(replaces));
1010 
1011  switch (stmt->kind)
1012  {
1014  {
1015  supported_opts = (SUBOPT_SLOT_NAME |
1018 
1019  parse_subscription_options(pstate, stmt->options,
1020  supported_opts, &opts);
1021 
1022  if (IsSet(opts.specified_opts, SUBOPT_SLOT_NAME))
1023  {
1024  /*
1025  * The subscription must be disabled to allow slot_name as
1026  * 'none', otherwise, the apply worker will repeatedly try
1027  * to stream the data using that slot_name which neither
1028  * exists on the publisher nor the user will be allowed to
1029  * create it.
1030  */
1031  if (sub->enabled && !opts.slot_name)
1032  ereport(ERROR,
1033  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1034  errmsg("cannot set %s for enabled subscription",
1035  "slot_name = NONE")));
1036 
1037  if (opts.slot_name)
1038  values[Anum_pg_subscription_subslotname - 1] =
1040  else
1041  nulls[Anum_pg_subscription_subslotname - 1] = true;
1042  replaces[Anum_pg_subscription_subslotname - 1] = true;
1043  }
1044 
1045  if (opts.synchronous_commit)
1046  {
1047  values[Anum_pg_subscription_subsynccommit - 1] =
1048  CStringGetTextDatum(opts.synchronous_commit);
1049  replaces[Anum_pg_subscription_subsynccommit - 1] = true;
1050  }
1051 
1052  if (IsSet(opts.specified_opts, SUBOPT_BINARY))
1053  {
1054  values[Anum_pg_subscription_subbinary - 1] =
1055  BoolGetDatum(opts.binary);
1056  replaces[Anum_pg_subscription_subbinary - 1] = true;
1057  }
1058 
1059  if (IsSet(opts.specified_opts, SUBOPT_STREAMING))
1060  {
1061  values[Anum_pg_subscription_substream - 1] =
1062  BoolGetDatum(opts.streaming);
1063  replaces[Anum_pg_subscription_substream - 1] = true;
1064  }
1065 
1066  if (IsSet(opts.specified_opts, SUBOPT_DISABLE_ON_ERR))
1067  {
1068  values[Anum_pg_subscription_subdisableonerr - 1]
1069  = BoolGetDatum(opts.disableonerr);
1070  replaces[Anum_pg_subscription_subdisableonerr - 1]
1071  = true;
1072  }
1073 
1074  update_tuple = true;
1075  break;
1076  }
1077 
1079  {
1080  parse_subscription_options(pstate, stmt->options,
1081  SUBOPT_ENABLED, &opts);
1082  Assert(IsSet(opts.specified_opts, SUBOPT_ENABLED));
1083 
1084  if (!sub->slotname && opts.enabled)
1085  ereport(ERROR,
1086  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1087  errmsg("cannot enable subscription that does not have a slot name")));
1088 
1089  values[Anum_pg_subscription_subenabled - 1] =
1090  BoolGetDatum(opts.enabled);
1091  replaces[Anum_pg_subscription_subenabled - 1] = true;
1092 
1093  if (opts.enabled)
1095 
1096  update_tuple = true;
1097  break;
1098  }
1099 
1101  /* Load the library providing us libpq calls. */
1102  load_file("libpqwalreceiver", false);
1103  /* Check the connection info string. */
1105 
1106  values[Anum_pg_subscription_subconninfo - 1] =
1108  replaces[Anum_pg_subscription_subconninfo - 1] = true;
1109  update_tuple = true;
1110  break;
1111 
1113  {
1114  supported_opts = SUBOPT_COPY_DATA | SUBOPT_REFRESH;
1115  parse_subscription_options(pstate, stmt->options,
1116  supported_opts, &opts);
1117 
1118  values[Anum_pg_subscription_subpublications - 1] =
1120  replaces[Anum_pg_subscription_subpublications - 1] = true;
1121 
1122  update_tuple = true;
1123 
1124  /* Refresh if user asked us to. */
1125  if (opts.refresh)
1126  {
1127  if (!sub->enabled)
1128  ereport(ERROR,
1129  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1130  errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
1131  errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
1132 
1133  /*
1134  * See ALTER_SUBSCRIPTION_REFRESH for details why this is
1135  * not allowed.
1136  */
1137  if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_ENABLED && opts.copy_data)
1138  ereport(ERROR,
1139  (errcode(ERRCODE_SYNTAX_ERROR),
1140  errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
1141  errhint("Use ALTER SUBSCRIPTION ...SET PUBLICATION with refresh = false, or with copy_data = false"
1142  ", or use DROP/CREATE SUBSCRIPTION.")));
1143 
1144  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
1145 
1146  /* Make sure refresh sees the new list of publications. */
1147  sub->publications = stmt->publication;
1148 
1149  AlterSubscription_refresh(sub, opts.copy_data,
1150  stmt->publication);
1151  }
1152 
1153  break;
1154  }
1155 
1158  {
1159  List *publist;
1160  bool isadd = stmt->kind == ALTER_SUBSCRIPTION_ADD_PUBLICATION;
1161 
1162  supported_opts = SUBOPT_REFRESH | SUBOPT_COPY_DATA;
1163  parse_subscription_options(pstate, stmt->options,
1164  supported_opts, &opts);
1165 
1166  publist = merge_publications(sub->publications, stmt->publication, isadd, stmt->subname);
1167  values[Anum_pg_subscription_subpublications - 1] =
1168  publicationListToArray(publist);
1169  replaces[Anum_pg_subscription_subpublications - 1] = true;
1170 
1171  update_tuple = true;
1172 
1173  /* Refresh if user asked us to. */
1174  if (opts.refresh)
1175  {
1176  /* We only need to validate user specified publications. */
1177  List *validate_publications = (isadd) ? stmt->publication : NULL;
1178 
1179  if (!sub->enabled)
1180  ereport(ERROR,
1181  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1182  errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
1183  errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
1184 
1185  /*
1186  * See ALTER_SUBSCRIPTION_REFRESH for details why this is
1187  * not allowed.
1188  */
1189  if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_ENABLED && opts.copy_data)
1190  ereport(ERROR,
1191  (errcode(ERRCODE_SYNTAX_ERROR),
1192  errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
1193  errhint("Use ALTER SUBSCRIPTION ...SET PUBLICATION with refresh = false, or with copy_data = false"
1194  ", or use DROP/CREATE SUBSCRIPTION.")));
1195 
1196  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
1197 
1198  /* Refresh the new list of publications. */
1199  sub->publications = publist;
1200 
1201  AlterSubscription_refresh(sub, opts.copy_data,
1202  validate_publications);
1203  }
1204 
1205  break;
1206  }
1207 
1209  {
1210  if (!sub->enabled)
1211  ereport(ERROR,
1212  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1213  errmsg("ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions")));
1214 
1215  parse_subscription_options(pstate, stmt->options,
1217 
1218  /*
1219  * The subscription option "two_phase" requires that
1220  * replication has passed the initial table synchronization
1221  * phase before the two_phase becomes properly enabled.
1222  *
1223  * But, having reached this two-phase commit "enabled" state
1224  * we must not allow any subsequent table initialization to
1225  * occur. So the ALTER SUBSCRIPTION ... REFRESH is disallowed
1226  * when the user had requested two_phase = on mode.
1227  *
1228  * The exception to this restriction is when copy_data =
1229  * false, because when copy_data is false the tablesync will
1230  * start already in READY state and will exit directly without
1231  * doing anything.
1232  *
1233  * For more details see comments atop worker.c.
1234  */
1235  if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_ENABLED && opts.copy_data)
1236  ereport(ERROR,
1237  (errcode(ERRCODE_SYNTAX_ERROR),
1238  errmsg("ALTER SUBSCRIPTION ... REFRESH with copy_data is not allowed when two_phase is enabled"),
1239  errhint("Use ALTER SUBSCRIPTION ... REFRESH with copy_data = false"
1240  ", or use DROP/CREATE SUBSCRIPTION.")));
1241 
1242  PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION ... REFRESH");
1243 
1244  AlterSubscription_refresh(sub, opts.copy_data, NULL);
1245 
1246  break;
1247  }
1248 
1250  {
1252 
1253  /* ALTER SUBSCRIPTION ... SKIP supports only LSN option */
1254  Assert(IsSet(opts.specified_opts, SUBOPT_LSN));
1255 
1256  if (!superuser())
1257  ereport(ERROR,
1258  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1259  errmsg("must be superuser to skip transaction")));
1260 
1261  /*
1262  * If the user sets subskiplsn, we do a sanity check to make
1263  * sure that the specified LSN is a probable value.
1264  */
1265  if (!XLogRecPtrIsInvalid(opts.lsn))
1266  {
1267  RepOriginId originid;
1268  char originname[NAMEDATALEN];
1269  XLogRecPtr remote_lsn;
1270 
1271  snprintf(originname, sizeof(originname), "pg_%u", subid);
1272  originid = replorigin_by_name(originname, false);
1273  remote_lsn = replorigin_get_progress(originid, false);
1274 
1275  /* Check the given LSN is at least a future LSN */
1276  if (!XLogRecPtrIsInvalid(remote_lsn) && opts.lsn < remote_lsn)
1277  ereport(ERROR,
1278  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1279  errmsg("skip WAL location (LSN %X/%X) must be greater than origin LSN %X/%X",
1280  LSN_FORMAT_ARGS(opts.lsn),
1281  LSN_FORMAT_ARGS(remote_lsn))));
1282  }
1283 
1284  values[Anum_pg_subscription_subskiplsn - 1] = LSNGetDatum(opts.lsn);
1285  replaces[Anum_pg_subscription_subskiplsn - 1] = true;
1286 
1287  update_tuple = true;
1288  break;
1289  }
1290 
1291  default:
1292  elog(ERROR, "unrecognized ALTER SUBSCRIPTION kind %d",
1293  stmt->kind);
1294  }
1295 
1296  /* Update the catalog if needed. */
1297  if (update_tuple)
1298  {
1299  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
1300  replaces);
1301 
1302  CatalogTupleUpdate(rel, &tup->t_self, tup);
1303 
1304  heap_freetuple(tup);
1305  }
1306 
1308 
1309  ObjectAddressSet(myself, SubscriptionRelationId, subid);
1310 
1311  InvokeObjectPostAlterHook(SubscriptionRelationId, subid, 0);
1312 
1313  return myself;
1314 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5735
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3512
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
uint32 bits32
Definition: c.h:461
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:144
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:631
Oid MyDatabaseId
Definition: globals.c:89
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
void ApplyLauncherWakeupAtCommit(void)
Definition: launcher.c:784
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:491
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:48
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:195
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
RepOriginId replorigin_by_name(const char *roname, bool missing_ok)
Definition: origin.c:209
XLogRecPtr replorigin_get_progress(RepOriginId node, bool flush)
Definition: origin.c:998
@ ALTER_SUBSCRIPTION_ENABLED
Definition: parsenodes.h:4076
@ ALTER_SUBSCRIPTION_DROP_PUBLICATION
Definition: parsenodes.h:4074
@ ALTER_SUBSCRIPTION_SET_PUBLICATION
Definition: parsenodes.h:4072
@ ALTER_SUBSCRIPTION_REFRESH
Definition: parsenodes.h:4075
@ ALTER_SUBSCRIPTION_SKIP
Definition: parsenodes.h:4077
@ ALTER_SUBSCRIPTION_OPTIONS
Definition: parsenodes.h:4070
@ ALTER_SUBSCRIPTION_CONNECTION
Definition: parsenodes.h:4071
@ ALTER_SUBSCRIPTION_ADD_PUBLICATION
Definition: parsenodes.h:4073
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2173
static AmcheckOptions opts
Definition: pg_amcheck.c:110
#define NAMEDATALEN
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
Subscription * GetSubscription(Oid subid, bool missing_ok)
#define LOGICALREP_TWOPHASE_STATE_ENABLED
FormData_pg_subscription * Form_pg_subscription
#define snprintf
Definition: port.h:225
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define BoolGetDatum(X)
Definition: postgres.h:446
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:514
AlterSubscriptionType kind
Definition: parsenodes.h:4083
ItemPointerData t_self
Definition: htup.h:65
Definition: pg_list.h:52
#define SUBOPT_STREAMING
#define SUBOPT_SYNCHRONOUS_COMMIT
#define SUBOPT_ENABLED
static Datum publicationListToArray(List *publist)
static void parse_subscription_options(ParseState *pstate, List *stmt_options, bits32 supported_opts, SubOpts *opts)
#define SUBOPT_SLOT_NAME
#define SUBOPT_COPY_DATA
static void AlterSubscription_refresh(Subscription *sub, bool copy_data, List *validate_publications)
#define SUBOPT_DISABLE_ON_ERR
#define SUBOPT_LSN
static List * merge_publications(List *oldpublist, List *newpublist, bool addpub, const char *subname)
#define SUBOPT_BINARY
#define IsSet(val, bits)
#define SUBOPT_REFRESH
bool superuser(void)
Definition: superuser.c:46
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:181
@ SUBSCRIPTIONNAME
Definition: syscache.h:98
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define walrcv_check_conninfo(conninfo)
Definition: walreceiver.h:406
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3462
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
uint16 RepOriginId
Definition: xlogdefs.h:65
uint64 XLogRecPtr
Definition: xlogdefs.h:21

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, ALTER_SUBSCRIPTION_SKIP, AlterSubscription_refresh(), ApplyLauncherWakeupAtCommit(), Assert(), BoolGetDatum, CatalogTupleUpdate(), AlterSubscriptionStmt::conninfo, CStringGetDatum, CStringGetTextDatum, DirectFunctionCall1, elog(), Subscription::enabled, ereport, errcode(), errhint(), errmsg(), ERROR, GETSTRUCT, GetSubscription(), GetUserId(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, if(), InvokeObjectPostAlterHook, IsSet, AlterSubscriptionStmt::kind, load_file(), LockSharedObject(), LOGICALREP_TWOPHASE_STATE_ENABLED, LSN_FORMAT_ARGS, LSNGetDatum, merge_publications(), MyDatabaseId, NAMEDATALEN, namein(), OBJECT_SUBSCRIPTION, ObjectAddressSet, AlterSubscriptionStmt::options, opts, parse_subscription_options(), pg_subscription_ownercheck(), PreventInTransactionBlock(), AlterSubscriptionStmt::publication, publicationListToArray(), Subscription::publications, RelationGetDescr, replorigin_by_name(), replorigin_get_progress(), RowExclusiveLock, SearchSysCacheCopy2, Subscription::slotname, snprintf, AlterSubscriptionStmt::subname, SUBOPT_BINARY, SUBOPT_COPY_DATA, SUBOPT_DISABLE_ON_ERR, SUBOPT_ENABLED, SUBOPT_LSN, SUBOPT_REFRESH, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBSCRIPTIONNAME, superuser(), HeapTupleData::t_self, table_close(), table_open(), Subscription::twophasestate, values, walrcv_check_conninfo, and XLogRecPtrIsInvalid.

Referenced by ProcessUtilitySlow().

◆ AlterSubscriptionOwner()

ObjectAddress AlterSubscriptionOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 1696 of file subscriptioncmds.c.

1697 {
1698  Oid subid;
1699  HeapTuple tup;
1700  Relation rel;
1701  ObjectAddress address;
1702  Form_pg_subscription form;
1703 
1704  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
1705 
1708 
1709  if (!HeapTupleIsValid(tup))
1710  ereport(ERROR,
1711  (errcode(ERRCODE_UNDEFINED_OBJECT),
1712  errmsg("subscription \"%s\" does not exist", name)));
1713 
1714  form = (Form_pg_subscription) GETSTRUCT(tup);
1715  subid = form->oid;
1716 
1717  AlterSubscriptionOwner_internal(rel, tup, newOwnerId);
1718 
1719  ObjectAddressSet(address, SubscriptionRelationId, subid);
1720 
1721  heap_freetuple(tup);
1722 
1724 
1725  return address;
1726 }
const char * name
Definition: encode.c:561
static void AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)

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

Referenced by ExecAlterOwnerStmt().

◆ AlterSubscriptionOwner_oid()

void AlterSubscriptionOwner_oid ( Oid  subid,
Oid  newOwnerId 
)

Definition at line 1732 of file subscriptioncmds.c.

1733 {
1734  HeapTuple tup;
1735  Relation rel;
1736 
1737  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
1738 
1740 
1741  if (!HeapTupleIsValid(tup))
1742  ereport(ERROR,
1743  (errcode(ERRCODE_UNDEFINED_OBJECT),
1744  errmsg("subscription with OID %u does not exist", subid)));
1745 
1746  AlterSubscriptionOwner_internal(rel, tup, newOwnerId);
1747 
1748  heap_freetuple(tup);
1749 
1751 }
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179
@ SUBSCRIPTIONOID
Definition: syscache.h:99

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

Referenced by shdepReassignOwned().

◆ CreateSubscription()

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

Definition at line 508 of file subscriptioncmds.c.

510 {
511  Relation rel;
512  ObjectAddress myself;
513  Oid subid;
514  bool nulls[Natts_pg_subscription];
515  Datum values[Natts_pg_subscription];
516  Oid owner = GetUserId();
517  HeapTuple tup;
518  char *conninfo;
519  char originname[NAMEDATALEN];
520  List *publications;
521  bits32 supported_opts;
522  SubOpts opts = {0};
523 
524  /*
525  * Parse and check options.
526  *
527  * Connection and publication should not be specified here.
528  */
529  supported_opts = (SUBOPT_CONNECT | SUBOPT_ENABLED | SUBOPT_CREATE_SLOT |
534  parse_subscription_options(pstate, stmt->options, supported_opts, &opts);
535 
536  /*
537  * Since creating a replication slot is not transactional, rolling back
538  * the transaction leaves the created replication slot. So we cannot run
539  * CREATE SUBSCRIPTION inside a transaction block if creating a
540  * replication slot.
541  */
542  if (opts.create_slot)
543  PreventInTransactionBlock(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");
544 
545  if (!superuser())
546  ereport(ERROR,
547  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
548  errmsg("must be superuser to create subscriptions")));
549 
550  /*
551  * If built with appropriate switch, whine when regression-testing
552  * conventions for subscription names are violated.
553  */
554 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
555  if (strncmp(stmt->subname, "regress_", 8) != 0)
556  elog(WARNING, "subscriptions created by regression test cases should have names starting with \"regress_\"");
557 #endif
558 
559  rel = table_open(SubscriptionRelationId, RowExclusiveLock);
560 
561  /* Check if name is used */
562  subid = GetSysCacheOid2(SUBSCRIPTIONNAME, Anum_pg_subscription_oid,
564  if (OidIsValid(subid))
565  {
566  ereport(ERROR,
568  errmsg("subscription \"%s\" already exists",
569  stmt->subname)));
570  }
571 
572  if (!IsSet(opts.specified_opts, SUBOPT_SLOT_NAME) &&
573  opts.slot_name == NULL)
574  opts.slot_name = stmt->subname;
575 
576  /* The default for synchronous_commit of subscriptions is off. */
577  if (opts.synchronous_commit == NULL)
578  opts.synchronous_commit = "off";
579 
580  conninfo = stmt->conninfo;
581  publications = stmt->publication;
582 
583  /* Load the library providing us libpq calls. */
584  load_file("libpqwalreceiver", false);
585 
586  /* Check the connection info string. */
587  walrcv_check_conninfo(conninfo);
588 
589  /* Everything ok, form a new tuple. */
590  memset(values, 0, sizeof(values));
591  memset(nulls, false, sizeof(nulls));
592 
593  subid = GetNewOidWithIndex(rel, SubscriptionObjectIndexId,
594  Anum_pg_subscription_oid);
595  values[Anum_pg_subscription_oid - 1] = ObjectIdGetDatum(subid);
596  values[Anum_pg_subscription_subdbid - 1] = ObjectIdGetDatum(MyDatabaseId);
597  values[Anum_pg_subscription_subskiplsn - 1] = LSNGetDatum(InvalidXLogRecPtr);
598  values[Anum_pg_subscription_subname - 1] =
600  values[Anum_pg_subscription_subowner - 1] = ObjectIdGetDatum(owner);
601  values[Anum_pg_subscription_subenabled - 1] = BoolGetDatum(opts.enabled);
602  values[Anum_pg_subscription_subbinary - 1] = BoolGetDatum(opts.binary);
603  values[Anum_pg_subscription_substream - 1] = BoolGetDatum(opts.streaming);
604  values[Anum_pg_subscription_subtwophasestate - 1] =
605  CharGetDatum(opts.twophase ?
608  values[Anum_pg_subscription_subdisableonerr - 1] = BoolGetDatum(opts.disableonerr);
609  values[Anum_pg_subscription_subconninfo - 1] =
610  CStringGetTextDatum(conninfo);
611  if (opts.slot_name)
612  values[Anum_pg_subscription_subslotname - 1] =
614  else
615  nulls[Anum_pg_subscription_subslotname - 1] = true;
616  values[Anum_pg_subscription_subsynccommit - 1] =
617  CStringGetTextDatum(opts.synchronous_commit);
618  values[Anum_pg_subscription_subpublications - 1] =
619  publicationListToArray(publications);
620 
621  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
622 
623  /* Insert tuple into catalog. */
624  CatalogTupleInsert(rel, tup);
625  heap_freetuple(tup);
626 
627  recordDependencyOnOwner(SubscriptionRelationId, subid, owner);
628 
629  snprintf(originname, sizeof(originname), "pg_%u", subid);
630  replorigin_create(originname);
631 
632  /*
633  * Connect to remote side to execute requested commands and fetch table
634  * info.
635  */
636  if (opts.connect)
637  {
638  char *err;
640  List *tables;
641  ListCell *lc;
642  char table_state;
643 
644  /* Try to connect to the publisher. */
645  wrconn = walrcv_connect(conninfo, true, stmt->subname, &err);
646  if (!wrconn)
647  ereport(ERROR,
648  (errcode(ERRCODE_CONNECTION_FAILURE),
649  errmsg("could not connect to the publisher: %s", err)));
650 
651  PG_TRY();
652  {
653  check_publications(wrconn, publications);
654 
655  /*
656  * Set sync state based on if we were asked to do data copy or
657  * not.
658  */
659  table_state = opts.copy_data ? SUBREL_STATE_INIT : SUBREL_STATE_READY;
660 
661  /*
662  * Get the table list from publisher and build local table status
663  * info.
664  */
665  tables = fetch_table_list(wrconn, publications);
666  foreach(lc, tables)
667  {
668  RangeVar *rv = (RangeVar *) lfirst(lc);
669  Oid relid;
670 
671  relid = RangeVarGetRelid(rv, AccessShareLock, false);
672 
673  /* Check for supported relkind. */
675  rv->schemaname, rv->relname);
676 
677  AddSubscriptionRelState(subid, relid, table_state,
679  }
680 
681  /*
682  * If requested, create permanent slot for the subscription. We
683  * won't use the initial snapshot for anything, so no need to
684  * export it.
685  */
686  if (opts.create_slot)
687  {
688  bool twophase_enabled = false;
689 
690  Assert(opts.slot_name);
691 
692  /*
693  * Even if two_phase is set, don't create the slot with
694  * two-phase enabled. Will enable it once all the tables are
695  * synced and ready. This avoids race-conditions like prepared
696  * transactions being skipped due to changes not being applied
697  * due to checks in should_apply_changes_for_rel() when
698  * tablesync for the corresponding tables are in progress. See
699  * comments atop worker.c.
700  *
701  * Note that if tables were specified but copy_data is false
702  * then it is safe to enable two_phase up-front because those
703  * tables are already initially in READY state. When the
704  * subscription has no tables, we leave the twophase state as
705  * PENDING, to allow ALTER SUBSCRIPTION ... REFRESH
706  * PUBLICATION to work.
707  */
708  if (opts.twophase && !opts.copy_data && tables != NIL)
709  twophase_enabled = true;
710 
711  walrcv_create_slot(wrconn, opts.slot_name, false, twophase_enabled,
712  CRS_NOEXPORT_SNAPSHOT, NULL);
713 
714  if (twophase_enabled)
716 
717  ereport(NOTICE,
718  (errmsg("created replication slot \"%s\" on publisher",
719  opts.slot_name)));
720  }
721  }
722  PG_FINALLY();
723  {
725  }
726  PG_END_TRY();
727  }
728  else
730  /* translator: %s is an SQL ALTER statement */
731  (errmsg("tables were not subscribed, you will have to run %s to subscribe the tables",
732  "ALTER SUBSCRIPTION ... REFRESH PUBLICATION")));
733 
735 
737 
738  if (opts.enabled)
740 
741  ObjectAddressSet(myself, SubscriptionRelationId, subid);
742 
743  InvokeObjectPostCreateHook(SubscriptionRelationId, subid, 0);
744 
745  return myself;
746 }
#define OidIsValid(objectId)
Definition: c.h:721
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:391
#define PG_END_TRY()
Definition: elog.h:324
#define PG_TRY()
Definition: elog.h:299
#define WARNING
Definition: elog.h:30
#define PG_FINALLY()
Definition: elog.h:316
#define NOTICE
Definition: elog.h:29
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:221
#define AccessShareLock
Definition: lockdefs.h:36
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1984
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:171
RepOriginId replorigin_create(const char *roname)
Definition: origin.c:240
#define lfirst(lc)
Definition: pg_list.h:170
#define NIL
Definition: pg_list.h:66
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:164
void AddSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn)
#define LOGICALREP_TWOPHASE_STATE_DISABLED
#define LOGICALREP_TWOPHASE_STATE_PENDING
void pgstat_create_subscription(Oid subid)
#define CharGetDatum(X)
Definition: postgres.h:460
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
char * relname
Definition: primnodes.h:74
char * schemaname
Definition: primnodes.h:71
#define SUBOPT_CREATE_SLOT
static void check_publications(WalReceiverConn *wrconn, List *publications)
#define SUBOPT_TWOPHASE_COMMIT
static List * fetch_table_list(WalReceiverConn *wrconn, List *publications)
#define SUBOPT_CONNECT
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:199
void UpdateTwoPhaseState(Oid suboid, char new_state)
Definition: tablesync.c:1544
static WalReceiverConn * wrconn
Definition: walreceiver.c:95
#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
#define walrcv_disconnect(conn)
Definition: walreceiver.h:432
@ CRS_NOEXPORT_SNAPSHOT
Definition: walsender.h:23
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References AccessShareLock, AddSubscriptionRelState(), ApplyLauncherWakeupAtCommit(), Assert(), BoolGetDatum, CatalogTupleInsert(), CharGetDatum, check_publications(), CheckSubscriptionRelkind(), CreateSubscriptionStmt::conninfo, CRS_NOEXPORT_SNAPSHOT, CStringGetDatum, CStringGetTextDatum, DirectFunctionCall1, elog(), 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, LSNGetDatum, MyDatabaseId, NAMEDATALEN, namein(), NIL, NOTICE, ObjectAddressSet, ObjectIdGetDatum, OidIsValid, CreateSubscriptionStmt::options, opts, parse_subscription_options(), PG_END_TRY, PG_FINALLY, PG_TRY, pgstat_create_subscription(), PreventInTransactionBlock(), CreateSubscriptionStmt::publication, publicationListToArray(), RangeVarGetRelid, recordDependencyOnOwner(), RelationGetDescr, RangeVar::relname, replorigin_create(), RowExclusiveLock, RangeVar::schemaname, snprintf, CreateSubscriptionStmt::subname, SUBOPT_BINARY, SUBOPT_CONNECT, SUBOPT_COPY_DATA, SUBOPT_CREATE_SLOT, SUBOPT_DISABLE_ON_ERR, SUBOPT_ENABLED, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, SUBSCRIPTIONNAME, superuser(), table_close(), table_open(), UpdateTwoPhaseState(), values, walrcv_check_conninfo, walrcv_connect, walrcv_create_slot, walrcv_disconnect, WARNING, and wrconn.

Referenced by ProcessUtilitySlow().

◆ DropSubscription()

void DropSubscription ( DropSubscriptionStmt stmt,
bool  isTopLevel 
)

Definition at line 1320 of file subscriptioncmds.c.

1321 {
1322  Relation rel;
1323  ObjectAddress myself;
1324  HeapTuple tup;
1325  Oid subid;
1326  Datum datum;
1327  bool isnull;
1328  char *subname;
1329  char *conninfo;
1330  char *slotname;
1331  List *subworkers;
1332  ListCell *lc;
1333  char originname[NAMEDATALEN];
1334  char *err = NULL;
1336  Form_pg_subscription form;
1337  List *rstates;
1338 
1339  /*
1340  * Lock pg_subscription with AccessExclusiveLock to ensure that the
1341  * launcher doesn't restart new worker during dropping the subscription
1342  */
1343  rel = table_open(SubscriptionRelationId, AccessExclusiveLock);
1344 
1346  CStringGetDatum(stmt->subname));
1347 
1348  if (!HeapTupleIsValid(tup))
1349  {
1350  table_close(rel, NoLock);
1351 
1352  if (!stmt->missing_ok)
1353  ereport(ERROR,
1354  (errcode(ERRCODE_UNDEFINED_OBJECT),
1355  errmsg("subscription \"%s\" does not exist",
1356  stmt->subname)));
1357  else
1358  ereport(NOTICE,
1359  (errmsg("subscription \"%s\" does not exist, skipping",
1360  stmt->subname)));
1361 
1362  return;
1363  }
1364 
1365  form = (Form_pg_subscription) GETSTRUCT(tup);
1366  subid = form->oid;
1367 
1368  /* must be owner */
1369  if (!pg_subscription_ownercheck(subid, GetUserId()))
1371  stmt->subname);
1372 
1373  /* DROP hook for the subscription being removed */
1374  InvokeObjectDropHook(SubscriptionRelationId, subid, 0);
1375 
1376  /*
1377  * Lock the subscription so nobody else can do anything with it (including
1378  * the replication workers).
1379  */
1380  LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
1381 
1382  /* Get subname */
1383  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1384  Anum_pg_subscription_subname, &isnull);
1385  Assert(!isnull);
1386  subname = pstrdup(NameStr(*DatumGetName(datum)));
1387 
1388  /* Get conninfo */
1389  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1390  Anum_pg_subscription_subconninfo, &isnull);
1391  Assert(!isnull);
1392  conninfo = TextDatumGetCString(datum);
1393 
1394  /* Get slotname */
1395  datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
1396  Anum_pg_subscription_subslotname, &isnull);
1397  if (!isnull)
1398  slotname = pstrdup(NameStr(*DatumGetName(datum)));
1399  else
1400  slotname = NULL;
1401 
1402  /*
1403  * Since dropping a replication slot is not transactional, the replication
1404  * slot stays dropped even if the transaction rolls back. So we cannot
1405  * run DROP SUBSCRIPTION inside a transaction block if dropping the
1406  * replication slot. Also, in this case, we report a message for dropping
1407  * the subscription to the cumulative stats system.
1408  *
1409  * XXX The command name should really be something like "DROP SUBSCRIPTION
1410  * of a subscription that is associated with a replication slot", but we
1411  * don't have the proper facilities for that.
1412  */
1413  if (slotname)
1414  PreventInTransactionBlock(isTopLevel, "DROP SUBSCRIPTION");
1415 
1416  ObjectAddressSet(myself, SubscriptionRelationId, subid);
1417  EventTriggerSQLDropAddObject(&myself, true, true);
1418 
1419  /* Remove the tuple from catalog. */
1420  CatalogTupleDelete(rel, &tup->t_self);
1421 
1422  ReleaseSysCache(tup);
1423 
1424  /*
1425  * Stop all the subscription workers immediately.
1426  *
1427  * This is necessary if we are dropping the replication slot, so that the
1428  * slot becomes accessible.
1429  *
1430  * It is also necessary if the subscription is disabled and was disabled
1431  * in the same transaction. Then the workers haven't seen the disabling
1432  * yet and will still be running, leading to hangs later when we want to
1433  * drop the replication origin. If the subscription was disabled before
1434  * this transaction, then there shouldn't be any workers left, so this
1435  * won't make a difference.
1436  *
1437  * New workers won't be started because we hold an exclusive lock on the
1438  * subscription till the end of the transaction.
1439  */
1440  LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
1441  subworkers = logicalrep_workers_find(subid, false);
1442  LWLockRelease(LogicalRepWorkerLock);
1443  foreach(lc, subworkers)
1444  {
1446 
1448  }
1449  list_free(subworkers);
1450 
1451  /*
1452  * Cleanup of tablesync replication origins.
1453  *
1454  * Any READY-state relations would already have dealt with clean-ups.
1455  *
1456  * Note that the state can't change because we have already stopped both
1457  * the apply and tablesync workers and they can't restart because of
1458  * exclusive lock on the subscription.
1459  */
1460  rstates = GetSubscriptionNotReadyRelations(subid);
1461  foreach(lc, rstates)
1462  {
1464  Oid relid = rstate->relid;
1465 
1466  /* Only cleanup resources of tablesync workers */
1467  if (!OidIsValid(relid))
1468  continue;
1469 
1470  /*
1471  * Drop the tablesync's origin tracking if exists.
1472  *
1473  * It is possible that the origin is not yet created for tablesync
1474  * worker so passing missing_ok = true. This can happen for the states
1475  * before SUBREL_STATE_FINISHEDCOPY.
1476  */
1477  ReplicationOriginNameForTablesync(subid, relid, originname,
1478  sizeof(originname));
1479  replorigin_drop_by_name(originname, true, false);
1480  }
1481 
1482  /* Clean up dependencies */
1483  deleteSharedDependencyRecordsFor(SubscriptionRelationId, subid, 0);
1484 
1485  /* Remove any associated relation synchronization states. */
1487 
1488  /* Remove the origin tracking if exists. */
1489  snprintf(originname, sizeof(originname), "pg_%u", subid);
1490  replorigin_drop_by_name(originname, true, false);
1491 
1492  /*
1493  * If there is no slot associated with the subscription, we can finish
1494  * here.
1495  */
1496  if (!slotname && rstates == NIL)
1497  {
1498  table_close(rel, NoLock);
1499  return;
1500  }
1501 
1502  /*
1503  * Try to acquire the connection necessary for dropping slots.
1504  *
1505  * Note: If the slotname is NONE/NULL then we allow the command to finish
1506  * and users need to manually cleanup the apply and tablesync worker slots
1507  * later.
1508  *
1509  * This has to be at the end because otherwise if there is an error while
1510  * doing the database operations we won't be able to rollback dropped
1511  * slot.
1512  */
1513  load_file("libpqwalreceiver", false);
1514 
1515  wrconn = walrcv_connect(conninfo, true, subname, &err);
1516  if (wrconn == NULL)
1517  {
1518  if (!slotname)
1519  {
1520  /* be tidy */
1521  list_free(rstates);
1522  table_close(rel, NoLock);
1523  return;
1524  }
1525  else
1526  {
1527  ReportSlotConnectionError(rstates, subid, slotname, err);
1528  }
1529  }
1530 
1531  PG_TRY();
1532  {
1533  foreach(lc, rstates)
1534  {
1536  Oid relid = rstate->relid;
1537 
1538  /* Only cleanup resources of tablesync workers */
1539  if (!OidIsValid(relid))
1540  continue;
1541 
1542  /*
1543  * Drop the tablesync slots associated with removed tables.
1544  *
1545  * For SYNCDONE/READY states, the tablesync slot is known to have
1546  * already been dropped by the tablesync worker.
1547  *
1548  * For other states, there is no certainty, maybe the slot does
1549  * not exist yet. Also, if we fail after removing some of the
1550  * slots, next time, it will again try to drop already dropped
1551  * slots and fail. For these reasons, we allow missing_ok = true
1552  * for the drop.
1553  */
1554  if (rstate->state != SUBREL_STATE_SYNCDONE)
1555  {
1556  char syncslotname[NAMEDATALEN] = {0};
1557 
1558  ReplicationSlotNameForTablesync(subid, relid, syncslotname,
1559  sizeof(syncslotname));
1560  ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
1561  }
1562  }
1563 
1564  list_free(rstates);
1565 
1566  /*
1567  * If there is a slot associated with the subscription, then drop the
1568  * replication slot at the publisher.
1569  */
1570  if (slotname)
1571  ReplicationSlotDropAtPubNode(wrconn, slotname, false);
1572  }
1573  PG_FINALLY();
1574  {
1576  }
1577  PG_END_TRY();
1578 
1579  /*
1580  * Tell the cumulative stats system that the subscription is getting
1581  * dropped. We can safely report dropping the subscription statistics here
1582  * if the subscription is associated with a replication slot since we
1583  * cannot run DROP SUBSCRIPTION inside a transaction block. Subscription
1584  * statistics will be removed later by (auto)vacuum either if it's not
1585  * associated with a replication slot or if the message for dropping the
1586  * subscription gets lost.
1587  */
1588  if (slotname)
1589  pgstat_drop_subscription(subid);
1590 
1591  table_close(rel, NoLock);
1592 }
#define TextDatumGetCString(d)
Definition: builtins.h:86
#define NameStr(name)
Definition: c.h:692
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:350
List * logicalrep_workers_find(Oid subid, bool only_running)
Definition: launcher.c:242
void logicalrep_worker_stop(Oid subid, Oid relid)
Definition: launcher.c:436
void list_free(List *list)
Definition: list.c:1545
#define NoLock
Definition: lockdefs.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_SHARED
Definition: lwlock.h:105
char * pstrdup(const char *in)
Definition: mcxt.c:1305
#define InvokeObjectDropHook(classId, objectId, subId)
Definition: objectaccess.h:180
void replorigin_drop_by_name(const char *name, bool missing_ok, bool nowait)
Definition: origin.c:414
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1001
List * GetSubscriptionNotReadyRelations(Oid subid)
void RemoveSubscriptionRel(Oid subid, Oid relid)
NameData subname
void pgstat_drop_subscription(Oid subid)
#define DatumGetName(X)
Definition: postgres.h:629
#define InvalidOid
Definition: postgres_ext.h:36
static void ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1434
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1184
void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname, int szorgname)
Definition: tablesync.c:1168
void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot)
Definition: tablesync.c:1155

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, pgstat_drop_subscription(), PreventInTransactionBlock(), pstrdup(), ReleaseSysCache(), SubscriptionRelState::relid, LogicalRepWorker::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().