Re: pgsql: Introduce replication slots.

Lists: pgsql-committers
From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Introduce replication slots.
Date: 2014-02-01 03:50:47
Message-ID: E1W9RbT-0003e1-89@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Introduce replication slots.

Replication slots are a crash-safe data structure which can be created
on either a master or a standby to prevent premature removal of
write-ahead log segments needed by a standby, as well as (with
hot_standby_feedback=on) pruning of tuples whose removal would cause
replication conflicts. Slots have some advantages over existing
techniques, as explained in the documentation.

In a few places, we refer to the type of replication slots introduced
by this patch as "physical" slots, because forthcoming patches for
logical decoding will also have slots, but with somewhat different
properties.

Andres Freund and Robert Haas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/858ec11858a914d4c380971985709b6d6b7dd6fc

Modified Files
--------------
doc/src/sgml/catalogs.sgml | 99 ++
doc/src/sgml/config.sgml | 19 +
doc/src/sgml/func.sgml | 70 ++
doc/src/sgml/high-availability.sgml | 94 +-
doc/src/sgml/protocol.sgml | 64 +-
doc/src/sgml/recovery-config.sgml | 16 +
doc/src/sgml/ref/pg_receivexlog.sgml | 18 +
src/backend/access/transam/xlog.c | 95 +-
src/backend/catalog/system_views.sql | 12 +
src/backend/replication/Makefile | 2 +-
src/backend/replication/README | 5 +-
src/backend/replication/basebackup.c | 4 +
.../libpqwalreceiver/libpqwalreceiver.c | 16 +-
src/backend/replication/repl_gram.y | 54 +-
src/backend/replication/repl_scanner.l | 57 +-
src/backend/replication/slot.c | 1066 ++++++++++++++++++++
src/backend/replication/slotfuncs.c | 193 ++++
src/backend/replication/walreceiver.c | 5 +-
src/backend/replication/walreceiverfuncs.c | 13 +-
src/backend/replication/walsender.c | 197 +++-
src/backend/storage/ipc/ipci.c | 3 +
src/backend/storage/ipc/procarray.c | 42 +
src/backend/storage/lmgr/lwlock.c | 4 +
src/backend/storage/lmgr/proc.c | 5 +
src/backend/utils/misc/guc.c | 12 +
src/backend/utils/misc/postgresql.conf.sample | 3 +
src/bin/initdb/initdb.c | 1 +
src/bin/pg_basebackup/pg_receivexlog.c | 5 +
src/bin/pg_basebackup/receivelog.c | 49 +-
src/bin/pg_basebackup/streamutil.c | 1 +
src/bin/pg_basebackup/streamutil.h | 1 +
src/include/access/xlog.h | 1 +
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.h | 8 +
src/include/nodes/nodes.h | 2 +
src/include/nodes/replnodes.h | 32 +
src/include/replication/slot.h | 120 +++
src/include/replication/walreceiver.h | 11 +-
src/include/storage/lwlock.h | 4 +-
src/include/storage/procarray.h | 2 +
src/test/regress/expected/rules.out | 9 +
src/tools/pgindent/typedefs.list | 2 +
42 files changed, 2356 insertions(+), 62 deletions(-)


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-01 07:47:47
Message-ID: CAHGQGwGvb0qXP7Q76xLUkGO+wE9SyJzvzF=QBOS-mxgiz0vfKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sat, Feb 1, 2014 at 12:50 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> Introduce replication slots.
>
> Replication slots are a crash-safe data structure which can be created
> on either a master or a standby to prevent premature removal of
> write-ahead log segments needed by a standby, as well as (with
> hot_standby_feedback=on) pruning of tuples whose removal would cause
> replication conflicts. Slots have some advantages over existing
> techniques, as explained in the documentation.
>
> In a few places, we refer to the type of replication slots introduced
> by this patch as "physical" slots, because forthcoming patches for
> logical decoding will also have slots, but with somewhat different
> properties.

This patch changed basebackup.c so that it skips pg_replslot. It's OK
to skip all files in that directory, but an empty pg_replslot must be
included in the backup. Otherwise we cannot start PostgreSQL from
the backup taken via pg_basebackup. Attached patch fixes this problem.

Regards,

--
Fujii Masao

Attachment Content-Type Size
include_empty_pg_relslot_in_backup_v1.patch text/x-diff 1.2 KB

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-01 09:09:24
Message-ID: 20140201090924.GC17636@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
> On Sat, Feb 1, 2014 at 12:50 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> > Introduce replication slots.
> >
> > Replication slots are a crash-safe data structure which can be created
> > on either a master or a standby to prevent premature removal of
> > write-ahead log segments needed by a standby, as well as (with
> > hot_standby_feedback=on) pruning of tuples whose removal would cause
> > replication conflicts. Slots have some advantages over existing
> > techniques, as explained in the documentation.
> >
> > In a few places, we refer to the type of replication slots introduced
> > by this patch as "physical" slots, because forthcoming patches for
> > logical decoding will also have slots, but with somewhat different
> > properties.
>
> This patch changed basebackup.c so that it skips pg_replslot. It's OK
> to skip all files in that directory, but an empty pg_replslot must be
> included in the backup. Otherwise we cannot start PostgreSQL from
> the backup taken via pg_basebackup. Attached patch fixes this problem.

That's a pretty fair point. Not sure how that could escape my
notice. The patch does look sane to me.

I wonder if we additionally should add code to recreate pg_replslot on
startup, similar to pg_xlog?

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-01 09:33:08
Message-ID: CAHGQGwFsUrmA5ZZdxt1g8LYBT0N5BX9d2KzoC6mUgSXXqt3V-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>> On Sat, Feb 1, 2014 at 12:50 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>> > Introduce replication slots.
>> >
>> > Replication slots are a crash-safe data structure which can be created
>> > on either a master or a standby to prevent premature removal of
>> > write-ahead log segments needed by a standby, as well as (with
>> > hot_standby_feedback=on) pruning of tuples whose removal would cause
>> > replication conflicts. Slots have some advantages over existing
>> > techniques, as explained in the documentation.
>> >
>> > In a few places, we refer to the type of replication slots introduced
>> > by this patch as "physical" slots, because forthcoming patches for
>> > logical decoding will also have slots, but with somewhat different
>> > properties.
>>
>> This patch changed basebackup.c so that it skips pg_replslot. It's OK
>> to skip all files in that directory, but an empty pg_replslot must be
>> included in the backup. Otherwise we cannot start PostgreSQL from
>> the backup taken via pg_basebackup. Attached patch fixes this problem.
>
> That's a pretty fair point. Not sure how that could escape my
> notice. The patch does look sane to me.
>
> I wonder if we additionally should add code to recreate pg_replslot on
> startup, similar to pg_xlog?

Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
But I'm not inclined to do that for now. The fact that the essential
directory like
pg_replslot doesn't exist indicates the symptom of something strange. And,
changing that way might prevent us from detecting such symptom.

BTW, we should add the setting of primary_slotname into recovery.conf.sample?

Regards,

--
Fujii Masao


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-01 09:37:56
Message-ID: 20140201093756.GD17636@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 2014-02-01 18:33:08 +0900, Fujii Masao wrote:
> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> > On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
> >> This patch changed basebackup.c so that it skips pg_replslot. It's OK
> >> to skip all files in that directory, but an empty pg_replslot must be
> >> included in the backup. Otherwise we cannot start PostgreSQL from
> >> the backup taken via pg_basebackup. Attached patch fixes this problem.
> >
> > That's a pretty fair point. Not sure how that could escape my
> > notice. The patch does look sane to me.
> >
> > I wonder if we additionally should add code to recreate pg_replslot on
> > startup, similar to pg_xlog?
>
> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
> But I'm not inclined to do that for now. The fact that the essential
> directory like pg_replslot doesn't exist indicates the symptom of
> something strange. And, changing that way might prevent us from
> detecting such symptom.

The reason I am wondering is that it makes a fair bit of sense to
exclude it in open-coded base backups as well, and excluding the
entire directory might be the easiest way there. But I guess people
manage for pg_xlog/, so it's really not something that would reduce pain
measurably.

> BTW, we should add the setting of primary_slotname into
> recovery.conf.sample?

Yes.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Thom Brown <thom(at)linux(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-01 23:19:02
Message-ID: CAA-aLv5mU8fk=Wk17Sd0N=ttS+P+KBNPmz_2UxuYXYP7-EtHZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 1 February 2014 04:50, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> doc/src/sgml/high-availability.sgml | 94 +-

s/configuration a replication slot/configuring a replication/

> doc/src/sgml/ref/pg_receivexlog.sgml

s/paramter/parameter/

> src/backend/replication/slot.c | 1066 ++++++++++++++++++++

s/they also useful/they are also useful/

s/name to be uses/name to be used/

s/Find an previously/Find a previously/

s/nobody else wil write/nobody else will write/

s/wouldn't know wether/wouldn't know whether/

> src/backend/replication/walsender.c | 197 +++-

s/slot should saved to/slot should save to|slot should be saved to/

s/we don't need the the/we don't need the/

> src/bin/pg_basebackup/receivelog.c | 49 +-

s/elegible/eligible/

--
Thom


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-02 05:44:17
Message-ID: CAHGQGwHA==nSk-jY8Wqxa+f7y658qzaDnRSrG0SpnOGnOrntzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sat, Feb 1, 2014 at 6:37 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2014-02-01 18:33:08 +0900, Fujii Masao wrote:
>> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> > On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>> >> This patch changed basebackup.c so that it skips pg_replslot. It's OK
>> >> to skip all files in that directory, but an empty pg_replslot must be
>> >> included in the backup. Otherwise we cannot start PostgreSQL from
>> >> the backup taken via pg_basebackup. Attached patch fixes this problem.
>> >
>> > That's a pretty fair point. Not sure how that could escape my
>> > notice. The patch does look sane to me.
>> >
>> > I wonder if we additionally should add code to recreate pg_replslot on
>> > startup, similar to pg_xlog?
>>
>> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
>> But I'm not inclined to do that for now. The fact that the essential
>> directory like pg_replslot doesn't exist indicates the symptom of
>> something strange. And, changing that way might prevent us from
>> detecting such symptom.
>
> The reason I am wondering is that it makes a fair bit of sense to
> exclude it in open-coded base backups as well, and excluding the
> entire directory might be the easiest way there. But I guess people
> manage for pg_xlog/, so it's really not something that would reduce pain
> measurably.

On second thought, we should always delete all files in pg_replslot
when starting recovery from the backup? The users who are
using their own backup script instead of pg_basebackup might
include pg_replslot files in the backup. Currently, in this case,
the replication slots which were created before would be available
even after the recovery. Is this OK? If not, all files in pg_replslot
should be removed at the beginning of the PITR. OTOH, if that's OK,
I think that pg_basebackup should not skip pg_replslot files.
Thought?

Regards,

--
Fujii Masao


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-02 05:44:51
Message-ID: CAHGQGwHL5bRpoB=bustiZcoRqyYGoTMAfgEWY_Uo8f20jK6NnQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sun, Feb 2, 2014 at 8:19 AM, Thom Brown <thom(at)linux(dot)com> wrote:
> On 1 February 2014 04:50, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>> doc/src/sgml/high-availability.sgml | 94 +-
>
> s/configuration a replication slot/configuring a replication/
>
>
>> doc/src/sgml/ref/pg_receivexlog.sgml
>
> s/paramter/parameter/
>
>
>> src/backend/replication/slot.c | 1066 ++++++++++++++++++++
>
> s/they also useful/they are also useful/
>
> s/name to be uses/name to be used/
>
> s/Find an previously/Find a previously/
>
> s/nobody else wil write/nobody else will write/
>
> s/wouldn't know wether/wouldn't know whether/
>
>
>> src/backend/replication/walsender.c | 197 +++-
>
> s/slot should saved to/slot should save to|slot should be saved to/
>
> s/we don't need the the/we don't need the/
>
>
>> src/bin/pg_basebackup/receivelog.c | 49 +-
>
> s/elegible/eligible/

Thanks! Committed.

Regards,

--
Fujii Masao


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-02 14:06:35
Message-ID: 20140202140635.GN5930@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 2014-02-02 14:44:17 +0900, Fujii Masao wrote:
> On Sat, Feb 1, 2014 at 6:37 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> > On 2014-02-01 18:33:08 +0900, Fujii Masao wrote:
> >> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> >> > On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
> >> >> This patch changed basebackup.c so that it skips pg_replslot. It's OK
> >> >> to skip all files in that directory, but an empty pg_replslot must be
> >> >> included in the backup. Otherwise we cannot start PostgreSQL from
> >> >> the backup taken via pg_basebackup. Attached patch fixes this problem.
> >> >
> >> > That's a pretty fair point. Not sure how that could escape my
> >> > notice. The patch does look sane to me.
> >> >
> >> > I wonder if we additionally should add code to recreate pg_replslot on
> >> > startup, similar to pg_xlog?
> >>
> >> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
> >> But I'm not inclined to do that for now. The fact that the essential
> >> directory like pg_replslot doesn't exist indicates the symptom of
> >> something strange. And, changing that way might prevent us from
> >> detecting such symptom.
> >
> > The reason I am wondering is that it makes a fair bit of sense to
> > exclude it in open-coded base backups as well, and excluding the
> > entire directory might be the easiest way there. But I guess people
> > manage for pg_xlog/, so it's really not something that would reduce pain
> > measurably.
>
> On second thought, we should always delete all files in pg_replslot
> when starting recovery from the backup?

Are you suggesting to always delete them when in standby_mode? If so,
no, that'd be bad, we intentially *do* want to support situations in
which we stream from the standby, i.e. cascading types of setups.

If you mean doing so when initially starting with a backup label,
hm. Maybe. That would make it impossible to keep replication slots when
moving to a new server with a short downtime, which seems a bit
annoying.

> The users who are
> using their own backup script instead of pg_basebackup might
> include pg_replslot files in the backup. Currently, in this case,
> the replication slots which were created before would be available
> even after the recovery. Is this OK? If not, all files in pg_replslot
> should be removed at the beginning of the PITR. OTOH, if that's OK,
> I think that pg_basebackup should not skip pg_replslot files.
> Thought?

Robert raised this previously in
http://archives.postgresql.org/message-id/CA%2BTgmoar6BLb%2B7BQUYEmkmdFSE1f8khCZCDP-aCojOrESiNLBg%40mail.gmail.com :
> - Exclude pg_replslot from base backups. This might need more thought
> and documentation; people who use the filesystem method to perform
> backups might need to be advised to remove this directory in some
> cases also, or people who use pg_basebackup might want to keep it in
> some cases (not sure).

I can see usecases for removing and keeping them. Removing them has the
big advantage that the user won't be surprised by a slot's existance
which prevents resources (WAL, xmin horizon/VACUUM) from being
reclaimed.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-02 15:04:34
Message-ID: CAHGQGwEuBryFA5q_FiDRP2921Ljh0aSNWLnLfZRGF8=tV_7qVg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sun, Feb 2, 2014 at 11:06 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2014-02-02 14:44:17 +0900, Fujii Masao wrote:
>> On Sat, Feb 1, 2014 at 6:37 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> > On 2014-02-01 18:33:08 +0900, Fujii Masao wrote:
>> >> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> >> > On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>> >> >> This patch changed basebackup.c so that it skips pg_replslot. It's OK
>> >> >> to skip all files in that directory, but an empty pg_replslot must be
>> >> >> included in the backup. Otherwise we cannot start PostgreSQL from
>> >> >> the backup taken via pg_basebackup. Attached patch fixes this problem.
>> >> >
>> >> > That's a pretty fair point. Not sure how that could escape my
>> >> > notice. The patch does look sane to me.
>> >> >
>> >> > I wonder if we additionally should add code to recreate pg_replslot on
>> >> > startup, similar to pg_xlog?
>> >>
>> >> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
>> >> But I'm not inclined to do that for now. The fact that the essential
>> >> directory like pg_replslot doesn't exist indicates the symptom of
>> >> something strange. And, changing that way might prevent us from
>> >> detecting such symptom.
>> >
>> > The reason I am wondering is that it makes a fair bit of sense to
>> > exclude it in open-coded base backups as well, and excluding the
>> > entire directory might be the easiest way there. But I guess people
>> > manage for pg_xlog/, so it's really not something that would reduce pain
>> > measurably.
>>
>> On second thought, we should always delete all files in pg_replslot
>> when starting recovery from the backup?
>
> Are you suggesting to always delete them when in standby_mode? If so,
> no, that'd be bad, we intentially *do* want to support situations in
> which we stream from the standby, i.e. cascading types of setups.
>
> If you mean doing so when initially starting with a backup label,
> hm. Maybe. That would make it impossible to keep replication slots when
> moving to a new server with a short downtime, which seems a bit
> annoying.

Yeah, I was thinking the latter.

>> The users who are
>> using their own backup script instead of pg_basebackup might
>> include pg_replslot files in the backup. Currently, in this case,
>> the replication slots which were created before would be available
>> even after the recovery. Is this OK? If not, all files in pg_replslot
>> should be removed at the beginning of the PITR. OTOH, if that's OK,
>> I think that pg_basebackup should not skip pg_replslot files.
>> Thought?
>
> Robert raised this previously in
> http://archives.postgresql.org/message-id/CA%2BTgmoar6BLb%2B7BQUYEmkmdFSE1f8khCZCDP-aCojOrESiNLBg%40mail.gmail.com :
>> - Exclude pg_replslot from base backups. This might need more thought
>> and documentation; people who use the filesystem method to perform
>> backups might need to be advised to remove this directory in some
>> cases also, or people who use pg_basebackup might want to keep it in
>> some cases (not sure).
>
> I can see usecases for removing and keeping them. Removing them has the
> big advantage that the user won't be surprised by a slot's existance
> which prevents resources (WAL, xmin horizon/VACUUM) from being
> reclaimed.

Agreed.

Regards,

--
Fujii Masao


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-04 05:19:28
Message-ID: CAB7nPqSdA_D1WVdTVO+qawO2_swyng9fCL0nqJStUp+YiOEUTw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Sat, Feb 1, 2014 at 6:33 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>>> On Sat, Feb 1, 2014 at 12:50 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>>> > Introduce replication slots.
>>> >
>>> > Replication slots are a crash-safe data structure which can be created
>>> > on either a master or a standby to prevent premature removal of
>>> > write-ahead log segments needed by a standby, as well as (with
>>> > hot_standby_feedback=on) pruning of tuples whose removal would cause
>>> > replication conflicts. Slots have some advantages over existing
>>> > techniques, as explained in the documentation.
>>> >
>>> > In a few places, we refer to the type of replication slots introduced
>>> > by this patch as "physical" slots, because forthcoming patches for
>>> > logical decoding will also have slots, but with somewhat different
>>> > properties.
>>>
>>> This patch changed basebackup.c so that it skips pg_replslot. It's OK
>>> to skip all files in that directory, but an empty pg_replslot must be
>>> included in the backup. Otherwise we cannot start PostgreSQL from
>>> the backup taken via pg_basebackup. Attached patch fixes this problem.
>>
>> That's a pretty fair point. Not sure how that could escape my
>> notice. The patch does look sane to me.
>>
>> I wonder if we additionally should add code to recreate pg_replslot on
>> startup, similar to pg_xlog?
>
> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
> But I'm not inclined to do that for now. The fact that the essential
> directory like
> pg_replslot doesn't exist indicates the symptom of something strange. And,
> changing that way might prevent us from detecting such symptom.
To facilitate the user's life, I would be more inclined to do the following:
1) Have pg_replslot created if it does not exist in the base backup
such as users are not surprised that there old scripts do not work
anymore with 9.4
2) Add a new option in BASE_BACKUP (and pg_basebackup as well) to
stream pg_replslot data at will, because I see use cases for both
keeping those files in a base backup as well as removing them.
Regards,
--
Michael


From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-04 19:29:20
Message-ID: 1391542160.15160.21.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Also, in 25.2.6:

"or by storing the segments in an archive using restore_command".

I think you meant "archive_command", right?

Jeff Davis


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Thom Brown <thom(at)linux(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-05 18:42:18
Message-ID: CA+Tgmoa7n-iQMts1awn-5xYU-=u=FPha-X-aHGpaszUA1pEnaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Tue, Feb 4, 2014 at 2:29 PM, Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
> Also, in 25.2.6:
>
> "or by storing the segments in an archive using restore_command".
>
> I think you meant "archive_command", right?

Yep, thanks. Fixed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Thom Brown <thom(at)linux(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-06 10:20:00
Message-ID: CAA-aLv4Owpf0H9ySaVjAjdSpxQxPNGRNwenAUt=61cJ8sCtdyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 4 February 2014 05:19, Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
> On Sat, Feb 1, 2014 at 6:33 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Sat, Feb 1, 2014 at 6:09 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>>> On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>>>> On Sat, Feb 1, 2014 at 12:50 PM, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>>>> > Introduce replication slots.
>>>> >
>>>> > Replication slots are a crash-safe data structure which can be created
>>>> > on either a master or a standby to prevent premature removal of
>>>> > write-ahead log segments needed by a standby, as well as (with
>>>> > hot_standby_feedback=on) pruning of tuples whose removal would cause
>>>> > replication conflicts. Slots have some advantages over existing
>>>> > techniques, as explained in the documentation.
>>>> >
>>>> > In a few places, we refer to the type of replication slots introduced
>>>> > by this patch as "physical" slots, because forthcoming patches for
>>>> > logical decoding will also have slots, but with somewhat different
>>>> > properties.
>>>>
>>>> This patch changed basebackup.c so that it skips pg_replslot. It's OK
>>>> to skip all files in that directory, but an empty pg_replslot must be
>>>> included in the backup. Otherwise we cannot start PostgreSQL from
>>>> the backup taken via pg_basebackup. Attached patch fixes this problem.
>>>
>>> That's a pretty fair point. Not sure how that could escape my
>>> notice. The patch does look sane to me.
>>>
>>> I wonder if we additionally should add code to recreate pg_replslot on
>>> startup, similar to pg_xlog?
>>
>> Similar to pg_xlog/archive_status, not pg_xlog? That might be an option.
>> But I'm not inclined to do that for now. The fact that the essential
>> directory like
>> pg_replslot doesn't exist indicates the symptom of something strange. And,
>> changing that way might prevent us from detecting such symptom.
> To facilitate the user's life, I would be more inclined to do the following:
> 1) Have pg_replslot created if it does not exist in the base backup
> such as users are not surprised that there old scripts do not work
> anymore with 9.4

Yeah, a script I use to create a replication set-up no longer works.
Using latest Git master, this is causing standbys created with
pg_basebackup to fail to start.

FATAL: could not open directory "pg_replslot": No such file or directory

The pg_basebackup command used was:

pg_basebackup -D standby1 -h localhost -p 5530 -U rep_user

--
Thom


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-06 10:29:32
Message-ID: 20140206102932.GL28649@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Hi Fujii,

On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
> This patch changed basebackup.c so that it skips pg_replslot. It's OK
> to skip all files in that directory, but an empty pg_replslot must be
> included in the backup. Otherwise we cannot start PostgreSQL from
> the backup taken via pg_basebackup. Attached patch fixes this problem.

Do you plan to commit this patch? It's clearly an improvement over the
current situation...

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Thom Brown <thom(at)linux(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-25 15:11:55
Message-ID: CAA-aLv6R_yPDqiS9NgxT888iAF6kyh6tYuOsdB7P5wTL9F3juQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 6 February 2014 10:29, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:

> Hi Fujii,
>
> On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
> > This patch changed basebackup.c so that it skips pg_replslot. It's OK
> > to skip all files in that directory, but an empty pg_replslot must be
> > included in the backup. Otherwise we cannot start PostgreSQL from
> > the backup taken via pg_basebackup. Attached patch fixes this problem.
>
> Do you plan to commit this patch? It's clearly an improvement over the
> current situation...

Yeah, this is still an annoyance.

--
Thom


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-25 16:25:38
Message-ID: CA+Tgmobm07+fXZmy4Xsipq1FLR6+nYUZJXSQhu8756s7MVxJtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Tue, Feb 25, 2014 at 10:11 AM, Thom Brown <thom(at)linux(dot)com> wrote:
> On 6 February 2014 10:29, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> Hi Fujii,
>>
>> On 2014-02-01 16:47:47 +0900, Fujii Masao wrote:
>> > This patch changed basebackup.c so that it skips pg_replslot. It's OK
>> > to skip all files in that directory, but an empty pg_replslot must be
>> > included in the backup. Otherwise we cannot start PostgreSQL from
>> > the backup taken via pg_basebackup. Attached patch fixes this problem.
>>
>> Do you plan to commit this patch? It's clearly an improvement over the
>> current situation...
>
> Yeah, this is still an annoyance.

Since Fujii Masao doesn't seem to be around, I'll commit this. But
don't we need to update the documentation as well, for those using the
file-copy method of taking a backup?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-27 14:31:18
Message-ID: 20140227143118.GG28858@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

Hi,

Vik Faering noticed a couple of oversights in the replication slot
function reference, and I noticed some more, including using the text
type instead of name, while looking.

Patch attached.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
0001-Improve-consistency-in-replication-slot-data-types.patch text/x-patch 6.7 KB

From: Thom Brown <thom(at)linux(dot)com>
To: Robert Haas <rhaas(at)postgresql(dot)org>
Cc: pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-28 19:05:40
Message-ID: CAA-aLv7MS9w6pJ1wU=0Ev3y9GmR_MphkOTckM5943fEuH7J-GQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 1 February 2014 03:50, Robert Haas <rhaas(at)postgresql(dot)org> wrote:

> Introduce replication slots.
>
> Replication slots are a crash-safe data structure which can be created
> on either a master or a standby to prevent premature removal of
> write-ahead log segments needed by a standby, as well as (with
> hot_standby_feedback=on) pruning of tuples whose removal would cause
> replication conflicts. Slots have some advantages over existing
> techniques, as explained in the documentation.
>
> In a few places, we refer to the type of replication slots introduced
> by this patch as "physical" slots, because forthcoming patches for
> logical decoding will also have slots, but with somewhat different
> properties.
>

So now that I've actually gone to use physical replication slots, I can't
get them working.

Primary postgresql.conf changes:

shared_buffers = 8MB
logging_collector = on
log_line_prefix = '%m - %u - %d'
max_connections = 8
wal_level = 'hot_standby'
port = 5532
max_wal_senders = 4
max_replication_slots = 4

Standby postgresql.conf changes:

shared_buffers = 8MB
logging_collector = on
log_line_prefix = '%m - %u - %d'
max_connections = 8
wal_level = 'hot_standby'
port = 5533
hot_standby = on

Standby recovery.conf:

standby_mode = 'on'
recovery_target_timeline = 'latest'
primary_conninfo = 'host=127.0.0.1 user=rep_user port=5532
application_name=standby1'
primary_slotname = 'primary_physical_slot'

Primary:

psql://thom(at)[local]:5532/postgres

# SELECT * FROM pg_replication_slots;
slot_name | slot_type | datoid | database | active | xmin |
restart_lsn
-----------------------+-----------+--------+----------+--------+------+-------------
primary_physical_slot | physical | 0 | | f | |
(1 row)

Errors in primary log:

2014-02-28 19:00:40.459 GMT - rep_user - [unknown]ERROR: syntax error
(repeated every 5 seconds)

Errors in standby log:

2014-02-28 19:00:40.459 GMT - - FATAL: could not start WAL streaming:
ERROR: syntax error
(repeated every 5 seconds)

Am I missing something obvious? The error message isn't particularly
helpful.
--
Thom


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-28 19:22:38
Message-ID: 20140228192238.GK15628@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 2014-02-28 19:05:40 +0000, Thom Brown wrote:
> On 1 February 2014 03:50, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
>
> > Introduce replication slots.
> >
> > Replication slots are a crash-safe data structure which can be created
> > on either a master or a standby to prevent premature removal of
> > write-ahead log segments needed by a standby, as well as (with
> > hot_standby_feedback=on) pruning of tuples whose removal would cause
> > replication conflicts. Slots have some advantages over existing
> > techniques, as explained in the documentation.
> >
> > In a few places, we refer to the type of replication slots introduced
> > by this patch as "physical" slots, because forthcoming patches for
> > logical decoding will also have slots, but with somewhat different
> > properties.
> >
>
> So now that I've actually gone to use physical replication slots, I can't
> get them working.

Aw yuck. Try a shorter name. libpqrcv_startstreaming is truncating the
identifier if it's too long...

Patch fixing that attached.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
use-sufficiently-large-buf.patch text/x-patch 587 bytes

From: Thom Brown <thom(at)linux(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-02-28 19:33:51
Message-ID: CAA-aLv79Do9KjUMqT-W1cffirLn0MJpNQQThc2+aTXUKbqz1Rw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 28 February 2014 19:22, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:

> On 2014-02-28 19:05:40 +0000, Thom Brown wrote:
> > On 1 February 2014 03:50, Robert Haas <rhaas(at)postgresql(dot)org> wrote:
> >
> > > Introduce replication slots.
> > >
> > > Replication slots are a crash-safe data structure which can be created
> > > on either a master or a standby to prevent premature removal of
> > > write-ahead log segments needed by a standby, as well as (with
> > > hot_standby_feedback=on) pruning of tuples whose removal would cause
> > > replication conflicts. Slots have some advantages over existing
> > > techniques, as explained in the documentation.
> > >
> > > In a few places, we refer to the type of replication slots introduced
> > > by this patch as "physical" slots, because forthcoming patches for
> > > logical decoding will also have slots, but with somewhat different
> > > properties.
> > >
> >
> > So now that I've actually gone to use physical replication slots, I can't
> > get them working.
>
> Aw yuck. Try a shorter name. libpqrcv_startstreaming is truncating the
> identifier if it's too long...
>
> Patch fixing that attached.

Yes, that fixes the problem. Thanks. I can stop quadruple-checking my
config now. :)

--
Thom


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-03-03 12:26:56
Message-ID: CA+TgmoYNC4yPUJmbuP0+P-nzjgc3GPDgjwC+JwxCSFtTjdDAWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On Fri, Feb 28, 2014 at 2:22 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
>> So now that I've actually gone to use physical replication slots, I can't
>> get them working.
>
> Aw yuck. Try a shorter name. libpqrcv_startstreaming is truncating the
> identifier if it's too long...
>
> Patch fixing that attached.

Committed, although I wonder if we shouldn't be doing something more
sophisticated here to avoid the need to guess how long the command
could be. Like, maybe using psprintf()?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Thom Brown <thom(at)linux(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Robert Haas <rhaas(at)postgresql(dot)org>, pgsql-committers <pgsql-committers(at)postgresql(dot)org>
Subject: Re: pgsql: Introduce replication slots.
Date: 2014-03-05 17:42:09
Message-ID: CAA-aLv4eoC-AwR40kz10asn8D5zAkK0LaRpjJRt7Z-e2x1pvYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers

On 25 February 2014 16:25, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> Since Fujii Masao doesn't seem to be around, I'll commit this. But
> don't we need to update the documentation as well, for those using the
> file-copy method of taking a backup?
>

Yes, that sounds like a sensible idea.

--
Thom