PostgreSQL Source Code  git master
subscriptioncmds.c File Reference
Include dependency graph for subscriptioncmds.c:

Go to the source code of this file.

Data Structures

struct  SubOpts
 

Macros

#define SUBOPT_CONNECT   0x00000001
 
#define SUBOPT_ENABLED   0x00000002
 
#define SUBOPT_CREATE_SLOT   0x00000004
 
#define SUBOPT_SLOT_NAME   0x00000008
 
#define SUBOPT_COPY_DATA   0x00000010
 
#define SUBOPT_SYNCHRONOUS_COMMIT   0x00000020
 
#define SUBOPT_REFRESH   0x00000040
 
#define SUBOPT_BINARY   0x00000080
 
#define SUBOPT_STREAMING   0x00000100
 
#define SUBOPT_TWOPHASE_COMMIT   0x00000200
 
#define IsSet(val, bits)   (((val) & (bits)) == (bits))
 

Typedefs

typedef struct SubOpts SubOpts
 

Functions

static Listfetch_table_list (WalReceiverConn *wrconn, List *publications)
 
static void check_duplicates_in_publist (List *publist, Datum *datums)
 
static Listmerge_publications (List *oldpublist, List *newpublist, bool addpub, const char *subname)
 
static void ReportSlotConnectionError (List *rstates, Oid subid, char *slotname, char *err)
 
static void parse_subscription_options (ParseState *pstate, List *stmt_options, bits32 supported_opts, SubOpts *opts)
 
static Datum publicationListToArray (List *publist)
 
ObjectAddress CreateSubscription (ParseState *pstate, CreateSubscriptionStmt *stmt, bool isTopLevel)
 
static void AlterSubscription_refresh (Subscription *sub, bool copy_data)
 
ObjectAddress AlterSubscription (ParseState *pstate, AlterSubscriptionStmt *stmt, bool isTopLevel)
 
void DropSubscription (DropSubscriptionStmt *stmt, bool isTopLevel)
 
void ReplicationSlotDropAtPubNode (WalReceiverConn *wrconn, char *slotname, bool missing_ok)
 
static void AlterSubscriptionOwner_internal (Relation rel, HeapTuple tup, Oid newOwnerId)
 
ObjectAddress AlterSubscriptionOwner (const char *name, Oid newOwnerId)
 
void AlterSubscriptionOwner_oid (Oid subid, Oid newOwnerId)
 

Macro Definition Documentation

◆ IsSet

#define IsSet (   val,
  bits 
)    (((val) & (bits)) == (bits))

◆ SUBOPT_BINARY

#define SUBOPT_BINARY   0x00000080

◆ SUBOPT_CONNECT

#define SUBOPT_CONNECT   0x00000001

Definition at line 53 of file subscriptioncmds.c.

Referenced by CreateSubscription(), and parse_subscription_options().

◆ SUBOPT_COPY_DATA

#define SUBOPT_COPY_DATA   0x00000010

◆ SUBOPT_CREATE_SLOT

#define SUBOPT_CREATE_SLOT   0x00000004

Definition at line 55 of file subscriptioncmds.c.

Referenced by CreateSubscription(), and parse_subscription_options().

◆ SUBOPT_ENABLED

#define SUBOPT_ENABLED   0x00000002

◆ SUBOPT_REFRESH

#define SUBOPT_REFRESH   0x00000040

Definition at line 59 of file subscriptioncmds.c.

Referenced by AlterSubscription(), and parse_subscription_options().

◆ SUBOPT_SLOT_NAME

#define SUBOPT_SLOT_NAME   0x00000008

◆ SUBOPT_STREAMING

#define SUBOPT_STREAMING   0x00000100

◆ SUBOPT_SYNCHRONOUS_COMMIT

#define SUBOPT_SYNCHRONOUS_COMMIT   0x00000020

◆ SUBOPT_TWOPHASE_COMMIT

#define SUBOPT_TWOPHASE_COMMIT   0x00000200

Definition at line 62 of file subscriptioncmds.c.

Referenced by CreateSubscription(), and parse_subscription_options().

Typedef Documentation

◆ SubOpts

typedef struct SubOpts SubOpts

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:3716
#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:3399
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:1018
#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:179
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:5384

◆ AlterSubscription_refresh()

static void AlterSubscription_refresh ( Subscription sub,
bool  copy_data 
)
static

Definition at line 609 of file subscriptioncmds.c.

References AccessExclusiveLock, AccessShareLock, AddSubscriptionRelState(), CheckSubscriptionRelkind(), Subscription::conninfo, DEBUG1, ereport, errcode(), errmsg(), errmsg_internal(), ERROR, fetch_table_list(), get_namespace_name(), get_rel_name(), get_rel_namespace(), get_rel_relkind(), GetSubscriptionRelations(), GetSubscriptionRelState(), InvalidXLogRecPtr, lfirst, list_length(), load_file(), logicalrep_worker_stop(), Subscription::name, NAMEDATALEN, NoLock, Subscription::oid, oid_cmp(), palloc(), PG_END_TRY, PG_FINALLY, PG_TRY, Subscription::publications, qsort, RangeVarGetRelid, SubscriptionRelState::relid, RangeVar::relname, RemoveSubscriptionRel(), ReplicationOriginNameForTablesync(), ReplicationSlotDropAtPubNode(), ReplicationSlotNameForTablesync(), replorigin_drop_by_name(), RangeVar::schemaname, table_close(), table_open(), walrcv_connect, walrcv_disconnect, and wrconn.

Referenced by AlterSubscription().

610 {
611  char *err;
612  List *pubrel_names;
613  List *subrel_states;
614  Oid *subrel_local_oids;
615  Oid *pubrel_local_oids;
616  ListCell *lc;
617  int off;
618  int remove_rel_len;
619  Relation rel = NULL;
620  typedef struct SubRemoveRels
621  {
622  Oid relid;
623  char state;
624  } SubRemoveRels;
625  SubRemoveRels *sub_remove_rels;
627 
628  /* Load the library providing us libpq calls. */
629  load_file("libpqwalreceiver", false);
630 
631  /* Try to connect to the publisher. */
632  wrconn = walrcv_connect(sub->conninfo, true, sub->name, &err);
633  if (!wrconn)
634  ereport(ERROR,
635  (errcode(ERRCODE_CONNECTION_FAILURE),
636  errmsg("could not connect to the publisher: %s", err)));
637 
638  PG_TRY();
639  {
640  /* Get the table list from publisher. */
641  pubrel_names = fetch_table_list(wrconn, sub->publications);
642 
643  /* Get local table list. */
644  subrel_states = GetSubscriptionRelations(sub->oid);
645 
646  /*
647  * Build qsorted array of local table oids for faster lookup. This can
648  * potentially contain all tables in the database so speed of lookup
649  * is important.
650  */
651  subrel_local_oids = palloc(list_length(subrel_states) * sizeof(Oid));
652  off = 0;
653  foreach(lc, subrel_states)
654  {
656 
657  subrel_local_oids[off++] = relstate->relid;
658  }
659  qsort(subrel_local_oids, list_length(subrel_states),
660  sizeof(Oid), oid_cmp);
661 
662  /*
663  * Rels that we want to remove from subscription and drop any slots
664  * and origins corresponding to them.
665  */
666  sub_remove_rels = palloc(list_length(subrel_states) * sizeof(SubRemoveRels));
667 
668  /*
669  * Walk over the remote tables and try to match them to locally known
670  * tables. If the table is not known locally create a new state for
671  * it.
672  *
673  * Also builds array of local oids of remote tables for the next step.
674  */
675  off = 0;
676  pubrel_local_oids = palloc(list_length(pubrel_names) * sizeof(Oid));
677 
678  foreach(lc, pubrel_names)
679  {
680  RangeVar *rv = (RangeVar *) lfirst(lc);
681  Oid relid;
682 
683  relid = RangeVarGetRelid(rv, AccessShareLock, false);
684 
685  /* Check for supported relkind. */
687  rv->schemaname, rv->relname);
688 
689  pubrel_local_oids[off++] = relid;
690 
691  if (!bsearch(&relid, subrel_local_oids,
692  list_length(subrel_states), sizeof(Oid), oid_cmp))
693  {
694  AddSubscriptionRelState(sub->oid, relid,
695  copy_data ? SUBREL_STATE_INIT : SUBREL_STATE_READY,
697  ereport(DEBUG1,
698  (errmsg_internal("table \"%s.%s\" added to subscription \"%s\"",
699  rv->schemaname, rv->relname, sub->name)));
700  }
701  }
702 
703  /*
704  * Next remove state for tables we should not care about anymore using
705  * the data we collected above
706  */
707  qsort(pubrel_local_oids, list_length(pubrel_names),
708  sizeof(Oid), oid_cmp);
709 
710  remove_rel_len = 0;
711  for (off = 0; off < list_length(subrel_states); off++)
712  {
713  Oid relid = subrel_local_oids[off];
714 
715  if (!bsearch(&relid, pubrel_local_oids,
716  list_length(pubrel_names), sizeof(Oid), oid_cmp))
717  {
718  char state;
719  XLogRecPtr statelsn;
720 
721  /*
722  * Lock pg_subscription_rel with AccessExclusiveLock to
723  * prevent any race conditions with the apply worker
724  * re-launching workers at the same time this code is trying
725  * to remove those tables.
726  *
727  * Even if new worker for this particular rel is restarted it
728  * won't be able to make any progress as we hold exclusive
729  * lock on subscription_rel till the transaction end. It will
730  * simply exit as there is no corresponding rel entry.
731  *
732  * This locking also ensures that the state of rels won't
733  * change till we are done with this refresh operation.
734  */
735  if (!rel)
736  rel = table_open(SubscriptionRelRelationId, AccessExclusiveLock);
737 
738  /* Last known rel state. */
739  state = GetSubscriptionRelState(sub->oid, relid, &statelsn);
740 
741  sub_remove_rels[remove_rel_len].relid = relid;
742  sub_remove_rels[remove_rel_len++].state = state;
743 
744  RemoveSubscriptionRel(sub->oid, relid);
745 
746  logicalrep_worker_stop(sub->oid, relid);
747 
748  /*
749  * For READY state, we would have already dropped the
750  * tablesync origin.
751  */
752  if (state != SUBREL_STATE_READY)
753  {
754  char originname[NAMEDATALEN];
755 
756  /*
757  * Drop the tablesync's origin tracking if exists.
758  *
759  * It is possible that the origin is not yet created for
760  * tablesync worker, this can happen for the states before
761  * SUBREL_STATE_FINISHEDCOPY. The apply worker can also
762  * concurrently try to drop the origin and by this time
763  * the origin might be already removed. For these reasons,
764  * passing missing_ok = true.
765  */
766  ReplicationOriginNameForTablesync(sub->oid, relid, originname,
767  sizeof(originname));
768  replorigin_drop_by_name(originname, true, false);
769  }
770 
771  ereport(DEBUG1,
772  (errmsg_internal("table \"%s.%s\" removed from subscription \"%s\"",
774  get_rel_name(relid),
775  sub->name)));
776  }
777  }
778 
779  /*
780  * Drop the tablesync slots associated with removed tables. This has
781  * to be at the end because otherwise if there is an error while doing
782  * the database operations we won't be able to rollback dropped slots.
783  */
784  for (off = 0; off < remove_rel_len; off++)
785  {
786  if (sub_remove_rels[off].state != SUBREL_STATE_READY &&
787  sub_remove_rels[off].state != SUBREL_STATE_SYNCDONE)
788  {
789  char syncslotname[NAMEDATALEN] = {0};
790 
791  /*
792  * For READY/SYNCDONE states we know the tablesync slot has
793  * already been dropped by the tablesync worker.
794  *
795  * For other states, there is no certainty, maybe the slot
796  * does not exist yet. Also, if we fail after removing some of
797  * the slots, next time, it will again try to drop already
798  * dropped slots and fail. For these reasons, we allow
799  * missing_ok = true for the drop.
800  */
801  ReplicationSlotNameForTablesync(sub->oid, sub_remove_rels[off].relid,
802  syncslotname, sizeof(syncslotname));
803  ReplicationSlotDropAtPubNode(wrconn, syncslotname, true);
804  }
805  }
806  }
807  PG_FINALLY();
808  {
809  walrcv_disconnect(wrconn);
810  }
811  PG_END_TRY();
812 
813  if (rel)
814  table_close(rel, NoLock);
815 }
static List * fetch_table_list(WalReceiverConn *wrconn, List *publications)
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define DEBUG1
Definition: elog.h:25
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
void RemoveSubscriptionRel(Oid subid, Oid relid)
void ReplicationSlotDropAtPubNode(WalReceiverConn *wrconn, char *slotname, bool missing_ok)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1974
Oid get_rel_namespace(Oid relid)
Definition: lsyscache.c:1923
void replorigin_drop_by_name(const char *name, bool missing_ok, bool nowait)
Definition: origin.c:414
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
unsigned int Oid
Definition: postgres_ext.h:31
static WalReceiverConn * wrconn
Definition: walreceiver.c:94
char * schemaname
Definition: primnodes.h:67
#define NAMEDATALEN
char * relname
Definition: primnodes.h:68
#define ERROR
Definition: elog.h:46
void AddSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn)
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
#define NoLock
Definition: lockdefs.h:34
void logicalrep_worker_stop(Oid subid, Oid relid)
Definition: launcher.c:437
List * GetSubscriptionRelations(Oid subid)
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
#define PG_FINALLY()
Definition: elog.h:330
char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn)
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define lfirst(lc)
Definition: pg_list.h:169
Definition: regguts.h:317
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
int oid_cmp(const void *p1, const void *p2)
Definition: oid.c:336
static int list_length(const List *l)
Definition: pg_list.h:149
void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname, int szorgname)
Definition: tablesync.c:905
#define walrcv_disconnect(conn)
Definition: walreceiver.h:432
#define AccessExclusiveLock
Definition: lockdefs.h:45
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define qsort(a, b, c, d)
Definition: port.h:505
#define PG_TRY()
Definition: elog.h:313
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1899
#define PG_END_TRY()
Definition: elog.h:338
void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot)
Definition: tablesync.c:892
#define walrcv_connect(conninfo, logical, appname, err)
Definition: walreceiver.h:404

◆ 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:179
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterSubscriptionOwner_internal()

static void AlterSubscriptionOwner_internal ( Relation  rel,
HeapTuple  tup,
Oid  newOwnerId 
)
static

Definition at line 1446 of file subscriptioncmds.c.

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), changeDependencyOnOwner(), ereport, errcode(), errhint(), errmsg(), ERROR, GETSTRUCT, GetUserId(), InvokeObjectPostAlterHook, NameStr, OBJECT_SUBSCRIPTION, pg_subscription_ownercheck(), superuser_arg(), and HeapTupleData::t_self.

Referenced by AlterSubscriptionOwner(), and AlterSubscriptionOwner_oid().

1447 {
1448  Form_pg_subscription form;
1449 
1450  form = (Form_pg_subscription) GETSTRUCT(tup);
1451 
1452  if (form->subowner == newOwnerId)
1453  return;
1454 
1455  if (!pg_subscription_ownercheck(form->oid, GetUserId()))
1457  NameStr(form->subname));
1458 
1459  /* New owner must be a superuser */
1460  if (!superuser_arg(newOwnerId))
1461  ereport(ERROR,
1462  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1463  errmsg("permission denied to change owner of subscription \"%s\"",
1464  NameStr(form->subname)),
1465  errhint("The owner of a subscription must be a superuser.")));
1466 
1467  form->subowner = newOwnerId;
1468  CatalogTupleUpdate(rel, &tup->t_self, tup);
1469 
1470  /* Update owner dependency reference */
1471  changeDependencyOnOwner(SubscriptionRelationId,
1472  form->oid,
1473  newOwnerId);
1474 
1475  InvokeObjectPostAlterHook(SubscriptionRelationId,
1476  form->oid, 0);
1477 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
Oid GetUserId(void)
Definition: miscinit.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
FormData_pg_subscription * Form_pg_subscription
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:311
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 InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
#define ereport(elevel,...)
Definition: elog.h:157
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define NameStr(name)
Definition: c.h:681
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5384

◆ 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:177
int errmsg(const char *fmt,...)
Definition: elog.c:909
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ check_duplicates_in_publist()

static void check_duplicates_in_publist ( List publist,
Datum datums 
)
static

Definition at line 1659 of file subscriptioncmds.c.

References CStringGetTextDatum, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, lfirst, name, and strVal.

Referenced by merge_publications(), and publicationListToArray().

1660 {
1661  ListCell *cell;
1662  int j = 0;
1663 
1664  foreach(cell, publist)
1665  {
1666  char *name = strVal(lfirst(cell));
1667  ListCell *pcell;
1668 
1669  foreach(pcell, publist)
1670  {
1671  char *pname = strVal(lfirst(pcell));
1672 
1673  if (pcell == cell)
1674  break;
1675 
1676  if (strcmp(name, pname) == 0)
1677  ereport(ERROR,
1679  errmsg("publication name \"%s\" used more than once",
1680  pname)));
1681  }
1682 
1683  if (datums)
1684  datums[j++] = CStringGetTextDatum(name);
1685  }
1686 }
#define strVal(v)
Definition: value.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define CStringGetTextDatum(s)
Definition: builtins.h:86
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32

◆ 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:3399
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:197
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:217
#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:3399
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1000
#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:1198
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1411
Oid MyDatabaseId
Definition: globals.c:88
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1018
#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:1161
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:217
#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:5384
#define walrcv_connect(conninfo, logical, appname, err)
Definition: walreceiver.h:404

◆ fetch_table_list()

static List * fetch_table_list ( WalReceiverConn wrconn,
List publications 
)
static

Definition at line 1545 of file subscriptioncmds.c.

References appendStringInfoChar(), appendStringInfoString(), Assert, StringInfoData::data, ereport, WalRcvExecResult::err, errcode(), errmsg(), ERROR, ExecClearTuple(), ExecDropSingleTupleTableSlot(), initStringInfo(), lappend(), lfirst, list_length(), makeRangeVar(), MakeSingleTupleTableSlot(), NIL, pfree(), quote_literal_cstr(), relname, slot_getattr(), WalRcvExecResult::status, strVal, TextDatumGetCString, TTSOpsMinimalTuple, WalRcvExecResult::tupledesc, WalRcvExecResult::tuplestore, tuplestore_gettupleslot(), walrcv_clear_result(), walrcv_exec, and WALRCV_OK_TUPLES.

Referenced by AlterSubscription_refresh(), and CreateSubscription().

1546 {
1547  WalRcvExecResult *res;
1548  StringInfoData cmd;
1549  TupleTableSlot *slot;
1550  Oid tableRow[2] = {TEXTOID, TEXTOID};
1551  ListCell *lc;
1552  bool first;
1553  List *tablelist = NIL;
1554 
1555  Assert(list_length(publications) > 0);
1556 
1557  initStringInfo(&cmd);
1558  appendStringInfoString(&cmd, "SELECT DISTINCT t.schemaname, t.tablename\n"
1559  " FROM pg_catalog.pg_publication_tables t\n"
1560  " WHERE t.pubname IN (");
1561  first = true;
1562  foreach(lc, publications)
1563  {
1564  char *pubname = strVal(lfirst(lc));
1565 
1566  if (first)
1567  first = false;
1568  else
1569  appendStringInfoString(&cmd, ", ");
1570 
1572  }
1573  appendStringInfoChar(&cmd, ')');
1574 
1575  res = walrcv_exec(wrconn, cmd.data, 2, tableRow);
1576  pfree(cmd.data);
1577 
1578  if (res->status != WALRCV_OK_TUPLES)
1579  ereport(ERROR,
1580  (errcode(ERRCODE_CONNECTION_FAILURE),
1581  errmsg("could not receive list of replicated tables from the publisher: %s",
1582  res->err)));
1583 
1584  /* Process tables. */
1586  while (tuplestore_gettupleslot(res->tuplestore, true, false, slot))
1587  {
1588  char *nspname;
1589  char *relname;
1590  bool isnull;
1591  RangeVar *rv;
1592 
1593  nspname = TextDatumGetCString(slot_getattr(slot, 1, &isnull));
1594  Assert(!isnull);
1595  relname = TextDatumGetCString(slot_getattr(slot, 2, &isnull));
1596  Assert(!isnull);
1597 
1598  rv = makeRangeVar(nspname, relname, -1);
1599  tablelist = lappend(tablelist, rv);
1600 
1601  ExecClearTuple(slot);
1602  }
1604 
1605  walrcv_clear_result(res);
1606 
1607  return tablelist;
1608 }
#define NIL
Definition: pg_list.h:65
char * quote_literal_cstr(const char *rawstr)
Definition: quote.c:102
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1238
#define strVal(v)
Definition: value.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
static void walrcv_clear_result(WalRcvExecResult *walres)
Definition: walreceiver.h:436
void pfree(void *pointer)
Definition: mcxt.c:1169
TupleDesc tupledesc
Definition: walreceiver.h:220
#define ERROR
Definition: elog.h:46
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1254
List * lappend(List *list, void *datum)
Definition: list.c:336
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define TextDatumGetCString(d)
Definition: builtins.h:87
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:381
#define ereport(elevel,...)
Definition: elog.h:157
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
Definition: tuplestore.c:1078
Tuplestorestate * tuplestore
Definition: walreceiver.h:219
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
WalRcvExecStatus status
Definition: walreceiver.h:216
static int list_length(const List *l)
Definition: pg_list.h:149
int errmsg(const char *fmt,...)
Definition: elog.c:909
Definition: pg_list.h:50
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:422
#define walrcv_exec(conn, exec, nRetTypes, retTypes)
Definition: walreceiver.h:430

◆ merge_publications()

static List * merge_publications ( List oldpublist,
List newpublist,
bool  addpub,
const char *  subname 
)
static

Definition at line 1699 of file subscriptioncmds.c.

References check_duplicates_in_publist(), ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, foreach_delete_current, lappend(), lfirst, list_copy(), makeString(), name, and strVal.

Referenced by AlterSubscription().

1700 {
1701  ListCell *lc;
1702 
1703  oldpublist = list_copy(oldpublist);
1704 
1705  check_duplicates_in_publist(newpublist, NULL);
1706 
1707  foreach(lc, newpublist)
1708  {
1709  char *name = strVal(lfirst(lc));
1710  ListCell *lc2;
1711  bool found = false;
1712 
1713  foreach(lc2, oldpublist)
1714  {
1715  char *pubname = strVal(lfirst(lc2));
1716 
1717  if (strcmp(name, pubname) == 0)
1718  {
1719  found = true;
1720  if (addpub)
1721  ereport(ERROR,
1723  errmsg("publication \"%s\" is already in subscription \"%s\"",
1724  name, subname)));
1725  else
1726  oldpublist = foreach_delete_current(oldpublist, lc2);
1727 
1728  break;
1729  }
1730  }
1731 
1732  if (addpub && !found)
1733  oldpublist = lappend(oldpublist, makeString(name));
1734  else if (!addpub && !found)
1735  ereport(ERROR,
1736  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1737  errmsg("publication \"%s\" is not in subscription \"%s\"",
1738  name, subname)));
1739  }
1740 
1741  /*
1742  * XXX Probably no strong reason for this, but for now it's to make ALTER
1743  * SUBSCRIPTION ... DROP PUBLICATION consistent with SET PUBLICATION.
1744  */
1745  if (!oldpublist)
1746  ereport(ERROR,
1747  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1748  errmsg("cannot drop all the publications from a subscription")));
1749 
1750  return oldpublist;
1751 }
List * list_copy(const List *oldlist)
Definition: list.c:1418
#define strVal(v)
Definition: value.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
String * makeString(char *str)
Definition: value.c:51
NameData subname
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:369
#define ERROR
Definition: elog.h:46
List * lappend(List *list, void *datum)
Definition: list.c:336
static void check_duplicates_in_publist(List *publist, Datum *datums)
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
const char * name
Definition: encode.c:561
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32

◆ parse_subscription_options()

static void parse_subscription_options ( ParseState pstate,
List stmt_options,
bits32  supported_opts,
SubOpts opts 
)
static

Definition at line 101 of file subscriptioncmds.c.

References Assert, SubOpts::binary, SubOpts::connect, SubOpts::copy_data, SubOpts::create_slot, defGetBoolean(), defGetString(), DefElem::defname, SubOpts::enabled, ereport, errcode(), errmsg(), ERROR, errorConflictingDefElem(), GUC_ACTION_SET, IsSet, lfirst, PGC_BACKEND, PGC_S_TEST, SubOpts::refresh, ReplicationSlotValidateName(), set_config_option(), SubOpts::slot_name, SubOpts::specified_opts, SubOpts::streaming, SUBOPT_BINARY, SUBOPT_CONNECT, SUBOPT_COPY_DATA, SUBOPT_CREATE_SLOT, SUBOPT_ENABLED, SUBOPT_REFRESH, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, SubOpts::synchronous_commit, and SubOpts::twophase.

Referenced by AlterSubscription(), and CreateSubscription().

103 {
104  ListCell *lc;
105 
106  /* caller must expect some option */
107  Assert(supported_opts != 0);
108 
109  /* If connect option is supported, these others also need to be. */
110  Assert(!IsSet(supported_opts, SUBOPT_CONNECT) ||
111  IsSet(supported_opts, SUBOPT_ENABLED | SUBOPT_CREATE_SLOT |
113 
114  /* Set default values for the boolean supported options. */
115  if (IsSet(supported_opts, SUBOPT_CONNECT))
116  opts->connect = true;
117  if (IsSet(supported_opts, SUBOPT_ENABLED))
118  opts->enabled = true;
119  if (IsSet(supported_opts, SUBOPT_CREATE_SLOT))
120  opts->create_slot = true;
121  if (IsSet(supported_opts, SUBOPT_COPY_DATA))
122  opts->copy_data = true;
123  if (IsSet(supported_opts, SUBOPT_REFRESH))
124  opts->refresh = true;
125  if (IsSet(supported_opts, SUBOPT_BINARY))
126  opts->binary = false;
127  if (IsSet(supported_opts, SUBOPT_STREAMING))
128  opts->streaming = false;
129  if (IsSet(supported_opts, SUBOPT_TWOPHASE_COMMIT))
130  opts->twophase = false;
131 
132  /* Parse options */
133  foreach(lc, stmt_options)
134  {
135  DefElem *defel = (DefElem *) lfirst(lc);
136 
137  if (IsSet(supported_opts, SUBOPT_CONNECT) &&
138  strcmp(defel->defname, "connect") == 0)
139  {
140  if (IsSet(opts->specified_opts, SUBOPT_CONNECT))
141  errorConflictingDefElem(defel, pstate);
142 
144  opts->connect = defGetBoolean(defel);
145  }
146  else if (IsSet(supported_opts, SUBOPT_ENABLED) &&
147  strcmp(defel->defname, "enabled") == 0)
148  {
149  if (IsSet(opts->specified_opts, SUBOPT_ENABLED))
150  errorConflictingDefElem(defel, pstate);
151 
153  opts->enabled = defGetBoolean(defel);
154  }
155  else if (IsSet(supported_opts, SUBOPT_CREATE_SLOT) &&
156  strcmp(defel->defname, "create_slot") == 0)
157  {
159  errorConflictingDefElem(defel, pstate);
160 
162  opts->create_slot = defGetBoolean(defel);
163  }
164  else if (IsSet(supported_opts, SUBOPT_SLOT_NAME) &&
165  strcmp(defel->defname, "slot_name") == 0)
166  {
168  errorConflictingDefElem(defel, pstate);
169 
171  opts->slot_name = defGetString(defel);
172 
173  /* Setting slot_name = NONE is treated as no slot name. */
174  if (strcmp(opts->slot_name, "none") == 0)
175  opts->slot_name = NULL;
176  else
178  }
179  else if (IsSet(supported_opts, SUBOPT_COPY_DATA) &&
180  strcmp(defel->defname, "copy_data") == 0)
181  {
183  errorConflictingDefElem(defel, pstate);
184 
186  opts->copy_data = defGetBoolean(defel);
187  }
188  else if (IsSet(supported_opts, SUBOPT_SYNCHRONOUS_COMMIT) &&
189  strcmp(defel->defname, "synchronous_commit") == 0)
190  {
192  errorConflictingDefElem(defel, pstate);
193 
195  opts->synchronous_commit = defGetString(defel);
196 
197  /* Test if the given value is valid for synchronous_commit GUC. */
198  (void) set_config_option("synchronous_commit", opts->synchronous_commit,
200  false, 0, false);
201  }
202  else if (IsSet(supported_opts, SUBOPT_REFRESH) &&
203  strcmp(defel->defname, "refresh") == 0)
204  {
205  if (IsSet(opts->specified_opts, SUBOPT_REFRESH))
206  errorConflictingDefElem(defel, pstate);
207 
209  opts->refresh = defGetBoolean(defel);
210  }
211  else if (IsSet(supported_opts, SUBOPT_BINARY) &&
212  strcmp(defel->defname, "binary") == 0)
213  {
214  if (IsSet(opts->specified_opts, SUBOPT_BINARY))
215  errorConflictingDefElem(defel, pstate);
216 
217  opts->specified_opts |= SUBOPT_BINARY;
218  opts->binary = defGetBoolean(defel);
219  }
220  else if (IsSet(supported_opts, SUBOPT_STREAMING) &&
221  strcmp(defel->defname, "streaming") == 0)
222  {
224  errorConflictingDefElem(defel, pstate);
225 
227  opts->streaming = defGetBoolean(defel);
228  }
229  else if (strcmp(defel->defname, "two_phase") == 0)
230  {
231  /*
232  * Do not allow toggling of two_phase option. Doing so could cause
233  * missing of transactions and lead to an inconsistent replica.
234  * See comments atop worker.c
235  *
236  * Note: Unsupported twophase indicates that this call originated
237  * from AlterSubscription.
238  */
239  if (!IsSet(supported_opts, SUBOPT_TWOPHASE_COMMIT))
240  ereport(ERROR,
241  (errcode(ERRCODE_SYNTAX_ERROR),
242  errmsg("unrecognized subscription parameter: \"%s\"", defel->defname)));
243 
245  errorConflictingDefElem(defel, pstate);
246 
248  opts->twophase = defGetBoolean(defel);
249  }
250  else
251  ereport(ERROR,
252  (errcode(ERRCODE_SYNTAX_ERROR),
253  errmsg("unrecognized subscription parameter: \"%s\"", defel->defname)));
254  }
255 
256  /*
257  * We've been explicitly asked to not connect, that requires some
258  * additional processing.
259  */
260  if (!opts->connect && IsSet(supported_opts, SUBOPT_CONNECT))
261  {
262  /* Check for incompatible options from the user. */
263  if (opts->enabled &&
264  IsSet(supported_opts, SUBOPT_ENABLED) &&
266  ereport(ERROR,
267  (errcode(ERRCODE_SYNTAX_ERROR),
268  /*- translator: both %s are strings of the form "option = value" */
269  errmsg("%s and %s are mutually exclusive options",
270  "connect = false", "enabled = true")));
271 
272  if (opts->create_slot &&
273  IsSet(supported_opts, SUBOPT_CREATE_SLOT) &&
275  ereport(ERROR,
276  (errcode(ERRCODE_SYNTAX_ERROR),
277  errmsg("%s and %s are mutually exclusive options",
278  "connect = false", "create_slot = true")));
279 
280  if (opts->copy_data &&
281  IsSet(supported_opts, SUBOPT_COPY_DATA) &&
283  ereport(ERROR,
284  (errcode(ERRCODE_SYNTAX_ERROR),
285  errmsg("%s and %s are mutually exclusive options",
286  "connect = false", "copy_data = true")));
287 
288  /* Change the defaults of other options. */
289  opts->enabled = false;
290  opts->create_slot = false;
291  opts->copy_data = false;
292  }
293 
294  /*
295  * Do additional checking for disallowed combination when slot_name = NONE
296  * was used.
297  */
298  if (!opts->slot_name &&
299  IsSet(supported_opts, SUBOPT_SLOT_NAME) &&
301  {
302  if (opts->enabled &&
303  IsSet(supported_opts, SUBOPT_ENABLED) &&
305  ereport(ERROR,
306  (errcode(ERRCODE_SYNTAX_ERROR),
307  /*- translator: both %s are strings of the form "option = value" */
308  errmsg("%s and %s are mutually exclusive options",
309  "slot_name = NONE", "enabled = true")));
310 
311  if (opts->create_slot &&
312  IsSet(supported_opts, SUBOPT_CREATE_SLOT) &&
314  ereport(ERROR,
315  (errcode(ERRCODE_SYNTAX_ERROR),
316  /*- translator: both %s are strings of the form "option = value" */
317  errmsg("%s and %s are mutually exclusive options",
318  "slot_name = NONE", "create_slot = true")));
319 
320  if (opts->enabled &&
321  IsSet(supported_opts, SUBOPT_ENABLED) &&
323  ereport(ERROR,
324  (errcode(ERRCODE_SYNTAX_ERROR),
325  /*- translator: both %s are strings of the form "option = value" */
326  errmsg("subscription with %s must also set %s",
327  "slot_name = NONE", "enabled = false")));
328 
329  if (opts->create_slot &&
330  IsSet(supported_opts, SUBOPT_CREATE_SLOT) &&
332  ereport(ERROR,
333  (errcode(ERRCODE_SYNTAX_ERROR),
334  /*- translator: both %s are strings of the form "option = value" */
335  errmsg("subscription with %s must also set %s",
336  "slot_name = NONE", "create_slot = false")));
337  }
338 }
bool copy_data
bool create_slot
bits32 specified_opts
int errcode(int sqlerrcode)
Definition: elog.c:698
#define SUBOPT_ENABLED
#define SUBOPT_CREATE_SLOT
#define SUBOPT_SYNCHRONOUS_COMMIT
#define SUBOPT_STREAMING
bool ReplicationSlotValidateName(const char *name, int elevel)
Definition: slot.c:172
bool defGetBoolean(DefElem *def)
Definition: define.c:106
#define SUBOPT_TWOPHASE_COMMIT
bool streaming
#define ERROR
Definition: elog.h:46
#define SUBOPT_CONNECT
char * defGetString(DefElem *def)
Definition: define.c:49
#define SUBOPT_BINARY
#define SUBOPT_REFRESH
char * slot_name
#define ereport(elevel,...)
Definition: elog.h:157
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
Definition: define.c:350
#define SUBOPT_COPY_DATA
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
#define SUBOPT_SLOT_NAME
int errmsg(const char *fmt,...)
Definition: elog.c:909
char * defname
Definition: parsenodes.h:758
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:7332
#define IsSet(val, bits)
char * synchronous_commit

◆ publicationListToArray()

static Datum publicationListToArray ( List publist)
static

Definition at line 344 of file subscriptioncmds.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, check_duplicates_in_publist(), construct_array(), CurrentMemoryContext, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), palloc(), and PointerGetDatum.

Referenced by AlterSubscription(), and CreateSubscription().

345 {
346  ArrayType *arr;
347  Datum *datums;
348  MemoryContext memcxt;
349  MemoryContext oldcxt;
350 
351  /* Create memory context for temporary allocations. */
353  "publicationListToArray to array",
355  oldcxt = MemoryContextSwitchTo(memcxt);
356 
357  datums = (Datum *) palloc(sizeof(Datum) * list_length(publist));
358 
359  check_duplicates_in_publist(publist, datums);
360 
361  MemoryContextSwitchTo(oldcxt);
362 
363  arr = construct_array(datums, list_length(publist),
364  TEXTOID, -1, false, TYPALIGN_INT);
365 
366  MemoryContextDelete(memcxt);
367 
368  return PointerGetDatum(arr);
369 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define AllocSetContextCreate
Definition: memutils.h:173
#define PointerGetDatum(X)
Definition: postgres.h:600
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3319
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
static void check_duplicates_in_publist(List *publist, Datum *datums)
uintptr_t Datum
Definition: postgres.h:411
static int list_length(const List *l)
Definition: pg_list.h:149
void * palloc(Size size)
Definition: mcxt.c:1062

◆ ReplicationSlotDropAtPubNode()

void ReplicationSlotDropAtPubNode ( WalReceiverConn wrconn,
char *  slotname,
bool  missing_ok 
)

Definition at line 1391 of file subscriptioncmds.c.

References appendStringInfo(), Assert, StringInfoData::data, ereport, WalRcvExecResult::err, errcode(), errmsg(), ERROR, initStringInfo(), load_file(), LOG, NOTICE, pfree(), PG_END_TRY, PG_FINALLY, PG_TRY, quote_identifier(), WalRcvExecResult::sqlstate, WalRcvExecResult::status, walrcv_clear_result(), WALRCV_ERROR, walrcv_exec, and WALRCV_OK_COMMAND.

Referenced by AlterSubscription_refresh(), DropSubscription(), LogicalRepSyncTableStart(), and process_syncing_tables_for_sync().

1392 {
1393  StringInfoData cmd;
1394 
1395  Assert(wrconn);
1396 
1397  load_file("libpqwalreceiver", false);
1398 
1399  initStringInfo(&cmd);
1400  appendStringInfo(&cmd, "DROP_REPLICATION_SLOT %s WAIT", quote_identifier(slotname));
1401 
1402  PG_TRY();
1403  {
1404  WalRcvExecResult *res;
1405 
1406  res = walrcv_exec(wrconn, cmd.data, 0, NULL);
1407 
1408  if (res->status == WALRCV_OK_COMMAND)
1409  {
1410  /* NOTICE. Success. */
1411  ereport(NOTICE,
1412  (errmsg("dropped replication slot \"%s\" on publisher",
1413  slotname)));
1414  }
1415  else if (res->status == WALRCV_ERROR &&
1416  missing_ok &&
1417  res->sqlstate == ERRCODE_UNDEFINED_OBJECT)
1418  {
1419  /* LOG. Error, but missing_ok = true. */
1420  ereport(LOG,
1421  (errmsg("could not drop replication slot \"%s\" on publisher: %s",
1422  slotname, res->err)));
1423  }
1424  else
1425  {
1426  /* ERROR. */
1427  ereport(ERROR,
1428  (errcode(ERRCODE_CONNECTION_FAILURE),
1429  errmsg("could not drop replication slot \"%s\" on publisher: %s",
1430  slotname, res->err)));
1431  }
1432 
1433  walrcv_clear_result(res);
1434  }
1435  PG_FINALLY();
1436  {
1437  pfree(cmd.data);
1438  }
1439  PG_END_TRY();
1440 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:11374
int errcode(int sqlerrcode)
Definition: elog.c:698
#define LOG
Definition: elog.h:26
static void walrcv_clear_result(WalRcvExecResult *walres)
Definition: walreceiver.h:436
void pfree(void *pointer)
Definition: mcxt.c:1169
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ERROR
Definition: elog.h:46
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define PG_FINALLY()
Definition: elog.h:330
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
#define Assert(condition)
Definition: c.h:804
WalRcvExecStatus status
Definition: walreceiver.h:216
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define PG_TRY()
Definition: elog.h:313
#define PG_END_TRY()
Definition: elog.h:338
#define walrcv_exec(conn, exec, nRetTypes, retTypes)
Definition: walreceiver.h:430

◆ ReportSlotConnectionError()

static void ReportSlotConnectionError ( List rstates,
Oid  subid,
char *  slotname,
char *  err 
)
static

Definition at line 1616 of file subscriptioncmds.c.

References elog, ereport, errcode(), errhint(), errmsg(), ERROR, lfirst, NAMEDATALEN, OidIsValid, SubscriptionRelState::relid, ReplicationSlotNameForTablesync(), SubscriptionRelState::state, and WARNING.

Referenced by DropSubscription().

1617 {
1618  ListCell *lc;
1619 
1620  foreach(lc, rstates)
1621  {
1623  Oid relid = rstate->relid;
1624 
1625  /* Only cleanup resources of tablesync workers */
1626  if (!OidIsValid(relid))
1627  continue;
1628 
1629  /*
1630  * Caller needs to ensure that relstate doesn't change underneath us.
1631  * See DropSubscription where we get the relstates.
1632  */
1633  if (rstate->state != SUBREL_STATE_SYNCDONE)
1634  {
1635  char syncslotname[NAMEDATALEN] = {0};
1636 
1637  ReplicationSlotNameForTablesync(subid, relid, syncslotname,
1638  sizeof(syncslotname));
1639  elog(WARNING, "could not drop tablesync replication slot \"%s\"",
1640  syncslotname);
1641  }
1642  }
1643 
1644  ereport(ERROR,
1645  (errcode(ERRCODE_CONNECTION_FAILURE),
1646  errmsg("could not connect to publisher when attempting to "
1647  "drop replication slot \"%s\": %s", slotname, err),
1648  /* translator: %s is an SQL ALTER command */
1649  errhint("Use %s to disassociate the subscription from the slot.",
1650  "ALTER SUBSCRIPTION ... SET (slot_name = NONE)")));
1651 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
int errcode(int sqlerrcode)
Definition: elog.c:698
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
#define NAMEDATALEN
#define ERROR
Definition: elog.h:46
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
void ReplicationSlotNameForTablesync(Oid suboid, Oid relid, char *syncslotname, int szslot)
Definition: tablesync.c:892