Don'st start streaming after creating a slot in pg_receivexlog
Hi,
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.
Michael, what do you think?
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 07/29/2015 10:37 AM, Andres Freund wrote:
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.
To be clear, I think "pg_receivexlog --create-slot" should only create
the slot, and exit.
- Heikki
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 29 July 2015 at 08:37, Andres Freund <andres@anarazel.de> wrote:
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.Michael, what do you think?
--drop-slot seems pointless, since you can just do that with psql
If we make --create-slot do nothing but add the slot, then that seems
pointless also
Would we need to add those options to all commands, when it can be done
with psql?
I'd suggest just removing --create-slot and --drop-slot altogether
--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Wed, Jul 29, 2015 at 4:51 PM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
On 07/29/2015 10:37 AM, Andres Freund wrote:
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.To be clear, I think "pg_receivexlog --create-slot" should only create the
slot, and exit.
Even if I would like to make pg_recvlogical and pg_receivexlog behave
as similarly as possible by having an additional switch --start in
pg_receivexlog to control if it starts to stream or not, this ship has
already sailed for backward-compatibility's sake... Then let's just
create the slot and exit().
--
Michael
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2015-07-29 08:54:40 +0100, Simon Riggs wrote:
--drop-slot seems pointless, since you can just do that with psql
If we make --create-slot do nothing but add the slot, then that seems
pointless also
Would we need to add those options to all commands, when it can be done
with psql?
They work over the replication protocol, which is handy, because it can
be done with the same user/permissions as the normal pg_receivexlog.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 07/29/2015 10:58 AM, Michael Paquier wrote:
On Wed, Jul 29, 2015 at 4:51 PM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
On 07/29/2015 10:37 AM, Andres Freund wrote:
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.To be clear, I think "pg_receivexlog --create-slot" should only create the
slot, and exit.Even if I would like to make pg_recvlogical and pg_receivexlog behave
as similarly as possible by having an additional switch --start in
pg_receivexlog to control if it starts to stream or not, this ship has
already sailed for backward-compatibility's sake... Then let's just
create the slot and exit().
Hmm. pg_receivelogical is basically a debugging tool. I don't think
anyone will have it integrated into production scripts etc. So maybe we
could just change it.
I'm not sure I understand the proposal though. If you don't specify
--create-slot, nor --start, what would the program do? Nothing?
- Heikki
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 29 July 2015 at 09:01, Andres Freund <andres@anarazel.de> wrote:
On 2015-07-29 08:54:40 +0100, Simon Riggs wrote:
--drop-slot seems pointless, since you can just do that with psql
If we make --create-slot do nothing but add the slot, then that seems
pointless alsoWould we need to add those options to all commands, when it can be done
with psql?They work over the replication protocol, which is handy, because it can
be done with the same user/permissions as the normal pg_receivexlog.
It's useful to separate permissions for creating/dropping a slot from using
it. A one-time act configures (or re-configures) how you wish the cluster
to look, another more regular task is to connect to the slot and use it.
But if you want to have a single user with privileges for both, you can
create that. I don't see it as something that we need to support in the
replication protocol, since that would require us to extend it every time
we think of something else.
Creating a temporary slot goes against the whole concept of slots, so using
the same id in the same script isn't actually needed, except maybe to
simplify testing.
--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Wed, Jul 29, 2015 at 10:02 AM, Heikki Linnakangas <hlinnaka@iki.fi>
wrote:
On 07/29/2015 10:58 AM, Michael Paquier wrote:
On Wed, Jul 29, 2015 at 4:51 PM, Heikki Linnakangas <hlinnaka@iki.fi>
wrote:On 07/29/2015 10:37 AM, Andres Freund wrote:
Heikki complained about pg_receivexlog --create-slot starting to stream
in his talk in St. Petersburg. Saying that that makes it a hard to
script feature - and I have to agree. Since that option is new to 9.5 we
can should change that behaviour now if we decide to.To be clear, I think "pg_receivexlog --create-slot" should only create
the
slot, and exit.Even if I would like to make pg_recvlogical and pg_receivexlog behave
as similarly as possible by having an additional switch --start in
pg_receivexlog to control if it starts to stream or not, this ship has
already sailed for backward-compatibility's sake... Then let's just
create the slot and exit().Hmm. pg_receivelogical is basically a debugging tool. I don't think anyone
will have it integrated into production scripts etc. So maybe we could just
change it.I'm not sure I understand the proposal though. If you don't specify
--create-slot, nor --start, what would the program do? Nothing?
Maybe we should make --start an optional flag for --create-slot in both
pg_recvlogical and pg_receivexlog?
So that if you didn't use --create-slot or --drop-slot, then it is assumed
that you want to start streaming. And if you're using --create-slot, you
can still start streaming right away, though not by default.
At the moment I find it odd that pg_recvlogical -S myslot doesn't start
streaming and require you to use --start explicitly.
--
*Oleksandr Shulgin*
*Database Engineer*
Mobile: +49 160 84-90-639
Email: oleksandr.shulgin@zalando.de
On 2015-07-29 09:23:43 +0100, Simon Riggs wrote:
Creating a temporary slot goes against the whole concept of slots, so using
the same id in the same script isn't actually needed, except maybe to
simplify testing.
The concept of a slot is to reserve resources. I don't see why it's
wrong to reserve resources temporarily.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jul 29, 2015 at 5:02 PM, Heikki Linnakangas wrote:
Hmm. pg_receivelogical is basically a debugging tool. I don't think anyone
will have it integrated into production scripts etc. So maybe we could just
change it.
This sounds good to me as well.
I'm not sure I understand the proposal though.
In short, I would propose the following:
- Have --create-slot only create a slot, then exit for both
pg_recvlogical and pg_receivexlog.
- Have --drop-slot drop a slot, then exit.
- Remove the --start switch in pg_recvlogical, and let the utility
start streaming by default.
By doing so both utilities will behave similarly with the same set of options.
If you don't specify
--create-slot, nor --start, what would the program do? Nothing?
Complain if neither --create-slot nor --drop-slot nor --start are specified:
$ pg_recvlogical -f - --slot toto -d postgres
pg_recvlogical: at least one action needs to be specified
Try "pg_recvlogical --help" for more information.
$ echo $?
1
--
Michael
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 29 July 2015 at 12:51, Michael Paquier <michael.paquier@gmail.com> wrote:
In short, I would propose the following:
- Have --create-slot only create a slot, then exit for both
pg_recvlogical and pg_receivexlog.
- Have --drop-slot drop a slot, then exit.
It makes more sense to create one new utility to issue replication commands
than to enhance multiple utility commands to have bizarre looking
additional features and modes.
pg_reputil --create-slot
pg_reputil --drop-slot
etc
though I prefer the idea of using psql and the already existing slot
functions than doing all of this extra code that needs maintaining.
- Remove the --start switch in pg_recvlogical, and let the utility
start streaming by default.
By doing so both utilities will behave similarly with the same set of
options.
+1
That way all the utilities have just one thing they do.
--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On 2015-07-29 13:53:31 +0100, Simon Riggs wrote:
It makes more sense to create one new utility to issue replication commands
than to enhance multiple utility commands to have bizarre looking
additional features and modes.pg_reputil --create-slot
pg_reputil --drop-slot
etc
Logical slots behave differently than physical slots and need different
options. So to me there's a fair point in having support for
manipulating logical slot in a tool around logical slots.
Additionally that support was there in 9.4 and I know at least of three
scripts that call pg_recvlogical to create logical slots. Admittedly one
of them is of my own creation.
though I prefer the idea of using psql and the already existing slot
functions than doing all of this extra code that needs maintaining.
It's not that uncommon to have replicas only access the primary for
replication type connections. So it seems completely sensible to use the
replication protocol to manage slots. And that you can't really do with
psql.
Andres
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jul 29, 2015 at 8:51 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
On Wed, Jul 29, 2015 at 5:02 PM, Heikki Linnakangas wrote:
Hmm. pg_receivelogical is basically a debugging tool. I don't think anyone
will have it integrated into production scripts etc. So maybe we could just
change it.This sounds good to me as well.
I'm not sure I understand the proposal though.
In short, I would propose the following:
- Have --create-slot only create a slot, then exit for both
pg_recvlogical and pg_receivexlog.
- Have --drop-slot drop a slot, then exit.
- Remove the --start switch in pg_recvlogical, and let the utility
start streaming by default.
By doing so both utilities will behave similarly with the same set of options.If you don't specify
--create-slot, nor --start, what would the program do? Nothing?Complain if neither --create-slot nor --drop-slot nor --start are specified:
$ pg_recvlogical -f - --slot toto -d postgres
pg_recvlogical: at least one action needs to be specified
Try "pg_recvlogical --help" for more information.
$ echo $?
1
Here is a patch implementing those things. IMO if-not-exists does not
make much sense anymore. Documentation has been shuffled a bit as
well.
--
Michael
Attachments:
20150729_pgrecv_slots.patchbinary/octet-stream; name=20150729_pgrecv_slots.patchDownload
diff --git a/doc/src/sgml/ref/pg_receivexlog.sgml b/doc/src/sgml/ref/pg_receivexlog.sgml
index a4c9892..451e6d4 100644
--- a/doc/src/sgml/ref/pg_receivexlog.sgml
+++ b/doc/src/sgml/ref/pg_receivexlog.sgml
@@ -93,16 +93,6 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
- <term><option>--if-not-exists</option></term>
- <listitem>
- <para>
- Do not not error out when <option>--create-slot</option> is specified
- and a slot with the specified name already exists.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
<term><option>-n</option></term>
<term><option>--no-loop</option></term>
<listitem>
@@ -273,7 +263,7 @@ PostgreSQL documentation
<listitem>
<para>
Create a new physical replication slot with the name specified in
- <option>--slot</option>, then start to stream WAL.
+ <option>--slot</option>, then exit.
</para>
</listitem>
</varlistentry>
diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml
index 4eda9eb..3686acf 100644
--- a/doc/src/sgml/ref/pg_recvlogical.sgml
+++ b/doc/src/sgml/ref/pg_recvlogical.sgml
@@ -44,63 +44,6 @@ PostgreSQL documentation
<title>Options</title>
<para>
- At least one of the following options must be specified to select an action:
-
- <variablelist>
-
- <varlistentry>
- <term><option>--create-slot</option></term>
- <listitem>
- <para>
- Create a new logical replication slot with the name specified by
- <option>--slot</option>, using the output plugin specified by
- <option>--plugin</option>, for the database specified
- by <option>--dbname</option>.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--drop-slot</option></term>
- <listitem>
- <para>
- Drop the replication slot with the name specified
- by <option>--slot</option>, then exit.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--start</option></term>
- <listitem>
- <para>
- Begin streaming changes from the logical replication slot specified
- by <option>--slot</option>, continuing until terminated by a
- signal. If the server side change stream ends with a server shutdown
- or disconnect, retry in a loop unless
- <option>--no-loop</option> is specified.
- </para>
-
- <para>
- The stream format is determined by the output plugin specified when
- the slot was created.
- </para>
-
- <para>
- The connection must be to the same database used to create the slot.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </para>
-
- <para>
- <option>--create-slot</option> and <option>--start</option> can be
- specified together. <option>--drop-slot</option> cannot be combined with
- another action.
- </para>
-
- <para>
The following command-line options control the location and format of the
output and other replication behavior:
@@ -146,30 +89,20 @@ PostgreSQL documentation
<term><option>--startpos=<replaceable>lsn</replaceable></option></term>
<listitem>
<para>
- In <option>--start</option> mode, start replication from the given
- LSN. For details on the effect of this, see the documentation
- in <xref linkend="logicaldecoding">
+ Start replication from the given LSN. For details on the effect of
+ this, see the documentation in <xref linkend="logicaldecoding">
and <xref linkend="protocol-replication">. Ignored in other modes.
</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>--if-not-exists</option></term>
- <listitem>
- <para>
- Do not not error out when <option>--create-slot</option> is specified
- and a slot with the specified name already exists.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
<term><option>-n</option></term>
<term><option>--no-loop</option></term>
<listitem>
<para>
- When the connection to the server is lost, do not retry in a loop, just exit.
+ When the connection to the server is lost, do not retry in a loop,
+ just exit.
</para>
</listitem>
</varlistentry>
@@ -214,7 +147,7 @@ PostgreSQL documentation
<term><option>--slot=<replaceable>slot_name</replaceable></option></term>
<listitem>
<para>
- In <option>--start</option> mode, use the existing logical replication slot named
+ Use the existing logical replication slot named
<replaceable>slot_name</replaceable>. In <option>--create-slot</option>
mode, create the slot with this name. In <option>--drop-slot</option>
mode, delete the slot with this name.
@@ -328,6 +261,49 @@ PostgreSQL documentation
</para>
<para>
+ <application>pg_recvlogical</application> can perform one of the two
+ following actions in order to control logical replication slots:
+
+ <variablelist>
+ <varlistentry>
+ <term><option>--create-slot</option></term>
+ <listitem>
+ <para>
+ Create a new logical replication slot with the name specified by
+ <option>--slot</option>, using the output plugin specified by
+ <option>--plugin</option>, for the database specified
+ by <option>--dbname</option>, then exit.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>--drop-slot</option></term>
+ <listitem>
+ <para>
+ Drop the replication slot with the name specified
+ by <option>--slot</option>, then exit.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+
+ <para>
+ The stream format is determined by the output plugin specified when
+ the slot was created.
+ </para>
+
+ <para>
+ The connection must be to the same database used to create the slot.
+ </para>
+
+ <para>
+ <option>--create-slot</option> and <option>--drop-slot</option> cannot
+ be combined together.
+ </para>
+
+ <para>
The following additional options are available:
<variablelist>
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 00536bd..0fde0f0 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -38,7 +38,6 @@ static int noloop = 0;
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static volatile bool time_to_abort = false;
static bool do_create_slot = false;
-static bool slot_exists_ok = false;
static bool do_drop_slot = false;
static bool synchronous = false;
@@ -67,7 +66,6 @@ usage(void)
printf(_(" %s [OPTION]...\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -D, --directory=DIR receive transaction log files into this directory\n"));
- printf(_(" --if-not-exists do not treat naming conflicts as an error when creating a slot\n"));
printf(_(" -n, --no-loop do not loop on connection lost\n"));
printf(_(" -s, --status-interval=SECS\n"
" time between status packets sent to server (default: %d)\n"), (standby_message_timeout / 1000));
@@ -373,8 +371,7 @@ main(int argc, char **argv)
/* action */
{"create-slot", no_argument, NULL, 1},
{"drop-slot", no_argument, NULL, 2},
- {"if-not-exists", no_argument, NULL, 3},
- {"synchronous", no_argument, NULL, 4},
+ {"synchronous", no_argument, NULL, 3},
{NULL, 0, NULL, 0}
};
@@ -458,9 +455,6 @@ main(int argc, char **argv)
do_drop_slot = true;
break;
case 3:
- slot_exists_ok = true;
- break;
- case 4:
synchronous = true;
break;
default:
@@ -508,7 +502,7 @@ main(int argc, char **argv)
/*
* Required arguments
*/
- if (basedir == NULL && !do_drop_slot)
+ if (basedir == NULL && !do_drop_slot && !do_create_slot)
{
fprintf(stderr, _("%s: no target directory specified\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
@@ -519,7 +513,7 @@ main(int argc, char **argv)
/*
* Check existence of destination folder.
*/
- if (!do_drop_slot)
+ if (!do_drop_slot && !do_create_slot)
{
DIR *dir = get_destination_dir(basedir);
@@ -581,9 +575,9 @@ main(int argc, char **argv)
_("%s: creating replication slot \"%s\"\n"),
progname, replication_slot);
- if (!CreateReplicationSlot(conn, replication_slot, NULL, true,
- slot_exists_ok))
+ if (!CreateReplicationSlot(conn, replication_slot, NULL, true))
disconnect_and_exit(1);
+ disconnect_and_exit(0);
}
/*
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index f189f71..573fe7a 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -38,8 +38,6 @@ static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static int fsync_interval = 10 * 1000; /* 10 sec = default */
static XLogRecPtr startpos = InvalidXLogRecPtr;
static bool do_create_slot = false;
-static bool slot_exists_ok = false;
-static bool do_start_slot = false;
static bool do_drop_slot = false;
/* filled pairwise with option, value. value may be NULL */
@@ -68,15 +66,10 @@ usage(void)
progname);
printf(_("Usage:\n"));
printf(_(" %s [OPTION]...\n"), progname);
- printf(_("\nAction to be performed:\n"));
- printf(_(" --create-slot create a new replication slot (for the slot's name see --slot)\n"));
- printf(_(" --drop-slot drop the replication slot (for the slot's name see --slot)\n"));
- printf(_(" --start start streaming in a replication slot (for the slot's name see --slot)\n"));
printf(_("\nOptions:\n"));
printf(_(" -f, --file=FILE receive log into this file, - for stdout\n"));
printf(_(" -F --fsync-interval=SECS\n"
" time between fsyncs to the output file (default: %d)\n"), (fsync_interval / 1000));
- printf(_(" --if-not-exists do not treat naming conflicts as an error when creating a slot\n"));
printf(_(" -I, --startpos=LSN where in an existing slot should the streaming start\n"));
printf(_(" -n, --no-loop do not loop on connection lost\n"));
printf(_(" -o, --option=NAME[=VALUE]\n"
@@ -96,6 +89,9 @@ usage(void)
printf(_(" -U, --username=NAME connect as specified database user\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
+ printf(_("\nOptional actions:\n"));
+ printf(_(" --create-slot create a new replication slot (for the slot's name see --slot)\n"));
+ printf(_(" --drop-slot drop the replication slot (for the slot's name see --slot)\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
}
@@ -633,9 +629,7 @@ main(int argc, char **argv)
{"slot", required_argument, NULL, 'S'},
/* action */
{"create-slot", no_argument, NULL, 1},
- {"start", no_argument, NULL, 2},
- {"drop-slot", no_argument, NULL, 3},
- {"if-not-exists", no_argument, NULL, 4},
+ {"drop-slot", no_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
int c;
@@ -762,14 +756,8 @@ main(int argc, char **argv)
do_create_slot = true;
break;
case 2:
- do_start_slot = true;
- break;
- case 3:
do_drop_slot = true;
break;
- case 4:
- slot_exists_ok = true;
- break;
default:
@@ -806,7 +794,7 @@ main(int argc, char **argv)
exit(1);
}
- if (do_start_slot && outfile == NULL)
+ if (outfile == NULL && !do_drop_slot && !do_create_slot)
{
fprintf(stderr, _("%s: no target file specified\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
@@ -822,17 +810,9 @@ main(int argc, char **argv)
exit(1);
}
- if (!do_drop_slot && !do_create_slot && !do_start_slot)
- {
- fprintf(stderr, _("%s: at least one action needs to be specified\n"), progname);
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
- progname);
- exit(1);
- }
-
- if (do_drop_slot && (do_create_slot || do_start_slot))
+ if (do_drop_slot && do_create_slot)
{
- fprintf(stderr, _("%s: cannot use --create-slot or --start together with --drop-slot\n"), progname);
+ fprintf(stderr, _("%s: cannot use --create-slot together with --drop-slot\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
@@ -886,6 +866,7 @@ main(int argc, char **argv)
if (!DropReplicationSlot(conn, replication_slot))
disconnect_and_exit(1);
+ disconnect_and_exit(0);
}
/* Create a replication slot. */
@@ -896,14 +877,10 @@ main(int argc, char **argv)
_("%s: creating replication slot \"%s\"\n"),
progname, replication_slot);
- if (!CreateReplicationSlot(conn, replication_slot, plugin,
- false, slot_exists_ok))
+ if (!CreateReplicationSlot(conn, replication_slot, plugin, false))
disconnect_and_exit(1);
- startpos = InvalidXLogRecPtr;
- }
-
- if (!do_start_slot)
disconnect_and_exit(0);
+ }
/* Stream loop */
while (true)
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 91f919c..d61899c 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -316,7 +316,7 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
*/
bool
CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
- bool is_physical, bool slot_exists_ok)
+ bool is_physical)
{
PQExpBuffer query;
PGresult *res;
@@ -340,21 +340,12 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
{
const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
- if (slot_exists_ok && strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
- {
- destroyPQExpBuffer(query);
- PQclear(res);
- return true;
- }
- else
- {
- fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
- progname, query->data, PQerrorMessage(conn));
+ fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
+ progname, query->data, PQerrorMessage(conn));
- destroyPQExpBuffer(query);
- PQclear(res);
- return false;
- }
+ destroyPQExpBuffer(query);
+ PQclear(res);
+ return false;
}
if (PQntuples(res) != 1 || PQnfields(res) != 4)
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index b95f83f..6d5e88d 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -32,8 +32,7 @@ extern PGconn *GetConnection(void);
/* Replication commands */
extern bool CreateReplicationSlot(PGconn *conn, const char *slot_name,
- const char *plugin, bool is_physical,
- bool slot_exists_ok);
+ const char *plugin, bool is_physical);
extern bool DropReplicationSlot(PGconn *conn, const char *slot_name);
extern bool RunIdentifySystem(PGconn *conn, char **sysid,
TimeLineID *starttli,
On 2015-07-29 22:17:27 +0900, Michael Paquier wrote:
Here is a patch implementing those things. IMO if-not-exists does not
make much sense anymore
What? It's rather useful to be able to discern between 'slot was already
there' and 'oops, some error occured'. -1
To me the pg_recvlogical changes are pretty pointless.
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jul 29, 2015 at 10:15 PM, Andres Freund wrote:
It's not that uncommon to have replicas only access the primary for
replication type connections. So it seems completely sensible to use the
replication protocol to manage slots. And that you can't really do with
psql.
Actually, you can. CREATE_REPLICATION_SLOT is one of the commands that
work with psql, but that's not really practical compared to what
pg_recvlogical and pg_receivexlog can do.
$ psql -d "replication=1"
=# CREATE_REPLICATION_SLOT hoge PHYSICAL;
slot_name | consistent_point | snapshot_name | output_plugin
-----------+------------------+---------------+---------------
hoge | 0/0 | null | null
(1 row)
--
Michael
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2015-07-29 22:21:04 +0900, Michael Paquier wrote:
On Wed, Jul 29, 2015 at 10:15 PM, Andres Freund wrote:
It's not that uncommon to have replicas only access the primary for
replication type connections. So it seems completely sensible to use the
replication protocol to manage slots. And that you can't really do with
psql.Actually, you can. CREATE_REPLICATION_SLOT is one of the commands that
work with psql
I do know that, I wrote the bit in the docs explaining that that's
possible...
But using replication connections that way in psql makes requires it to
be invoked in a different way and makes it it impossible to specify the
database name in a normal way etc. You can also run into commands that
give you 'unexpected result status' errors and such. I don't think
that's a good default interface.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Wed, Jul 29, 2015 at 10:20 PM, Andres Freund <andres@anarazel.de> wrote:
On 2015-07-29 22:17:27 +0900, Michael Paquier wrote:
Here is a patch implementing those things. IMO if-not-exists does not
make much sense anymoreWhat? It's rather useful to be able to discern between 'slot was already
there' and 'oops, some error occured'. -1
OK, fine.
To me the pg_recvlogical changes are pretty pointless.
OK, you wrote it after all. I won't insist on it. So, perhaps the
attached is more convincing then? It just changes --create-slot to
leave immediately after creation to address the complain of this
thread.
--
Michael
Attachments:
20150730_pgrecv_slots_v2.patchbinary/octet-stream; name=20150730_pgrecv_slots_v2.patchDownload
diff --git a/doc/src/sgml/ref/pg_receivexlog.sgml b/doc/src/sgml/ref/pg_receivexlog.sgml
index a4c9892..0e6ec1c 100644
--- a/doc/src/sgml/ref/pg_receivexlog.sgml
+++ b/doc/src/sgml/ref/pg_receivexlog.sgml
@@ -273,7 +273,7 @@ PostgreSQL documentation
<listitem>
<para>
Create a new physical replication slot with the name specified in
- <option>--slot</option>, then start to stream WAL.
+ <option>--slot</option>, then exit.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 00536bd..ca648d9 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -508,7 +508,7 @@ main(int argc, char **argv)
/*
* Required arguments
*/
- if (basedir == NULL && !do_drop_slot)
+ if (basedir == NULL && !do_drop_slot && !do_create_slot)
{
fprintf(stderr, _("%s: no target directory specified\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
@@ -519,7 +519,7 @@ main(int argc, char **argv)
/*
* Check existence of destination folder.
*/
- if (!do_drop_slot)
+ if (!do_drop_slot && !do_create_slot)
{
DIR *dir = get_destination_dir(basedir);
@@ -584,6 +584,7 @@ main(int argc, char **argv)
if (!CreateReplicationSlot(conn, replication_slot, NULL, true,
slot_exists_ok))
disconnect_and_exit(1);
+ disconnect_and_exit(0);
}
/*
On 2015-07-30 17:14:16 +0900, Michael Paquier wrote:
So, perhaps the attached is more convincing then? It just changes
--create-slot to leave immediately after creation to address the
complain of this thread. -- Michael
Pushed that. Thanks!
Andres
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers