Re: pg_receivexlog and feedback message

Lists: pgsql-hackers
From: Magnus Hagander <magnus(at)hagander(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: pg_receivexlog and feedback message
Date: 2012-06-05 12:53:44
Message-ID: CABUevEx7sYUeE59FXbKDOmV6HcMY6J4twstkjf=xZixOWG8bCg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Right now, pg_receivexlog sets:
replymsg->write = InvalidXLogRecPtr;
replymsg->flush = InvalidXLogRecPtr;
replymsg->apply = InvalidXLogRecPtr;

when it sends it's status updates.

I'm thinking it sohuld set replymsg->write = blockpos instad.

Why? That way you can see in pg_stat_replication what has actually
been received by pg_receivexlog - not just what we last sent. This can
be useful in combination with an archive_command that can block WAL
recycling until it has been saved to the standby. And it would be
useful as a general monitoring thing as well.

I think the original reason was that it shouldn't interefer with
synchronous replication - but it does take away a fairly useful
usecase...

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


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-05 14:42:23
Message-ID: CAHGQGwHwok-3_isC8+M+tz6DeRks18tUfnJgfkQ_um0-DJyUxg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> Right now, pg_receivexlog sets:
>                        replymsg->write = InvalidXLogRecPtr;
>                        replymsg->flush = InvalidXLogRecPtr;
>                        replymsg->apply = InvalidXLogRecPtr;
>
> when it sends it's status updates.
>
> I'm thinking it sohuld set replymsg->write = blockpos instad.
>
> Why? That way you can see in pg_stat_replication what has actually
> been received by pg_receivexlog - not just what we last sent. This can
> be useful in combination with an archive_command that can block WAL
> recycling until it has been saved to the standby. And it would be
> useful as a general monitoring thing as well.
>
> I think the original reason was that it shouldn't interefer with
> synchronous replication - but it does take away a fairly useful
> usecase...

I think that not only replaymsg->write but also ->flush should be set to
blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
as synchronous standby, so we can write WAL to both local and remote
synchronously. I believe there are some use cases for synchronous
pg_receivexlog.

OTOH, neither replaymsg->write nor ->flush should be set to
InvalidXLogRecPtr, to prevent pg_basebackup from behaving as
synchronous standby.

Regards,

--
Fujii Masao


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-05 14:44:31
Message-ID: CABUevEy4vyuz2v3b2-VPZjj+1nFixE6Q93uzs3ZfWMQWtF-mXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> Right now, pg_receivexlog sets:
>>                        replymsg->write = InvalidXLogRecPtr;
>>                        replymsg->flush = InvalidXLogRecPtr;
>>                        replymsg->apply = InvalidXLogRecPtr;
>>
>> when it sends it's status updates.
>>
>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>>
>> Why? That way you can see in pg_stat_replication what has actually
>> been received by pg_receivexlog - not just what we last sent. This can
>> be useful in combination with an archive_command that can block WAL
>> recycling until it has been saved to the standby. And it would be
>> useful as a general monitoring thing as well.
>>
>> I think the original reason was that it shouldn't interefer with
>> synchronous replication - but it does take away a fairly useful
>> usecase...
>
> I think that not only replaymsg->write but also ->flush should be set to
> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
> as synchronous standby, so we can write WAL to both local and remote
> synchronously. I believe there are some use cases for synchronous
> pg_receivexlog.

pg_receivexlog doesn't currently fsync() after every write. It only
fsync():s complete files. So we'd need to set ->flush only at the end
of a segment, right?

> OTOH, neither replaymsg->write nor ->flush should be set to
> InvalidXLogRecPtr, to prevent pg_basebackup from behaving as
> synchronous standby.

Oh, good point. So yeah, we'd need to make it a parameter to the function.

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


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-06 18:26:12
Message-ID: CAHGQGwHoGGGWbRd29s5Rc-oTLD2OA-D+0O3=aeELcFJSL=KVWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>> Right now, pg_receivexlog sets:
>>>                        replymsg->write = InvalidXLogRecPtr;
>>>                        replymsg->flush = InvalidXLogRecPtr;
>>>                        replymsg->apply = InvalidXLogRecPtr;
>>>
>>> when it sends it's status updates.
>>>
>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>>>
>>> Why? That way you can see in pg_stat_replication what has actually
>>> been received by pg_receivexlog - not just what we last sent. This can
>>> be useful in combination with an archive_command that can block WAL
>>> recycling until it has been saved to the standby. And it would be
>>> useful as a general monitoring thing as well.
>>>
>>> I think the original reason was that it shouldn't interefer with
>>> synchronous replication - but it does take away a fairly useful
>>> usecase...
>>
>> I think that not only replaymsg->write but also ->flush should be set to
>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>> as synchronous standby, so we can write WAL to both local and remote
>> synchronously. I believe there are some use cases for synchronous
>> pg_receivexlog.
>
> pg_receivexlog doesn't currently fsync() after every write. It only
> fsync():s complete files. So we'd need to set ->flush only at the end
> of a segment, right?

Yes.

Currently the status update is sent for each status interval. In sync
replication, transaction has to wait for a while even after pg_receivexlog
has written or flushed the WAL data.

So we should add new option which specifies whether pg_receivexlog
sends the status packet back as soon as it writes or flushes the WAL
data, like the walreceiver does?

Regards,

--
Fujii Masao


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-06 18:52:09
Message-ID: CA+TgmoYWOV_TYqYWcaFWkt9D_2bqpAFN7_EmzN4-ghD24TpJqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 5, 2012 at 10:44 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>> Right now, pg_receivexlog sets:
>>>                        replymsg->write = InvalidXLogRecPtr;
>>>                        replymsg->flush = InvalidXLogRecPtr;
>>>                        replymsg->apply = InvalidXLogRecPtr;
>>>
>>> when it sends it's status updates.
>>>
>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>>>
>>> Why? That way you can see in pg_stat_replication what has actually
>>> been received by pg_receivexlog - not just what we last sent. This can
>>> be useful in combination with an archive_command that can block WAL
>>> recycling until it has been saved to the standby. And it would be
>>> useful as a general monitoring thing as well.
>>>
>>> I think the original reason was that it shouldn't interefer with
>>> synchronous replication - but it does take away a fairly useful
>>> usecase...
>>
>> I think that not only replaymsg->write but also ->flush should be set to
>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>> as synchronous standby, so we can write WAL to both local and remote
>> synchronously. I believe there are some use cases for synchronous
>> pg_receivexlog.
>
> pg_receivexlog doesn't currently fsync() after every write. It only
> fsync():s complete files. So we'd need to set ->flush only at the end
> of a segment, right?

If you want to be able to use it as a synchronous standby, that's not
going to work very well. You could end up with pg_receivexlog waiting
for the end of the segment before it flushes; meanwhile, all the
clients are sitting there waiting for the flush to happen before they
do anything that could generate more WAL to fill the segment.

Unless you have a solution to that problem, I'd recommend setting
write (which should work with the new remote_write mode for sync rep)
but not setting flush.

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


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-06 20:05:21
Message-ID: CABUevEwy9aV3+yzSizaYv8AvwNqoRK9FenrEZ6tCr2Md+n2Mrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>>> Right now, pg_receivexlog sets:
>>>>                        replymsg->write = InvalidXLogRecPtr;
>>>>                        replymsg->flush = InvalidXLogRecPtr;
>>>>                        replymsg->apply = InvalidXLogRecPtr;
>>>>
>>>> when it sends it's status updates.
>>>>
>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>>>>
>>>> Why? That way you can see in pg_stat_replication what has actually
>>>> been received by pg_receivexlog - not just what we last sent. This can
>>>> be useful in combination with an archive_command that can block WAL
>>>> recycling until it has been saved to the standby. And it would be
>>>> useful as a general monitoring thing as well.
>>>>
>>>> I think the original reason was that it shouldn't interefer with
>>>> synchronous replication - but it does take away a fairly useful
>>>> usecase...
>>>
>>> I think that not only replaymsg->write but also ->flush should be set to
>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>>> as synchronous standby, so we can write WAL to both local and remote
>>> synchronously. I believe there are some use cases for synchronous
>>> pg_receivexlog.
>>
>> pg_receivexlog doesn't currently fsync() after every write. It only
>> fsync():s complete files. So we'd need to set ->flush only at the end
>> of a segment, right?
>
> Yes.
>
> Currently the status update is sent for each status interval. In sync
> replication, transaction has to wait for a while even after pg_receivexlog
> has written or flushed the WAL data.
>
> So we should add new option which specifies whether pg_receivexlog
> sends the status packet back as soon as it writes or flushes the WAL
> data, like the walreceiver does?

That might be useful, but I think that's 9.3 material at this point.

But I think we can get the "set the write location" in as a bugfix.

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


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-06 22:25:04
Message-ID: CAHGQGwHd9cFSHhfw2=9zr1PVEU2AuiOqGdtvGBRdpvoAAy=ccQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 7, 2012 at 5:05 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>>>> Right now, pg_receivexlog sets:
>>>>>                        replymsg->write = InvalidXLogRecPtr;
>>>>>                        replymsg->flush = InvalidXLogRecPtr;
>>>>>                        replymsg->apply = InvalidXLogRecPtr;
>>>>>
>>>>> when it sends it's status updates.
>>>>>
>>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>>>>>
>>>>> Why? That way you can see in pg_stat_replication what has actually
>>>>> been received by pg_receivexlog - not just what we last sent. This can
>>>>> be useful in combination with an archive_command that can block WAL
>>>>> recycling until it has been saved to the standby. And it would be
>>>>> useful as a general monitoring thing as well.
>>>>>
>>>>> I think the original reason was that it shouldn't interefer with
>>>>> synchronous replication - but it does take away a fairly useful
>>>>> usecase...
>>>>
>>>> I think that not only replaymsg->write but also ->flush should be set to
>>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>>>> as synchronous standby, so we can write WAL to both local and remote
>>>> synchronously. I believe there are some use cases for synchronous
>>>> pg_receivexlog.
>>>
>>> pg_receivexlog doesn't currently fsync() after every write. It only
>>> fsync():s complete files. So we'd need to set ->flush only at the end
>>> of a segment, right?
>>
>> Yes.
>>
>> Currently the status update is sent for each status interval. In sync
>> replication, transaction has to wait for a while even after pg_receivexlog
>> has written or flushed the WAL data.
>>
>> So we should add new option which specifies whether pg_receivexlog
>> sends the status packet back as soon as it writes or flushes the WAL
>> data, like the walreceiver does?
>
> That might be useful, but I think that's 9.3 material at this point.

Fair enough. That's new feature rather than a bugfix.

> But I think we can get the "set the write location" in as a bugfix.

Also "set the flush location"? Sending the flush location back seems
helpful when using pg_receivexlog for WAL archiving purpose. By
seeing the flush location we can ensure that WAL file has been archived
durably (IOW, WAL file has been flushed in remote archive area).

Regards,

--
Fujii Masao


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-07 09:25:42
Message-ID: CABUevExatiWbukfGZGSPpa-YHw8VfKxpE_WcduczKm+2tHOg8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thursday, June 7, 2012, Fujii Masao wrote:

> On Thu, Jun 7, 2012 at 5:05 AM, Magnus Hagander <magnus(at)hagander(dot)net<javascript:;>>
> wrote:
> > On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com<javascript:;>>
> wrote:
> >> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <magnus(at)hagander(dot)net<javascript:;>>
> wrote:
> >>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com<javascript:;>>
> wrote:
> >>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net<javascript:;>>
> wrote:
> >>>>> Right now, pg_receivexlog sets:
> >>>>> replymsg->write = InvalidXLogRecPtr;
> >>>>> replymsg->flush = InvalidXLogRecPtr;
> >>>>> replymsg->apply = InvalidXLogRecPtr;
> >>>>>
> >>>>> when it sends it's status updates.
> >>>>>
> >>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
> >>>>>
> >>>>> Why? That way you can see in pg_stat_replication what has actually
> >>>>> been received by pg_receivexlog - not just what we last sent. This
> can
> >>>>> be useful in combination with an archive_command that can block WAL
> >>>>> recycling until it has been saved to the standby. And it would be
> >>>>> useful as a general monitoring thing as well.
> >>>>>
> >>>>> I think the original reason was that it shouldn't interefer with
> >>>>> synchronous replication - but it does take away a fairly useful
> >>>>> usecase...
> >>>>
> >>>> I think that not only replaymsg->write but also ->flush should be set
> to
> >>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
> >>>> as synchronous standby, so we can write WAL to both local and remote
> >>>> synchronously. I believe there are some use cases for synchronous
> >>>> pg_receivexlog.
> >>>
> >>> pg_receivexlog doesn't currently fsync() after every write. It only
> >>> fsync():s complete files. So we'd need to set ->flush only at the end
> >>> of a segment, right?
> >>
> >> Yes.
> >>
> >> Currently the status update is sent for each status interval. In sync
> >> replication, transaction has to wait for a while even after
> pg_receivexlog
> >> has written or flushed the WAL data.
> >>
> >> So we should add new option which specifies whether pg_receivexlog
> >> sends the status packet back as soon as it writes or flushes the WAL
> >> data, like the walreceiver does?
> >
> > That might be useful, but I think that's 9.3 material at this point.
>
> Fair enough. That's new feature rather than a bugfix.
>
> > But I think we can get the "set the write location" in as a bugfix.
>
> Also "set the flush location"? Sending the flush location back seems
> helpful when using pg_receivexlog for WAL archiving purpose. By
> seeing the flush location we can ensure that WAL file has been archived
> durably (IOW, WAL file has been flushed in remote archive area).
>
>
You can do that with the write location as well, as long as you round it
off to complete segments, can't you?

In fact that's exactly the usecase that got me to realize we were missing
this :-)

//Magnus

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


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-07 10:34:55
Message-ID: CAHGQGwG3DGxv9h6MvyoLXB8TDbLxwBkVniiYgyE1ifjv-v1Q-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 7, 2012 at 6:25 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Thursday, June 7, 2012, Fujii Masao wrote:
>>
>> On Thu, Jun 7, 2012 at 5:05 AM, Magnus Hagander <magnus(at)hagander(dot)net>
>> wrote:
>> > On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
>> > wrote:
>> >> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <magnus(at)hagander(dot)net>
>> >> wrote:
>> >>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
>> >>> wrote:
>> >>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <magnus(at)hagander(dot)net>
>> >>>> wrote:
>> >>>>> Right now, pg_receivexlog sets:
>> >>>>>                        replymsg->write = InvalidXLogRecPtr;
>> >>>>>                        replymsg->flush = InvalidXLogRecPtr;
>> >>>>>                        replymsg->apply = InvalidXLogRecPtr;
>> >>>>>
>> >>>>> when it sends it's status updates.
>> >>>>>
>> >>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>> >>>>>
>> >>>>> Why? That way you can see in pg_stat_replication what has actually
>> >>>>> been received by pg_receivexlog - not just what we last sent. This
>> >>>>> can
>> >>>>> be useful in combination with an archive_command that can block WAL
>> >>>>> recycling until it has been saved to the standby. And it would be
>> >>>>> useful as a general monitoring thing as well.
>> >>>>>
>> >>>>> I think the original reason was that it shouldn't interefer with
>> >>>>> synchronous replication - but it does take away a fairly useful
>> >>>>> usecase...
>> >>>>
>> >>>> I think that not only replaymsg->write but also ->flush should be set
>> >>>> to
>> >>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>> >>>> as synchronous standby, so we can write WAL to both local and remote
>> >>>> synchronously. I believe there are some use cases for synchronous
>> >>>> pg_receivexlog.
>> >>>
>> >>> pg_receivexlog doesn't currently fsync() after every write. It only
>> >>> fsync():s complete files. So we'd need to set ->flush only at the end
>> >>> of a segment, right?
>> >>
>> >> Yes.
>> >>
>> >> Currently the status update is sent for each status interval. In sync
>> >> replication, transaction has to wait for a while even after
>> >> pg_receivexlog
>> >> has written or flushed the WAL data.
>> >>
>> >> So we should add new option which specifies whether pg_receivexlog
>> >> sends the status packet back as soon as it writes or flushes the WAL
>> >> data, like the walreceiver does?
>> >
>> > That might be useful, but I think that's 9.3 material at this point.
>>
>> Fair enough. That's new feature rather than a bugfix.
>>
>> > But I think we can get the "set the write location" in as a bugfix.
>>
>> Also "set the flush location"? Sending the flush location back seems
>> helpful when using pg_receivexlog for WAL archiving purpose. By
>> seeing the flush location we can ensure that WAL file has been archived
>> durably (IOW, WAL file has been flushed in remote archive area).
>>
>
> You  can do that with the write location as well, as long as you round it
> off to complete segments, can't you?

You mean to prevent pg_receivexlog from sending back the end of WAL file
as the write location *before* it completes the WAL file? If so, yes. But
why do you want to keep the flush location invalid?

Regards,

--
Fujii Masao


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-07 10:40:09
Message-ID: CABUevEwW0XF5-95DFA_+eg_5kMHahjSELf6o=kQ3B+7da4+xfA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thursday, June 7, 2012, Fujii Masao wrote:

> On Thu, Jun 7, 2012 at 6:25 PM, Magnus Hagander <magnus(at)hagander(dot)net>
> wrote:
> > On Thursday, June 7, 2012, Fujii Masao wrote:
> >>
> >> On Thu, Jun 7, 2012 at 5:05 AM, Magnus Hagander <magnus(at)hagander(dot)net>
> >> wrote:
> >> > On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
> >> > wrote:
> >> >> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander <
> magnus(at)hagander(dot)net>
> >> >> wrote:
> >> >>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
> >> >>> wrote:
> >> >>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander <
> magnus(at)hagander(dot)net>
> >> >>>> wrote:
> >> >>>>> Right now, pg_receivexlog sets:
> >> >>>>> replymsg->write = InvalidXLogRecPtr;
> >> >>>>> replymsg->flush = InvalidXLogRecPtr;
> >> >>>>> replymsg->apply = InvalidXLogRecPtr;
> >> >>>>>
> >> >>>>> when it sends it's status updates.
> >> >>>>>
> >> >>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
> >> >>>>>
> >> >>>>> Why? That way you can see in pg_stat_replication what has actually
> >> >>>>> been received by pg_receivexlog - not just what we last sent. This
> >> >>>>> can
> >> >>>>> be useful in combination with an archive_command that can block
> WAL
> >> >>>>> recycling until it has been saved to the standby. And it would be
> >> >>>>> useful as a general monitoring thing as well.
> >> >>>>>
> >> >>>>> I think the original reason was that it shouldn't interefer with
> >> >>>>> synchronous replication - but it does take away a fairly useful
> >> >>>>> usecase...
> >> >>>>
> >> >>>> I think that not only replaymsg->write but also ->flush should be
> set
> >> >>>> to
> >> >>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
> >> >>>> as synchronous standby, so we can write WAL to both local and
> remote
> >> >>>> synchronously. I believe there are some use cases for synchronous
> >> >>>> pg_receivexlog.
> >> >>>
> >> >>> pg_receivexlog doesn't currently fsync() after every write. It only
> >> >>> fsync():s complete files. So we'd need to set ->flush only at the
> end
> >> >>> of a segment, right?
> >> >>
> >> >> Yes.
> >> >>
> >> >> Currently the status update is sent for each status interval. In sync
> >> >> replication, transaction has to wait for a while even after
> >> >> pg_receivexlog
> >> >> has written or flushed the WAL data.
> >> >>
> >> >> So we should add new option which specifies whether pg_receivexlog
> >> >> sends the status packet back as soon as it writes or flushes the WAL
> >> >> data, like the walreceiver does?
> >> >
> >> > That might be useful, but I think that's 9.3 material at this point.
> >>
> >> Fair enough. That's new feature rather than a bugfix.
> >>
> >> > But I think we can get the "set the write location" in as a bugfix.
> >>
> >> Also "set the flush location"? Sending the flush location back seems
> >> helpful when using pg_receivexlog for WAL archiving purpose. By
> >> seeing the flush location we can ensure that WAL file has been archived
> >> durably (IOW, WAL file has been flushed in remote archive area).
> >>
> >
> > You can do that with the write location as well, as long as you round it
> You mean to prevent pg_receivexlog from sending back the end of WAL file
> as the write location *before* it completes the WAL file? If so, yes. But
> why do you want to keep the flush location invalid?
>

No. pg_receivexlog sends back the correct write location. Whoever does the
check (through pg_stat_replication) rounds down, so it only counts it once
pg_receivexlog has acknowledged receiving the whole mail.

I'm not against doing the flush location as well, I'm just worried about
feature-creep :-) But let's see how big a change that would turn out to
be...

//Magnus

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


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-10 10:55:32
Message-ID: CABUevExP2m6BjrKWQ_fBDg2yUgY7sXU7y7YSoxZGgOLhVBJ8sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 7, 2012 at 12:40 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Thursday, June 7, 2012, Fujii Masao wrote:
>>
>> On Thu, Jun 7, 2012 at 6:25 PM, Magnus Hagander <magnus(at)hagander(dot)net>
>> wrote:
>> > On Thursday, June 7, 2012, Fujii Masao wrote:
>> >>
>> >> On Thu, Jun 7, 2012 at 5:05 AM, Magnus Hagander <magnus(at)hagander(dot)net>
>> >> wrote:
>> >> > On Wed, Jun 6, 2012 at 8:26 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
>> >> > wrote:
>> >> >> On Tue, Jun 5, 2012 at 11:44 PM, Magnus Hagander
>> >> >> <magnus(at)hagander(dot)net>
>> >> >> wrote:
>> >> >>> On Tue, Jun 5, 2012 at 4:42 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
>> >> >>> wrote:
>> >> >>>> On Tue, Jun 5, 2012 at 9:53 PM, Magnus Hagander
>> >> >>>> <magnus(at)hagander(dot)net>
>> >> >>>> wrote:
>> >> >>>>> Right now, pg_receivexlog sets:
>> >> >>>>>                        replymsg->write = InvalidXLogRecPtr;
>> >> >>>>>                        replymsg->flush = InvalidXLogRecPtr;
>> >> >>>>>                        replymsg->apply = InvalidXLogRecPtr;
>> >> >>>>>
>> >> >>>>> when it sends it's status updates.
>> >> >>>>>
>> >> >>>>> I'm thinking it sohuld set replymsg->write = blockpos instad.
>> >> >>>>>
>> >> >>>>> Why? That way you can see in pg_stat_replication what has
>> >> >>>>> actually
>> >> >>>>> been received by pg_receivexlog - not just what we last sent.
>> >> >>>>> This
>> >> >>>>> can
>> >> >>>>> be useful in combination with an archive_command that can block
>> >> >>>>> WAL
>> >> >>>>> recycling until it has been saved to the standby. And it would be
>> >> >>>>> useful as a general monitoring thing as well.
>> >> >>>>>
>> >> >>>>> I think the original reason was that it shouldn't interefer with
>> >> >>>>> synchronous replication - but it does take away a fairly useful
>> >> >>>>> usecase...
>> >> >>>>
>> >> >>>> I think that not only replaymsg->write but also ->flush should be
>> >> >>>> set
>> >> >>>> to
>> >> >>>> blockpos in pg_receivexlog. Which allows pg_receivexlog to behave
>> >> >>>> as synchronous standby, so we can write WAL to both local and
>> >> >>>> remote
>> >> >>>> synchronously. I believe there are some use cases for synchronous
>> >> >>>> pg_receivexlog.
>> >> >>>
>> >> >>> pg_receivexlog doesn't currently fsync() after every write. It only
>> >> >>> fsync():s complete files. So we'd need to set ->flush only at the
>> >> >>> end
>> >> >>> of a segment, right?
>> >> >>
>> >> >> Yes.
>> >> >>
>> >> >> Currently the status update is sent for each status interval. In
>> >> >> sync
>> >> >> replication, transaction has to wait for a while even after
>> >> >> pg_receivexlog
>> >> >> has written or flushed the WAL data.
>> >> >>
>> >> >> So we should add new option which specifies whether pg_receivexlog
>> >> >> sends the status packet back as soon as it writes or flushes the WAL
>> >> >> data, like the walreceiver does?
>> >> >
>> >> > That might be useful, but I think that's 9.3 material at this point.
>> >>
>> >> Fair enough. That's new feature rather than a bugfix.
>> >>
>> >> > But I think we can get the "set the write location" in as a bugfix.
>> >>
>> >> Also "set the flush location"? Sending the flush location back seems
>> >> helpful when using pg_receivexlog for WAL archiving purpose. By
>> >> seeing the flush location we can ensure that WAL file has been archived
>> >> durably (IOW, WAL file has been flushed in remote archive area).
>> >>
>> >
>> > You  can do that with the write location as well, as long as you round
>> > it
>> You mean to prevent pg_receivexlog from sending back the end of WAL file
>> as the write location *before* it completes the WAL file? If so, yes. But
>> why do you want to keep the flush location invalid?
>
>
> No. pg_receivexlog sends back the correct write location. Whoever does the
> check (through pg_stat_replication) rounds down, so it only counts it once
> pg_receivexlog has acknowledged receiving the whole mail.
>
> I'm not against doing the flush location as well, I'm just worried about
> feature-creep :-) But let's see how big a change that would turn out to
> be...

How about this?

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

Attachment Content-Type Size
receivelog_flushpos.patch application/octet-stream 1.4 KB

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-10 14:02:16
Message-ID: CAHGQGwGhd=XXhtze4fmBNE5-RKS7c0-u6ck7RUwcMHVPpCWXEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jun 10, 2012 at 7:55 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> How about this?

+ /*
+ * Set flushed position to the last byte in the previous
+ * file. Per above we know that xrecoff%XLOG_SEG_SIZE=0
+ */
+ flushedpos = blockpos;
+ if (flushedpos.xrecoff == 0)
+ {
+ flushedpos.xlogid--;
+ flushedpos.xrecoff = XLogFileSize-1;
+ }
+ else
+ flushedpos.xrecoff--;

flushedpos.xrecoff doesn't need to be decremented by one.
If xrecoff % XLOG_SEG_SIZE = 0, the position should be the last
byte of previous (i.e., flushed) WAL file.

Regards,

--
Fujii Masao


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-11 13:04:42
Message-ID: CABUevEybb_XOrzxffQU3F57pLkCA=sKjBYjQsYhu6b9hktbR0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jun 10, 2012 at 4:02 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Sun, Jun 10, 2012 at 7:55 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> How about this?
>
> +                               /*
> +                                * Set flushed position to the last byte in the previous
> +                                * file. Per above we know that xrecoff%XLOG_SEG_SIZE=0
> +                                */
> +                               flushedpos = blockpos;
> +                               if (flushedpos.xrecoff == 0)
> +                               {
> +                                       flushedpos.xlogid--;
> +                                       flushedpos.xrecoff = XLogFileSize-1;
> +                               }
> +                               else
> +                                       flushedpos.xrecoff--;
>
> flushedpos.xrecoff doesn't need to be decremented by one.
> If xrecoff % XLOG_SEG_SIZE = 0, the position should be the last
> byte of previous (i.e., flushed) WAL file.

Hmm. I thikn I confused myself with "last byte written" vs "current
position". And we're dealing with current position here...

So it should just be flushedpos = blockpos and be done with it, right?

Though before I commit anything with this, we need to decide what to
wrt syncrep on that, per the other thread.

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


From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-06-11 15:24:37
Message-ID: CAHGQGwEWG5L+WkrAYOave=xFE1Ch7Sauv6cCYrSfSDvR_biGgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 11, 2012 at 10:04 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Sun, Jun 10, 2012 at 4:02 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>> On Sun, Jun 10, 2012 at 7:55 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>> How about this?
>>
>> +                               /*
>> +                                * Set flushed position to the last byte in the previous
>> +                                * file. Per above we know that xrecoff%XLOG_SEG_SIZE=0
>> +                                */
>> +                               flushedpos = blockpos;
>> +                               if (flushedpos.xrecoff == 0)
>> +                               {
>> +                                       flushedpos.xlogid--;
>> +                                       flushedpos.xrecoff = XLogFileSize-1;
>> +                               }
>> +                               else
>> +                                       flushedpos.xrecoff--;
>>
>> flushedpos.xrecoff doesn't need to be decremented by one.
>> If xrecoff % XLOG_SEG_SIZE = 0, the position should be the last
>> byte of previous (i.e., flushed) WAL file.
>
> Hmm. I thikn I confused myself with "last byte written" vs "current
> position". And we're dealing with current position here...
>
> So it should just be flushedpos = blockpos and be done with it, right?

