From 2cab724505487663b53f8af09c8e16a70c52014d Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Fri, 9 Dec 2016 12:00:00 -0500
Subject: [PATCH 4/8] fixup! Add SUBSCRIPTION catalog and DDL

---
 doc/src/sgml/catalogs.sgml                         | 28 ++++++-------
 doc/src/sgml/ref/alter_subscription.sgml           | 25 +++++-------
 doc/src/sgml/ref/create_subscription.sgml          | 47 ++++++++++------------
 doc/src/sgml/ref/drop_subscription.sgml            | 23 ++++++-----
 doc/src/sgml/ref/psql-ref.sgml                     |  6 +--
 src/backend/catalog/pg_subscription.c              |  2 +-
 src/backend/commands/subscriptioncmds.c            |  6 +--
 src/backend/parser/gram.y                          |  2 +-
 .../libpqwalreceiver/libpqwalreceiver.c            |  2 +-
 src/backend/tcop/utility.c                         |  5 +++
 src/bin/pg_dump/pg_dump.c                          |  7 +---
 src/test/regress/parallel_schedule                 |  2 +-
 12 files changed, 75 insertions(+), 80 deletions(-)

diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 51f062ef70..7b3e95bc9f 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -6216,19 +6216,18 @@ <title><structname>pg_subscription</structname></title>
   </indexterm>
 
   <para>
-   The <structname>pg_subscription</structname> catalog contains
-   all existing logical replication subscriptions.
+   The catalog <structname>pg_subscription</structname> contains all existing
+   logical replication subscriptions.
   </para>
 
   <para>
-   Unlike most system catalogs, <structname>pg_subscription</structname>
-   is shared across all databases of a cluster: there is only one
-   copy of <structname>pg_subscription</structname> per cluster, not
-   one per database.
+   Unlike most system catalogs, <structname>pg_subscription</structname> is
+   shared across all databases of a cluster: There is only one copy
+   of <structname>pg_subscription</structname> per cluster, not one per
+   database.
   </para>
 
   <table>
-
    <title><structname>pg_subscription</structname> Columns</title>
 
    <tgroup cols="4">
@@ -6252,16 +6251,15 @@ <title><structname>pg_subscription</structname> Columns</title>
      <row>
       <entry><structfield>subdbid</structfield></entry>
       <entry><type>oid</type></entry>
-      <entry></entry>
-      <entry>Oid of the database which the subscription resides in.</entry>
+      <entry><literal><link linkend="catalog-pg-database"><structname>pg_database</structname></link>.oid</literal></entry>
+      <entry>OID of the database which the subscription resides in</entry>
      </row>
 
      <row>
       <entry><structfield>subname</structfield></entry>
-      <entry><type>Name</type></entry>
+      <entry><type>name</type></entry>
       <entry></entry>
-      <entry>A unique, database-wide identifier for the replication
-      subscription.</entry>
+      <entry>Name of the subscription</entry>
      </row>
 
      <row>
@@ -6275,16 +6273,14 @@ <title><structname>pg_subscription</structname> Columns</title>
       <entry><structfield>subenabled</structfield></entry>
       <entry><type>bool</type></entry>
       <entry></entry>
-      <entry>If true, the subscription is enabled and should be replicating.
-      </entry>
+      <entry>If true, the subscription is enabled and should be replicating.</entry>
      </row>
 
      <row>
       <entry><structfield>subconninfo</structfield></entry>
       <entry><type>text</type></entry>
       <entry></entry>
-      <entry>Connection string to the upstream database.
-      </entry>
+      <entry>Connection string to the upstream database</entry>
      </row>
 
      <row>
diff --git a/doc/src/sgml/ref/alter_subscription.sgml b/doc/src/sgml/ref/alter_subscription.sgml
index 29e1a24a2f..a7cbdb85fa 100644
--- a/doc/src/sgml/ref/alter_subscription.sgml
+++ b/doc/src/sgml/ref/alter_subscription.sgml
@@ -39,8 +39,8 @@ <title>Description</title>
 
   <para>
    <command>ALTER SUBSCRIPTION</command> can change most of the subscription
-   attributes that can be specified in
-   <xref linkend="sql-createsubscription">.
+   properties that can be specified
+   in <xref linkend="sql-createsubscription">.
   </para>
  </refsect1>
 
@@ -52,26 +52,26 @@ <title>Parameters</title>
     <term><replaceable class="parameter">name</replaceable></term>
     <listitem>
      <para>
-      The name of a subscription whose attributes are to be altered.
+      The name of a subscription whose properties are to be altered.
      </para>
     </listitem>
    </varlistentry>
 
    <varlistentry>
-    <term>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</term>
-    <term>SET PUBLICATION <replaceable class="parameter">publication_name</replaceable></term>
-    <term>SLOT NAME = <replaceable class="parameter">slot_name</replaceable></term>
+    <term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term>
+    <term><literal>SET PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
+    <term><literal>SLOT NAME = <replaceable class="parameter">slot_name</replaceable></literal></term>
     <listitem>
      <para>
-      These clauses alter attributes originally set by
-      <xref linkend="SQL-CREATESUBSCRIPTION">. For more information, see the
-      <command>CREATE SUBSCRIPTION</command> reference page.
+      These clauses alter properties originally set by
+      <xref linkend="SQL-CREATESUBSCRIPTION">.  See there for more
+      information.
      </para>
     </listitem>
    </varlistentry>
 
    <varlistentry>
-    <term>ENABLE</term>
+    <term><literal>ENABLE</literal></term>
     <listitem>
      <para>
       Enables the previously disabled subscription, starting the logical
@@ -81,7 +81,7 @@ <title>Parameters</title>
    </varlistentry>
 
    <varlistentry>
-    <term>DISABLE</term>
+    <term><literal>DISABLE</literal></term>
     <listitem>
      <para>
       Disables the running subscription, stopping the logical replication
@@ -89,7 +89,6 @@ <title>Parameters</title>
      </para>
     </listitem>
    </varlistentry>
-
   </variablelist>
  </refsect1>
 
@@ -110,7 +109,6 @@ <title>Examples</title>
 ALTER SUBSCRIPTION mysub DISABLE;
 </programlisting>
   </para>
-
  </refsect1>
 
  <refsect1>
@@ -132,5 +130,4 @@ <title>See Also</title>
    <member><xref linkend="sql-alterpublication"></member>
   </simplelist>
  </refsect1>
-
 </refentry>
diff --git a/doc/src/sgml/ref/create_subscription.sgml b/doc/src/sgml/ref/create_subscription.sgml
index 3ae4cd89b6..a5cd0a16ff 100644
--- a/doc/src/sgml/ref/create_subscription.sgml
+++ b/doc/src/sgml/ref/create_subscription.sgml
@@ -16,7 +16,7 @@
 
  <refnamediv>
   <refname>CREATE SUBSCRIPTION</refname>
-  <refpurpose>define new subscription</refpurpose>
+  <refpurpose>define a new subscription</refpurpose>
  </refnamediv>
 
  <refsynopsisdiv>
@@ -35,23 +35,21 @@
   <title>Description</title>
 
   <para>
-   <command>CREATE SUBSCRIPTION</command> adds a new subscription for
-   a current database. The subscription name must be distinct from
-   the name of any existing subscription in the database cluster.
+   <command>CREATE SUBSCRIPTION</command> adds a new subscription for a
+   current database.  The subscription name must be distinct from the name of
+   any existing subscription in the database.
   </para>
 
   <para>
-   The subscription represents a replication connection to the publisher.
-   As such this command does not only add definition in the local catalogs
-   but also creates a replication slot on the publisher.
+   The subscription represents a replication connection to the publisher.  As
+   such this command does not only add definitions in the local catalogs but
+   also creates a replication slot on the publisher.
   </para>
 
   <para>
-   A logical replication worker will be started to replicate data for the
-   new subscription at the commit of the transaction where this command
-   was run.
+   A logical replication worker will be started to replicate data for the new
+   subscription at the commit of the transaction where this command is run.
   </para>
-
  </refsect1>
 
  <refsect1>
@@ -68,7 +66,7 @@ <title>Parameters</title>
    </varlistentry>
 
    <varlistentry>
-    <term>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</term>
+    <term><literal>CONNECTION '<replaceable class="parameter">conninfo</replaceable>'</literal></term>
     <listitem>
      <para>
       The connection string to the publisher.
@@ -77,7 +75,7 @@ <title>Parameters</title>
    </varlistentry>
 
    <varlistentry>
-    <term>PUBLICATION <replaceable class="parameter">publication_name</replaceable></term>
+    <term><literal>PUBLICATION <replaceable class="parameter">publication_name</replaceable></literal></term>
     <listitem>
      <para>
       Name(s) of the publications on the publisher to subscribe to.
@@ -86,11 +84,11 @@ <title>Parameters</title>
    </varlistentry>
 
    <varlistentry>
-    <term>ENABLED</term>
-    <term>DISABLED</term>
+    <term><literal>ENABLED</literal></term>
+    <term><literal>DISABLED</literal></term>
     <listitem>
      <para>
-      Specifies if the subscription should be actively replicating or
+      Specifies whether the subscription should be actively replicating or
       if it should be just setup but not started yet.  Note that the
       replication slot as described above is created in either case.
       <literal>ENABLED</literal> is the default.
@@ -99,18 +97,18 @@ <title>Parameters</title>
    </varlistentry>
 
    <varlistentry>
-    <term>CREATE SLOT</term>
-    <term>NOCREATE SLOT</term>
+    <term><literal>CREATE SLOT</literal></term>
+    <term><literal>NOCREATE SLOT</literal></term>
     <listitem>
      <para>
-      Specifies if the command should create the replication slot on the
+      Specifies whether the command should create the replication slot on the
       publisher. <literal>CREATE SLOT</literal> is the default.
      </para>
     </listitem>
    </varlistentry>
 
    <varlistentry>
-    <term>SLOT NAME = <replaceable class="parameter">slot_name</replaceable></term>
+    <term><literal>SLOT NAME = <replaceable class="parameter">slot_name</replaceable></literal></term>
     <listitem>
      <para>
       Name of the replication slot to use. The default behavior is to use
@@ -118,7 +116,6 @@ <title>Parameters</title>
      </para>
     </listitem>
    </varlistentry>
-
   </variablelist>
  </refsect1>
 
@@ -126,7 +123,7 @@ <title>Parameters</title>
   <title>Examples</title>
 
   <para>
-   Create a subscription to a different server which replicates tables in
+   Create a subscription to a remote server that replicates tables in
    the publications <literal>mypubclication</literal> and
    <literal>insert_only</literal> and starts replicating immediately on
    commit:
@@ -138,8 +135,8 @@ <title>Examples</title>
   </para>
 
   <para>
-   Create a subscription to a different server which replicates tables in
-   the <literal>insert_only</literal> publication and does not replicate
+   Create a subscription to a remote server that replicates tables in
+   the <literal>insert_only</literal> publication and does not start replicating
    until enabled at a later time.
 <programlisting>
 CREATE SUBSCRIPTION mysub
@@ -148,7 +145,6 @@ <title>Examples</title>
                WITH (DISABLED);
 </programlisting>
   </para>
-
  </refsect1>
 
  <refsect1>
@@ -170,5 +166,4 @@ <title>See Also</title>
    <member><xref linkend="sql-alterpublication"></member>
   </simplelist>
  </refsect1>
-
 </refentry>
diff --git a/doc/src/sgml/ref/drop_subscription.sgml b/doc/src/sgml/ref/drop_subscription.sgml
index de40a7660f..9f2fb93275 100644
--- a/doc/src/sgml/ref/drop_subscription.sgml
+++ b/doc/src/sgml/ref/drop_subscription.sgml
@@ -16,7 +16,7 @@
 
  <refnamediv>
   <refname>DROP SUBSCRIPTION</refname>
-  <refpurpose>remove an existing subscription</refpurpose>
+  <refpurpose>remove a subscription</refpurpose>
  </refnamediv>
 
  <refsynopsisdiv>
@@ -29,8 +29,8 @@
   <title>Description</title>
 
   <para>
-   <command>DROP SUBSCRIPTION</command> removes subscriptions from the
-   cluster.
+   <command>DROP SUBSCRIPTION</command> removes a subscription from the
+   database cluster.
   </para>
 
   <para>
@@ -38,11 +38,9 @@ <title>Description</title>
   </para>
 
   <para>
-   The replication worker associated with the subscription will not stop
-   until after <command>COMMIT</command> of the transaction which issued
-   this command.
+   The replication worker associated with the subscription will not stop until
+   after the transaction that issued this command has committed.
   </para>
-
  </refsect1>
 
  <refsect1>
@@ -63,9 +61,17 @@ <title>Parameters</title>
     <term><replaceable class="parameter">NODROP SLOT</replaceable></term>
     <listitem>
      <para>
-      Specifies if to drop slot on the publisher. The default is
+      Specifies whether to drop the replication slot on the publisher.  The
+      default is
       <literal>DROP SLOT</literal>.
      </para>
+
+     <para>
+      If the publisher is not reachable when the subscription is to be
+      dropped, then it is useful to specify <literal>NODROP SLOT</literal>.
+      But the replication slot on the publisher will then have to be removed
+      manually.
+     </para>
     </listitem>
    </varlistentry>
 
@@ -101,5 +107,4 @@ <title>See Also</title>
    <member><xref linkend="sql-altersubscription"></member>
   </simplelist>
  </refsect1>
-
 </refentry>
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 48ff9b95dc..640fe12bbf 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1618,12 +1618,12 @@ <title>Meta-Commands</title>
         <term><literal>\dRs[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
         <listitem>
         <para>
-        List replication subscriptions.
+        Lists replication subscriptions.
         If <replaceable class="parameter">pattern</replaceable> is
-        specified, only subscriptions whose names match the pattern are
+        specified, only those subscriptions whose names match the pattern are
         listed.
         If <literal>+</literal> is appended to the command name, additional
-        parameters of the subscriptions are shown.
+        properties of the subscriptions are shown.
         </para>
         </listitem>
       </varlistentry>
diff --git a/src/backend/catalog/pg_subscription.c b/src/backend/catalog/pg_subscription.c
index d5078fca2d..fe94779ef2 100644
--- a/src/backend/catalog/pg_subscription.c
+++ b/src/backend/catalog/pg_subscription.c
@@ -3,7 +3,7 @@
  * pg_subscription.c
  *		replication subscriptions
  *
- * Copyright (c) 2015, PostgreSQL Global Development Group
+ * Copyright (c) 2016, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
  *		src/backend/catalog/pg_subscription.c
diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c
index 1b8d589d1b..5a7312c0c4 100644
--- a/src/backend/commands/subscriptioncmds.c
+++ b/src/backend/commands/subscriptioncmds.c
@@ -57,7 +57,7 @@
  * Common option parsing function for CREATE and ALTER SUBSCRIPTION commands.
  *
  * Since not all options can be specified in both commands, this function
- * will report error on options if the target output pointer is NULL to
+ * will report an error on options if the target output pointer is NULL to
  * accomodate that.
  */
 static void
@@ -160,7 +160,7 @@ parse_subscription_options(List *options, char **conninfo,
 }
 
 /*
- * Auxiliary function to return a TEXT array out of a list of String nodes.
+ * Auxiliary function to return a text array out of a list of String nodes.
  */
 static Datum
 publicationListToArray(List *publist)
@@ -309,7 +309,7 @@ CreateSubscription(CreateSubscriptionStmt *stmt)
 		if (server_version / 100 > PG_VERSION_NUM / 100)
 			ereport(WARNING,
 					(errmsg("publisher major version %d is higher than subscriber "
-							"major version %d,  the logical replicatiion might "
+							"major version %d, logical replication might "
 							"not work correctly",
 							server_version/10000, PG_VERSION_NUM/10000)));
 
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 5baf580af9..95f68b6a3e 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -9019,7 +9019,7 @@ AlterPublicationStmt:
 
 /*****************************************************************************
  *
- * CREATE SUBSCRIPTION name [ WITH ] options
+ * CREATE SUBSCRIPTION name ...
  *
  *****************************************************************************/
 
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index 41a0ac1275..f99158e251 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -104,7 +104,7 @@ _PG_init(void)
 /*
  * Establish the connection to the primary server for XLOG streaming
  *
- * Return NULL on error and fills the err with palloced error message.
+ * Returns NULL on error and fills the err with palloc'ed error message.
  */
 static WalReceiverConn *
 libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index ce98420ff0..2273405426 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -216,6 +216,7 @@ check_xact_readonly(Node *parsetree)
 		case T_AlterPublicationStmt:
 		case T_CreateSubscriptionStmt:
 		case T_AlterSubscriptionStmt:
+		case T_DropSubscriptionStmt:
 			PreventCommandIfReadOnly(CreateCommandTag(parsetree));
 			PreventCommandIfParallelMode(CreateCommandTag(parsetree));
 			break;
@@ -3211,6 +3212,10 @@ GetCommandLogLevel(Node *parsetree)
 			lev = LOGSTMT_DDL;
 			break;
 
+		case T_DropSubscriptionStmt:
+			lev = LOGSTMT_DDL;
+			break;
+
 			/* already-planned queries */
 		case T_PlannedStmt:
 			{
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index e20e5e423a..4968c27ded 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -919,7 +919,7 @@ help(const char *progname)
 	printf(_("  --no-security-labels         do not dump security label assignments\n"));
 	printf(_("  --no-synchronized-snapshots  do not use synchronized snapshots in parallel jobs\n"));
 	printf(_("  --no-tablespaces             do not dump tablespace assignments\n"));
-	printf(_("  --no-create-subsription-slot do not create replication slot for dumped subscriptions\n"));
+	printf(_("  --no-create-subscription-slot do not create replication slot for dumped subscriptions\n"));
 	printf(_("  --no-unlogged-table-data     do not dump unlogged table data\n"));
 	printf(_("  --quote-all-identifiers      quote all identifiers, even if not key words\n"));
 	printf(_("  --section=SECTION            dump named section (pre-data, data, or post-data)\n"));
@@ -3600,9 +3600,6 @@ getSubscriptions(Archive *fout)
 
 	query = createPQExpBuffer();
 
-	if (g_verbose)
-		write_msg(NULL, "reading subscriptions\n");
-
 	resetPQExpBuffer(query);
 
 	/* Get the subscriptions in current database. */
@@ -3621,7 +3618,7 @@ getSubscriptions(Archive *fout)
 	if (ntups == 0)
 	{
 		/*
-		 * There are no publications defined. Clean up and return.
+		 * There are no subscriptions defined. Clean up and return.
 		 */
 		PQclear(res);
 		return;
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 0de902eb7a..e9b2bad6fd 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -97,7 +97,7 @@ test: rules psql_crosstab amutils
 # run by itself so it can run parallel workers
 test: select_parallel
 
-# no relation related tests can be put in thi group
+# no relation related tests can be put in this group
 test: publication subscription
 
 # ----------
-- 
2.11.0

