pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Smith <greg@2ndquadrant.com>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: jd@commandprompt.com, Scott Marlowe <scott.marlowe@gmail.com>
Cc: Steve Crawford <scrawford@pinpointresearch.com>
Cc: pgsql-performance@postgresql.org, Ben Chobot <bench@silentmedia.com>
Subject: Re: BBU Cache vs. spindles
Date: Thu, 21 Oct 2010 23:47:24 -0400
Message-ID: <4CC1094C.1090306@2ndquadrant.com> (raw)
In-Reply-To: <4CC0513E0200002500036C68@gw.wicourts.gov>
References: <4CC04EA50200002500036C5E@gw.wicourts.gov>
	<201010211935.o9LJZTM21744@momjian.us>
	<4CC0513E0200002500036C68@gw.wicourts.gov>

Kevin Grittner wrote:
> I assume that we send a full
> 8K to the OS cache, and the file system writes disk sectors
> according to its own algorithm.  With either platters or BBU cache,
> the data is persisted on fsync; why do you see a risk with one but
> not the other

I'd like a 10 minute argument please.  I started to write something to 
refute this, only to clarify in my head the sequence of events that 
leads to the most questionable result, where I feel a bit less certain 
than I did before of the safety here.  Here is the worst case I believe 
you're describing:

1) Transaction is written to the WAL and sync'd; client receives 
COMMIT.  Since full_page_writes is off, the data in the WAL consists 
only of the delta of what changed on the page.
2) 8K database page is written to OS cache
3) PG calls fsync to force the database block out
4) OS writes first 4K block of the change to the BBU write cache.  Worst 
case, this fills the cache, and it takes a moment for some random writes 
to process before it has space to buffer again (makes this more likely 
to happen, but it's not required to see the failure case here)
5) Sudden power interruption, second half of the page write is lost
6) Server restarts
7) That 4K write is now replayed from the battery's cache

At this point, you now have a torn 8K page, with 1/2 old and 1/2 new 
data.  Without a full page write in the WAL, is it always possible to 
restore its original state now?  In theory, I think you do.  Since the 
delta in the WAL should be overwriting all of the bytes that changed 
between the old and new version of the page, applying it on top of any 
four possible states here:

1) None of the data was written to the database page yet
2) The first 4K of data was written out
3) The second 4K of data was written out
4) All 8K was actually written out

Should lead to the same result: an 8K page that includes the change that 
was in the WAL but not onto disk at the point when the crash happened.

-- 
Greg Smith   2ndQuadrant US    greg@2ndQuadrant.com   Baltimore, MD
PostgreSQL Training, Services and Support        www.2ndQuadrant.us
"PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books




view thread (61+ messages)  latest in thread

Message-ID: <4CC1094C.1090306@2ndquadrant.com>
Permalink:  ../4CC1094C.1090306@2ndquadrant.com/
Also on:    postgresql.org/message-id/4CC1094C.1090306@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: greg@2ndquadrant.com, Kevin.Grittner@wicourts.gov, bruce@momjian.us, scott.marlowe@gmail.com, scrawford@pinpointresearch.com, bench@silentmedia.com
  Subject: Re: BBU Cache vs. spindles
  In-Reply-To: <4CC1094C.1090306@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox