Re: Create replication slot in pg_basebackup if requested and not yet present

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Michael Banck <michael(dot)banck(at)credativ(dot)de>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Create replication slot in pg_basebackup if requested and not yet present
Date: 2017-03-19 16:01:23
Message-ID: CABUevExRKrT+7bLMPC7uyCXsZ+8Q89-yBKnn3vWiHxPHVNt0hg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Mar 19, 2017 at 11:21 AM, Michael Banck <michael(dot)banck(at)credativ(dot)de>
wrote:

> Hi,
>
> with the default configuration improvements so far for 10, it seems to
> be very easy to setup streaming replication (at least locally):
>
> $ initdb --pgdata=data1
> $ pg_ctl --pgdata=data1 start
> $ pg_basebackup --pgdata=data2 --write-recovery-conf
> $ sed -i -e 's/^#port.=.5432/port = 5433/' \
> > -e 's/^#hot_standby.=.off/hot_standby = on/' \
> > data2/postgresql.conf
> $ pg_ctl --pgdata=data2 start
>
> (there might be a case for having hot_standby=on by default, but I think
> that got discussed elsewhere and is anyway a different thread).
>
> However, the above does not use replication slots, and if you want to do
> so, you get:
>
> $ pg_basebackup --pgdata=data2 --write-recovery-conf --slot=pg2
> 2017-03-19 11:04:37.978 CET [25362] ERROR: replication slot "pg2" does
> not exist
> pg_basebackup: could not send replication command "START_REPLICATION":
> ERROR: replication slot "pg2" does not exist
> pg_basebackup: child process exited with error 1
> pg_basebackup: removing data directory "data2"
>
> The error message is clear enough, but I wonder whether people will
> start writing streaming replication tutorials just glossing over this
> because it's one more step to run CREATE_REPLICATION_SLOT manually.
>
> So I propose the attached tiny patch to just create the slot (if it does
> not exist already) in pg_basebackup, somewhat similar to what
> pg_receivewal does, albeit unconditionally, if the user explicitly
> requested a slot:
>
> $ pg_basebackup --pgdata=data2 --write-recovery-conf --slot=pg2
> $ echo $?
> 0
> $ psql -c "DROP_REPLICATION_SLOT pg2" "host=127.0.0.1 port=5432
> replication=database user=mba dbname=postgres"
> SELECT
> $
>
> This would get us somewhat closer to near zero-config replication, in my
> opinion. Pardon me if that was discussed already and shot down
>
> Comments?
>

I think this is a good idea, since it makes replication slots easier to
use. The change to use temporary slots was good for backups, but didn't
help people setting up replicas.

I've been annoyed for a while we didn't have a "create slot" mode in
pg_basebackup, but doing it integrated like this is definitely a step even
better than that.

I think maybe we should output a message when the slot is created, at least
in verbose mode, to make sure people realize that happened. Does that seem
reasonable?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2017-03-19 16:06:02 Re: createlang/droplang deprecated
Previous Message Greg Stark 2017-03-19 15:40:03 Re: [PATCH] SortSupport for macaddr type