From 2cab724505487663b53f8af09c8e16a70c52014d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut 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 @@ <structname>pg_subscription</structname> - The pg_subscription catalog contains - all existing logical replication subscriptions. + The catalog pg_subscription contains all existing + logical replication subscriptions. - Unlike most system catalogs, pg_subscription - is shared across all databases of a cluster: there is only one - copy of pg_subscription per cluster, not - one per database. + Unlike most system catalogs, pg_subscription is + shared across all databases of a cluster: There is only one copy + of pg_subscription per cluster, not one per + database. - <structname>pg_subscription</structname> Columns @@ -6252,16 +6251,15 @@ <structname>pg_subscription</structname> Columns subdbid oid - - Oid of the database which the subscription resides in. + pg_database.oid + OID of the database which the subscription resides in subname - Name + name - A unique, database-wide identifier for the replication - subscription. + Name of the subscription @@ -6275,16 +6273,14 @@ <structname>pg_subscription</structname> Columns subenabled bool - If true, the subscription is enabled and should be replicating. - + If true, the subscription is enabled and should be replicating. subconninfo text - Connection string to the upstream database. - + Connection string to the upstream database 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 @@ Description ALTER SUBSCRIPTION can change most of the subscription - attributes that can be specified in - . + properties that can be specified + in . @@ -52,26 +52,26 @@ Parameters name - The name of a subscription whose attributes are to be altered. + The name of a subscription whose properties are to be altered. - CONNECTION 'conninfo' - SET PUBLICATION publication_name - SLOT NAME = slot_name + CONNECTION 'conninfo' + SET PUBLICATION publication_name + SLOT NAME = slot_name - These clauses alter attributes originally set by - . For more information, see the - CREATE SUBSCRIPTION reference page. + These clauses alter properties originally set by + . See there for more + information. - ENABLE + ENABLE Enables the previously disabled subscription, starting the logical @@ -81,7 +81,7 @@ Parameters - DISABLE + DISABLE Disables the running subscription, stopping the logical replication @@ -89,7 +89,6 @@ Parameters - @@ -110,7 +109,6 @@ Examples ALTER SUBSCRIPTION mysub DISABLE; - @@ -132,5 +130,4 @@ See Also - 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 @@ CREATE SUBSCRIPTION - define new subscription + define a new subscription @@ -35,23 +35,21 @@ Description - CREATE SUBSCRIPTION 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. + CREATE SUBSCRIPTION adds a new subscription for a + current database. The subscription name must be distinct from the name of + any existing subscription in the database. - 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. - 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. - @@ -68,7 +66,7 @@ Parameters - CONNECTION 'conninfo' + CONNECTION 'conninfo' The connection string to the publisher. @@ -77,7 +75,7 @@ Parameters - PUBLICATION publication_name + PUBLICATION publication_name Name(s) of the publications on the publisher to subscribe to. @@ -86,11 +84,11 @@ Parameters - ENABLED - DISABLED + ENABLED + DISABLED - 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. ENABLED is the default. @@ -99,18 +97,18 @@ Parameters - CREATE SLOT - NOCREATE SLOT + CREATE SLOT + NOCREATE SLOT - Specifies if the command should create the replication slot on the + Specifies whether the command should create the replication slot on the publisher. CREATE SLOT is the default. - SLOT NAME = slot_name + SLOT NAME = slot_name Name of the replication slot to use. The default behavior is to use @@ -118,7 +116,6 @@ Parameters - @@ -126,7 +123,7 @@ Parameters Examples - Create a subscription to a different server which replicates tables in + Create a subscription to a remote server that replicates tables in the publications mypubclication and insert_only and starts replicating immediately on commit: @@ -138,8 +135,8 @@ Examples - Create a subscription to a different server which replicates tables in - the insert_only publication and does not replicate + Create a subscription to a remote server that replicates tables in + the insert_only publication and does not start replicating until enabled at a later time. CREATE SUBSCRIPTION mysub @@ -148,7 +145,6 @@ Examples WITH (DISABLED); - @@ -170,5 +166,4 @@ See Also - 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 @@ DROP SUBSCRIPTION - remove an existing subscription + remove a subscription @@ -29,8 +29,8 @@ Description - DROP SUBSCRIPTION removes subscriptions from the - cluster. + DROP SUBSCRIPTION removes a subscription from the + database cluster. @@ -38,11 +38,9 @@ Description - The replication worker associated with the subscription will not stop - until after COMMIT 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. - @@ -63,9 +61,17 @@ Parameters NODROP SLOT - Specifies if to drop slot on the publisher. The default is + Specifies whether to drop the replication slot on the publisher. The + default is DROP SLOT. + + + If the publisher is not reachable when the subscription is to be + dropped, then it is useful to specify NODROP SLOT. + But the replication slot on the publisher will then have to be removed + manually. + @@ -101,5 +107,4 @@ See Also - 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 @@ Meta-Commands \dRs[+] [ pattern ] - List replication subscriptions. + Lists replication subscriptions. If pattern is - specified, only subscriptions whose names match the pattern are + specified, only those subscriptions whose names match the pattern are listed. If + is appended to the command name, additional - parameters of the subscriptions are shown. + properties of the subscriptions are shown. 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