Yep.

> Though before I commit anything with this, we need to decide what to
> wrt syncrep on that, per the other thread.

Yep.

Regards,

--
Fujii Masao


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivexlog and feedback message
Date: 2012-07-04 13:26:59
Message-ID: CABUevEynybE3Kpo+auFFD1vgDp6nRPv+5+jfjAitQ+GTyrgnZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 11, 2012 at 5:24 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> On Mon, Jun 11, 2012 at 10:04 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> On Sun, Jun 10, 2012 at 4:02 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>>> On Sun, Jun 10, 2012 at 7:55 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>>> How about this?
>>>
>>> + /*
>>> + * Set flushed position to the last byte in the previous
>>> + * file. Per above we know that xrecoff%XLOG_SEG_SIZE=0
>>> + */
>>> + flushedpos = blockpos;
>>> + if (flushedpos.xrecoff == 0)
>>> + {
>>> + flushedpos.xlogid--;
>>> + flushedpos.xrecoff = XLogFileSize-1;
>>> + }
>>> + else
>>> + flushedpos.xrecoff--;
>>>
>>> flushedpos.xrecoff doesn't need to be decremented by one.
>>> If xrecoff % XLOG_SEG_SIZE = 0, the position should be the last
>>> byte of previous (i.e., flushed) WAL file.
>>
>> Hmm. I thikn I confused myself with "last byte written" vs "current
>> position". And we're dealing with current position here...
>>
>> So it should just be flushedpos = blockpos and be done with it, right?
>
> Yep.
>
>> Though before I commit anything with this, we need to decide what to
>> wrt syncrep on that, per the other thread.
>
> Yep.

Per the other thread, we decided to postpone this until 9.3. And also
figure out a better set of switches for pg_receivexlog to control it
with.

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