Skip to content

Commit 67738db

Browse files
committed
Teach pg_dump about the new pg_subscription.subrunasowner option.
Among numerous other oversights, commit 4826759 neglected to fix pg_dump to dump this new subscription option. Since the new default is "false" while the previous behavior corresponds to "true", this would cause legacy subscriptions to silently change behavior during dump/reload or pg_upgrade. That seems like a bad idea. Even if it was intended, failing to preserve the option once set in a new installation is certainly not OK. While here, reorder associated stanzas in pg_dump to match the field order in pg_subscription, in hopes of reducing the impression that all this code was written with the aid of a dartboard. Back-patch to v16 where this new field was added. Philip Warner (cosmetic tweaks by me) Discussion: https://postgr.es/m/20231027042539.01A3A220F0A@thebes.rime.com.au
1 parent ab73a37 commit 67738db

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,16 +4583,17 @@ getSubscriptions(Archive *fout)
45834583
int i_oid;
45844584
int i_subname;
45854585
int i_subowner;
4586+
int i_subbinary;
45864587
int i_substream;
45874588
int i_subtwophasestate;
45884589
int i_subdisableonerr;
4589-
int i_suborigin;
4590+
int i_subpasswordrequired;
4591+
int i_subrunasowner;
45904592
int i_subconninfo;
45914593
int i_subslotname;
45924594
int i_subsynccommit;
45934595
int i_subpublications;
4594-
int i_subbinary;
4595-
int i_subpasswordrequired;
4596+
int i_suborigin;
45964597
int i,
45974598
ntups;
45984599

@@ -4646,12 +4647,14 @@ getSubscriptions(Archive *fout)
46464647

46474648
if (fout->remoteVersion >= 160000)
46484649
appendPQExpBufferStr(query,
4649-
" s.suborigin,\n"
4650-
" s.subpasswordrequired\n");
4650+
" s.subpasswordrequired,\n"
4651+
" s.subrunasowner,\n"
4652+
" s.suborigin\n");
46514653
else
46524654
appendPQExpBuffer(query,
4653-
" '%s' AS suborigin,\n"
4654-
" 't' AS subpasswordrequired\n",
4655+
" 't' AS subpasswordrequired,\n"
4656+
" 't' AS subrunasowner,\n"
4657+
" '%s' AS suborigin\n",
46554658
LOGICALREP_ORIGIN_ANY);
46564659

