Skip site navigation (1) Skip section navigation (2)

Re: cheaper snapshots

From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Ants Aasma <ants(dot)aasma(at)eesti(dot)ee>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: cheaper snapshots
Date: 2011-07-29 14:20:19
Message-ID: 1311949219.3117.3554.camel@hvost (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Thu, 2011-07-28 at 20:14 -0400, Robert Haas wrote:
> On Thu, Jul 28, 2011 at 7:54 PM, Ants Aasma <ants(dot)aasma(at)eesti(dot)ee> wrote:
> > On Thu, Jul 28, 2011 at 11:54 PM, Kevin Grittner
> > <Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
> >> (4)  We communicate acceptable snapshots to the replica to make the
> >> order of visibility visibility match the master even when that
> >> doesn't match the order that transactions returned from commit.
> >
> > I wonder if some interpretation of 2 phase commit could make Robert's
> > original suggestion implement this.
> >
> > On the master the commit sequence would look something like:
> > 1. Insert commit record to the WAL
> > 2. Wait for replication
> > 3. Get a commit seq nr and mark XIDs visible
> > 4. WAL log the seq nr
> > 5. Return success to client
> >
> > When replaying:
> > * When replaying commit record, do everything but make
> >  the tx visible.
> > * When replaying the commit sequence number
> >    if there is a gap between last visible commit and current:
> >      insert the commit sequence nr. to list of waiting commits.
> >    else:
> >      mark current and all directly following waiting tx's visible
> >
> > This would give consistent visibility order on master and slave. Robert
> > is right that this would undesirably increase WAL traffic. Delaying this
> > traffic would undesirably increase replay lag between master and slave.
> > But it seems to me that this could be an optional WAL level on top of
> > hot_standby that would only be enabled if consistent visibility on
> > slaves is desired.
> I think you nailed it.

Agreed, this would keep current semantics on master and same visibility
order on master and slave.

> An additional point to think about: if we were willing to insist on
> streaming replication, we could send the commit sequence numbers via a
> side channel rather than writing them to WAL, which would be a lot
> cheaper. 

Why do you think that side channel is cheaper than main WAL ?

How would you handle synchronising the two ?

> That might even be a reasonable thing to do, because if
> you're doing log shipping, this is all going to be super-not-real-time
> anyway. 

But perhaps you still may want to preserve visibility order to be able
to do PITR to exact transaction "commit", no ?

>  OTOH, I know we don't want to make WAL shipping anything less
> than a first class citizen, so maybe not.
> At any rate, we may be getting a little sidetracked here from the
> original point of the thread, which was how to make snapshot-taking
> cheaper.  Maybe there's some tie-in to when transactions become
> visible, but I think it's pretty weak.  The existing system could be
> hacked up to avoid making transactions visible out of LSN order, and
> the system I proposed could make them visible either in LSN order or
> do the same thing we do now.  They are basically independent problems,


Hannu Krosing
PostgreSQL Infinite Scalability and Performance Consultant
PG Admin Book:

In response to


pgsql-hackers by date

Next:From: Robert HaasDate: 2011-07-29 14:23:27
Subject: Re: cheaper snapshots
Previous:From: Robert HaasDate: 2011-07-29 14:09:08
Subject: Re: per-column FDW options, v5

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group