@@ -342,7 +342,6 @@ main(int argc, char **argv)
342342 {"enable-row-security", no_argument, &dopt.enable_row_security, 1},
343343 {"exclude-table-data", required_argument, NULL, 4},
344344 {"if-exists", no_argument, &dopt.if_exists, 1},
345- {"include-subscriptions", no_argument, &dopt.include_subscriptions, 1},
346345 {"inserts", no_argument, &dopt.dump_inserts, 1},
347346 {"lock-wait-timeout", required_argument, NULL, 2},
348347 {"no-tablespaces", no_argument, &dopt.outputNoTablespaces, 1},
@@ -868,7 +867,6 @@ main(int argc, char **argv)
868867 ropt->include_everything = dopt.include_everything;
869868 ropt->enable_row_security = dopt.enable_row_security;
870869 ropt->sequence_data = dopt.sequence_data;
871- ropt->include_subscriptions = dopt.include_subscriptions;
872870 ropt->binary_upgrade = dopt.binary_upgrade;
873871
874872 if (compressLevel == -1)
@@ -951,7 +949,6 @@ help(const char *progname)
951949 " access to)\n"));
952950 printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
953951 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
954- printf(_(" --include-subscriptions dump logical replication subscriptions\n"));
955952 printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
956953 printf(_(" --no-security-labels do not dump security label assignments\n"));
957954 printf(_(" --no-subscription-connect dump subscriptions so they don't connect on restore\n"));
@@ -3641,6 +3638,22 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
36413638 destroyPQExpBuffer(query);
36423639}
36433640
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+ }
36443657
36453658/*
36463659 * getSubscriptions
@@ -3649,7 +3662,6 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
36493662void
36503663getSubscriptions(Archive *fout)
36513664{
3652- DumpOptions *dopt = fout->dopt;
36533665 PQExpBuffer query;
36543666 PGresult *res;
36553667 SubscriptionInfo *subinfo;
@@ -3664,9 +3676,25 @@ getSubscriptions(Archive *fout)
36643676 int i,
36653677 ntups;
36663678
3667- if (!dopt->include_subscriptions || fout->remoteVersion < 100000)
3679+ if (fout->remoteVersion < 100000)
36683680 return;
36693681
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+
36703698 query = createPQExpBuffer();
36713699
36723700 resetPQExpBuffer(query);
@@ -3714,6 +3742,9 @@ getSubscriptions(Archive *fout)
37143742 if (strlen(subinfo[i].rolname) == 0)
37153743 write_msg(NULL, "WARNING: owner of subscription \"%s\" appears to be invalid\n",
37163744 subinfo[i].dobj.name);
3745+
3746+ /* Decide whether we want to dump it */
3747+ selectDumpableObject(&(subinfo[i].dobj), fout);
37173748 }
37183749 PQclear(res);
37193750
@@ -3735,7 +3766,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37353766 int npubnames = 0;
37363767 int i;
37373768
3738- if (dopt->dataOnly )
3769+ if (!(subinfo->dobj.dump & DUMP_COMPONENT_DEFINITION) )
37393770 return;
37403771
37413772 delq = createPQExpBuffer();
0 commit comments