Addition of pg_dump --no-publications

Started by Michael Paquierover 8 years ago6 messages
#1Michael Paquier
michael.paquier@gmail.com

Hi all,

I imagine that pg_dump -s would be the basic operation that users
would do first before creating a subcription on a secondary node, but
what I find surprising is that publications are dumped by default. I
don't find confusing that those are actually included by default to be
consistent with the way subcriptions are handled, what I find
confusing is that there are no options to not dump them, and no
options to bypass their restore.

So, any opinions about having pg_dump/pg_restore --no-publications?
Thanks,
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#1)
1 attachment(s)
Re: Addition of pg_dump --no-publications

On Thu, May 11, 2017 at 3:19 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I imagine that pg_dump -s would be the basic operation that users
would do first before creating a subcription on a secondary node, but
what I find surprising is that publications are dumped by default. I
don't find confusing that those are actually included by default to be
consistent with the way subcriptions are handled, what I find
confusing is that there are no options to not dump them, and no
options to bypass their restore.

So, any opinions about having pg_dump/pg_restore --no-publications?

And that's really a boring patch, giving the attached.
--
Michael

Attachments:

pgdump-no-pubs.patchapplication/octet-stream; name=pgdump-no-pubs.patchDownload
diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index d326f08b07..bb0bf5d566 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -790,6 +790,15 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>--no-publications</option></term>
+      <listitem>
+       <para>
+        Do not dump publications.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>--no-security-labels</option></term>
       <listitem>
        <para>
diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml
index 60e67a2c7b..b45e813486 100644
--- a/doc/src/sgml/ref/pg_dumpall.sgml
+++ b/doc/src/sgml/ref/pg_dumpall.sgml
@@ -346,6 +346,15 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>--no-publications</option></term>
+      <listitem>
+       <para>
+        Do not dump publications.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>--no-security-labels</option></term>
       <listitem>
        <para>
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index 943378530b..f623cc04d2 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -582,6 +582,16 @@
      </varlistentry>
 
      <varlistentry>
+      <term><option>--no-publications</option></term>
+      <listitem>
+       <para>
+        Do not output commands to restore publications, even if the archive
+        contains them.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>--no-security-labels</option></term>
       <listitem>
        <para>
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index d00262cb9e..d10b46084e 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -74,6 +74,7 @@ typedef struct _restoreOptions
 	int			dump_inserts;
 	int			column_inserts;
 	int			if_exists;
+	int			no_publications;		/* Skip publication entries */
 	int			no_security_labels;		/* Skip security label entries */
 	int			no_subscriptions;		/* Skip subscription entries */
 	int			strict_names;
@@ -146,6 +147,7 @@ typedef struct _dumpOptions
 	int			column_inserts;
 	int			if_exists;
 	int			no_security_labels;
+	int			no_publications;
 	int			no_subscriptions;
 	int			no_synchronized_snapshots;
 	int			no_unlogged_table_data;
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 751f746364..9df5f2ebc8 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -166,6 +166,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
 
 	dopt->disable_dollar_quoting = ropt->disable_dollar_quoting;
 	dopt->dump_inserts = ropt->dump_inserts;
+	dopt->no_publications = ropt->no_publications;
 	dopt->no_security_labels = ropt->no_security_labels;
 	dopt->no_subscriptions = ropt->no_subscriptions;
 	dopt->lockWaitTimeout = ropt->lockWaitTimeout;
@@ -2792,6 +2793,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
 	if (ropt->aclsSkip && _tocEntryIsACL(te))
 		return 0;
 
+	/* If it's a publication, maybe ignore it */
+	if (ropt->no_publications && strcmp(te->desc, "PUBLICATION") == 0)
+		return 0;
+
 	/* If it's security labels, maybe ignore it */
 	if (ropt->no_security_labels && strcmp(te->desc, "SECURITY LABEL") == 0)
 		return 0;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index d724b11935..39e9a4c407 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -352,6 +352,7 @@ main(int argc, char **argv)
 		{"snapshot", required_argument, NULL, 6},
 		{"strict-names", no_argument, &strict_names, 1},
 		{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
+		{"no-publications", no_argument, &dopt.no_publications, 1},
 		{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
 		{"no-synchronized-snapshots", no_argument, &dopt.no_synchronized_snapshots, 1},
 		{"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
@@ -862,6 +863,7 @@ main(int argc, char **argv)
 	ropt->use_setsessauth = dopt.use_setsessauth;
 	ropt->disable_dollar_quoting = dopt.disable_dollar_quoting;
 	ropt->dump_inserts = dopt.dump_inserts;
+	ropt->no_publications = dopt.no_publications;
 	ropt->no_security_labels = dopt.no_security_labels;
 	ropt->no_subscriptions = dopt.no_subscriptions;
 	ropt->lockWaitTimeout = dopt.lockWaitTimeout;
@@ -951,6 +953,7 @@ help(const char *progname)
 	printf(_("  --exclude-table-data=TABLE   do NOT dump data for the named table(s)\n"));
 	printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
 	printf(_("  --inserts                    dump data as INSERT commands, rather than COPY\n"));
+	printf(_("  --no-publications            do not dump publications\n"));
 	printf(_("  --no-security-labels         do not dump security label assignments\n"));
 	printf(_("  --no-subscriptions           do not dump subscriptions\n"));
 	printf(_("  --no-synchronized-snapshots  do not use synchronized snapshots in parallel jobs\n"));
@@ -3376,6 +3379,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
 void
 getPublications(Archive *fout)
 {
+	DumpOptions *dopt = fout->dopt;
 	PQExpBuffer query;
 	PGresult   *res;
 	PublicationInfo *pubinfo;
@@ -3390,7 +3394,7 @@ getPublications(Archive *fout)
 	int			i,
 				ntups;
 
-	if (fout->remoteVersion < 100000)
+	if (dopt->no_publications || fout->remoteVersion < 100000)
 		return;
 
 	query = createPQExpBuffer();
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index d91c4e1cd3..cf0a932fdf 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -74,6 +74,7 @@ static int	if_exists = 0;
 static int	inserts = 0;
 static int	no_tablespaces = 0;
 static int	use_setsessauth = 0;
+static int	no_publications = 0;
 static int	no_security_labels = 0;
 static int	no_subscriptions = 0;
 static int	no_unlogged_table_data = 0;
@@ -129,6 +130,7 @@ main(int argc, char *argv[])
 		{"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
 		{"role", required_argument, NULL, 3},
 		{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+		{"no-publications", no_argument, &no_publications, 1},
 		{"no-security-labels", no_argument, &no_security_labels, 1},
 		{"no-subscriptions", no_argument, &no_subscriptions, 1},
 		{"no-sync", no_argument, NULL, 4},
@@ -385,6 +387,8 @@ main(int argc, char *argv[])
 		appendPQExpBufferStr(pgdumpopts, " --quote-all-identifiers");
 	if (use_setsessauth)
 		appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
+	if (no_publications)
+		appendPQExpBufferStr(pgdumpopts, " --no-publications");
 	if (no_security_labels)
 		appendPQExpBufferStr(pgdumpopts, " --no-security-labels");
 	if (no_subscriptions)
@@ -594,6 +598,7 @@ help(void)
 	printf(_("  --disable-triggers           disable triggers during data-only restore\n"));
 	printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
 	printf(_("  --inserts                    dump data as INSERT commands, rather than COPY\n"));
+	printf(_("  --no-publications            do not dump publications\n"));
 	printf(_("  --no-security-labels         do not dump security label assignments\n"));
 	printf(_("  --no-subscriptions           do not dump subscriptions\n"));
 	printf(_("  --no-sync                    do not wait for changes to be written safely to disk\n"));
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 46830ea2a4..1e6835d529 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -71,6 +71,7 @@ main(int argc, char **argv)
 	static int	no_data_for_failed_tables = 0;
 	static int	outputNoTablespaces = 0;
 	static int	use_setsessauth = 0;
+	static int	no_publications = 0;
 	static int	no_security_labels = 0;
 	static int	no_subscriptions = 0;
 	static int	strict_names = 0;
@@ -118,6 +119,7 @@ main(int argc, char **argv)
 		{"section", required_argument, NULL, 3},
 		{"strict-names", no_argument, &strict_names, 1},
 		{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+		{"no-publications", no_argument, &no_publications, 1},
 		{"no-security-labels", no_argument, &no_security_labels, 1},
 		{"no-subscriptions", no_argument, &no_subscriptions, 1},
 
@@ -356,6 +358,7 @@ main(int argc, char **argv)
 	opts->noDataForFailedTables = no_data_for_failed_tables;
 	opts->noTablespace = outputNoTablespaces;
 	opts->use_setsessauth = use_setsessauth;
+	opts->no_publications = no_publications;
 	opts->no_security_labels = no_security_labels;
 	opts->no_subscriptions = no_subscriptions;
 
@@ -479,6 +482,7 @@ usage(const char *progname)
 	printf(_("  --if-exists                  use IF EXISTS when dropping objects\n"));
 	printf(_("  --no-data-for-failed-tables  do not restore data of tables that could not be\n"
 			 "                               created\n"));
+	printf(_("  --no-publications            do not restore publications\n"));
 	printf(_("  --no-security-labels         do not restore security labels\n"));
 	printf(_("  --no-subscriptions           do not restore subscriptions\n"));
 	printf(_("  --no-tablespaces             do not restore tablespace assignments\n"));
#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#2)
Re: Addition of pg_dump --no-publications

On 5/11/17 21:59, Michael Paquier wrote:

On Thu, May 11, 2017 at 3:19 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I imagine that pg_dump -s would be the basic operation that users
would do first before creating a subcription on a secondary node, but
what I find surprising is that publications are dumped by default. I
don't find confusing that those are actually included by default to be
consistent with the way subcriptions are handled, what I find
confusing is that there are no options to not dump them, and no
options to bypass their restore.

So, any opinions about having pg_dump/pg_restore --no-publications?

And that's really a boring patch, giving the attached.

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4David Fetter
david@fetter.org
In reply to: Michael Paquier (#2)
Re: Addition of pg_dump --no-publications

On Fri, May 12, 2017 at 10:59:27AM +0900, Michael Paquier wrote:

On Thu, May 11, 2017 at 3:19 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I imagine that pg_dump -s would be the basic operation that users
would do first before creating a subcription on a secondary node, but
what I find surprising is that publications are dumped by default. I
don't find confusing that those are actually included by default to be
consistent with the way subcriptions are handled, what I find
confusing is that there are no options to not dump them, and no
options to bypass their restore.

So, any opinions about having pg_dump/pg_restore --no-publications?

And that's really a boring patch, giving the attached.

While it's consistent with surrounding code, I find the use of ints to
express what is in essence a boolean condition puzzling. Any
insights?

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Fetter (#4)
Re: Addition of pg_dump --no-publications

David Fetter <david@fetter.org> writes:

While it's consistent with surrounding code, I find the use of ints to
express what is in essence a boolean condition puzzling. Any
insights?

IIRC, it's forced by the getopt_long API, particularly the way that
the long-options struct has to be declared.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#3)
Re: Addition of pg_dump --no-publications

On Fri, May 12, 2017 at 10:19 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 5/11/17 21:59, Michael Paquier wrote:

On Thu, May 11, 2017 at 3:19 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

I imagine that pg_dump -s would be the basic operation that users
would do first before creating a subcription on a secondary node, but
what I find surprising is that publications are dumped by default. I
don't find confusing that those are actually included by default to be
consistent with the way subcriptions are handled, what I find
confusing is that there are no options to not dump them, and no
options to bypass their restore.

So, any opinions about having pg_dump/pg_restore --no-publications?

And that's really a boring patch, giving the attached.

committed

Thanks.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers