@@ -342,7 +342,6 @@ main(int argc, char **argv)
342
342
{"enable-row-security", no_argument, &dopt.enable_row_security, 1},
343
343
{"exclude-table-data", required_argument, NULL, 4},
344
344
{"if-exists", no_argument, &dopt.if_exists, 1},
345
- {"include-subscriptions", no_argument, &dopt.include_subscriptions, 1},
346
345
{"inserts", no_argument, &dopt.dump_inserts, 1},
347
346
{"lock-wait-timeout", required_argument, NULL, 2},
348
347
{"no-tablespaces", no_argument, &dopt.outputNoTablespaces, 1},
@@ -868,7 +867,6 @@ main(int argc, char **argv)
868
867
ropt->include_everything = dopt.include_everything;
869
868
ropt->enable_row_security = dopt.enable_row_security;
870
869
ropt->sequence_data = dopt.sequence_data;
871
- ropt->include_subscriptions = dopt.include_subscriptions;
872
870
ropt->binary_upgrade = dopt.binary_upgrade;
873
871
874
872
if (compressLevel == -1)
@@ -951,7 +949,6 @@ help(const char *progname)
951
949
" access to)\n"));
952
950
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
953
951
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
954
- printf(_(" --include-subscriptions dump logical replication subscriptions\n"));
955
952
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
956
953
printf(_(" --no-security-labels do not dump security label assignments\n"));
957
954
printf(_(" --no-subscription-connect dump subscriptions so they don't connect on restore\n"));
@@ -3641,6 +3638,22 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
3641
3638
destroyPQExpBuffer(query);
3642
3639
}
3643
3640
3641
+ /*
3642
+ * Is the currently connected user a superuser?
3643
+ */
3644
+ static bool
3645
+ is_superuser(Archive *fout)
3646
+ {
3647
+ ArchiveHandle *AH = (ArchiveHandle *) fout;
3648
+ const char *val;
3649
+
3650
+ val = PQparameterStatus(AH->connection, "is_superuser");
3651
+
3652
+ if (val && strcmp(val, "on") == 0)
3653
+ return true;
3654
+
3655
+ return false;
3656
+ }
3644
3657
3645
3658
/*
3646
3659
* getSubscriptions
@@ -3649,7 +3662,6 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
3649
3662
void
3650
3663
getSubscriptions(Archive *fout)
3651
3664
{
3652
- DumpOptions *dopt = fout->dopt;
3653
3665
PQExpBuffer query;
3654
3666
PGresult *res;
3655
3667
SubscriptionInfo *subinfo;
@@ -3664,9 +3676,25 @@ getSubscriptions(Archive *fout)
3664
3676
int i,
3665
3677
ntups;
3666
3678
3667
- if (!dopt->include_subscriptions || fout->remoteVersion < 100000)
3679
+ if (fout->remoteVersion < 100000)
3668
3680
return;
3669
3681
3682
+ if (!is_superuser(fout))
3683
+ {
3684
+ int n;
3685
+
3686
+ res = ExecuteSqlQuery(fout,
3687
+ "SELECT count(*) FROM pg_subscription "
3688
+ "WHERE subdbid = (SELECT oid FROM pg_catalog.pg_database"
3689
+ " WHERE datname = current_database())",
3690
+ PGRES_TUPLES_OK);
3691
+ n = atoi(PQgetvalue(res, 0, 0));
3692
+ if (n > 0)
3693
+ write_msg(NULL, "WARNING: subscriptions not dumped because current user is not a superuser\n");
3694
+ PQclear(res);
3695
+ return;
3696
+ }
3697
+
3670
3698
query = createPQExpBuffer();
3671
3699
3672
3700
resetPQExpBuffer(query);
@@ -3714,6 +3742,9 @@ getSubscriptions(Archive *fout)
3714
3742
if (strlen(subinfo[i].rolname) == 0)
3715
3743
write_msg(NULL, "WARNING: owner of subscription \"%s\" appears to be invalid\n",
3716
3744
subinfo[i].dobj.name);
3745
+
3746
+ /* Decide whether we want to dump it */
3747
+ selectDumpableObject(&(subinfo[i].dobj), fout);
3717
3748
}
3718
3749
PQclear(res);
3719
3750
@@ -3735,7 +3766,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
3735
3766
int npubnames = 0;
3736
3767
int i;
3737
3768
3738
- if (dopt->dataOnly )
3769
+ if (!(subinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) )
3739
3770
return;
3740
3771
3741
3772
delq = createPQExpBuffer();
0 commit comments