46574660
appendPQExpBufferStr(query,
@@ -4671,16 +4674,17 @@ getSubscriptions(Archive *fout)
46714674
i_oid = PQfnumber(res, "oid");
46724675
i_subname = PQfnumber(res, "subname");
46734676
i_subowner = PQfnumber(res, "subowner");
4674-
i_subconninfo = PQfnumber(res, "subconninfo");
4675-
i_subslotname = PQfnumber(res, "subslotname");
4676-
i_subsynccommit = PQfnumber(res, "subsynccommit");
4677-
i_subpublications = PQfnumber(res, "subpublications");
46784677
i_subbinary = PQfnumber(res, "subbinary");
46794678
i_substream = PQfnumber(res, "substream");
46804679
i_subtwophasestate = PQfnumber(res, "subtwophasestate");
46814680
i_subdisableonerr = PQfnumber(res, "subdisableonerr");
4682-
i_suborigin = PQfnumber(res, "suborigin");
46834681
i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
4682+
i_subrunasowner = PQfnumber(res, "subrunasowner");
4683+
i_subconninfo = PQfnumber(res, "subconninfo");
4684+
i_subslotname = PQfnumber(res, "subslotname");
4685+
i_subsynccommit = PQfnumber(res, "subsynccommit");
4686+
i_subpublications = PQfnumber(res, "subpublications");
4687+
i_suborigin = PQfnumber(res, "suborigin");
46844688

46854689
subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
46864690

@@ -4693,15 +4697,7 @@ getSubscriptions(Archive *fout)
46934697
AssignDumpId(&subinfo[i].dobj);
46944698
subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
46954699
subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
4696-
subinfo[i].subconninfo = pg_strdup(PQgetvalue(res, i, i_subconninfo));
4697-
if (PQgetisnull(res, i, i_subslotname))
4698-
subinfo[i].subslotname = NULL;
4699-
else
4700-
subinfo[i].subslotname = pg_strdup(PQgetvalue(res, i, i_subslotname));
4701-
subinfo[i].subsynccommit =
4702-
pg_strdup(PQgetvalue(res, i, i_subsynccommit));
4703-
subinfo[i].subpublications =
4704-
pg_strdup(PQgetvalue(res, i, i_subpublications));
4700+
47054701
subinfo[i].subbinary =
47064702
pg_strdup(PQgetvalue(res, i, i_subbinary));
47074703
subinfo[i].substream =
@@ -4710,9 +4706,22 @@ getSubscriptions(Archive *fout)
47104706
pg_strdup(PQgetvalue(res, i, i_subtwophasestate));
47114707
subinfo[i].subdisableonerr =
47124708
pg_strdup(PQgetvalue(res, i, i_subdisableonerr));
4713-
subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
47144709
subinfo[i].subpasswordrequired =
47154710
pg_strdup(PQgetvalue(res, i, i_subpasswordrequired));
4711+
subinfo[i].subrunasowner =
4712+
pg_strdup(PQgetvalue(res, i, i_subrunasowner));
4713+
subinfo[i].subconninfo =
4714+
pg_strdup(PQgetvalue(res, i, i_subconninfo));
4715+
if (PQgetisnull(res, i, i_subslotname))
4716+
subinfo[i].subslotname = NULL;
4717+
else
4718+
subinfo[i].subslotname =
4719+
pg_strdup(PQgetvalue(res, i, i_subslotname));
4720+
subinfo[i].subsynccommit =
4721+
pg_strdup(PQgetvalue(res, i, i_subsynccommit));
4722+
subinfo[i].subpublications =
4723+
pg_strdup(PQgetvalue(res, i, i_subpublications));
4724+
subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
47164725

47174726
/* Decide whether we want to dump it */
47184727
selectDumpableObject(&(subinfo[i].dobj), fout);
@@ -4788,14 +4797,17 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
47884797
if (strcmp(subinfo->subdisableonerr, "t") == 0)
47894798
appendPQExpBufferStr(query, ", disable_on_error = true");
47904799

4791-
if (pg_strcasecmp(subinfo->suborigin, LOGICALREP_ORIGIN_ANY) != 0)
4792-
appendPQExpBuffer(query, ", origin = %s", subinfo->suborigin);
4800+
if (strcmp(subinfo->subpasswordrequired, "t") != 0)
4801+
appendPQExpBuffer(query, ", password_required = false");
4802+
4803+
if (strcmp(subinfo->subrunasowner, "t") == 0)
4804+
appendPQExpBufferStr(query, ", run_as_owner = true");
47934805

47944806
if (strcmp(subinfo->subsynccommit, "off") != 0)
47954807
appendPQExpBuffer(query, ", synchronous_commit = %s", fmtId(subinfo->subsynccommit));
47964808

4797-
if (strcmp(subinfo->subpasswordrequired, "t") != 0)
4798-
appendPQExpBuffer(query, ", password_required = false");
4809+
if (pg_strcasecmp(subinfo->suborigin, LOGICALREP_ORIGIN_ANY) != 0)
4810+
appendPQExpBuffer(query, ", origin = %s", subinfo->suborigin);
47994811

48004812
appendPQExpBufferStr(query, ");\n");
48014813

src/bin/pg_dump/pg_dump.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,16 +655,17 @@ typedef struct _SubscriptionInfo
655655
{
656656
DumpableObject dobj;
657657
const char *rolname;
658-
char *subconninfo;
659-
char *subslotname;
660658
char *subbinary;
661659
char *substream;
662660
char *subtwophasestate;
663661
char *subdisableonerr;
664-
char *suborigin;
662+
char *subpasswordrequired;
663+
char *subrunasowner;
664+
char *subconninfo;
665+
char *subslotname;
665666
char *subsynccommit;
666667
char *subpublications;
667-
char *subpasswordrequired;
668+
char *suborigin;
668669
} SubscriptionInfo;
669670

670671
/*

0 commit comments

Comments
 (0)