Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 1D0FC1337B69 for ; Tue, 30 Nov 2010 23:07:34 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 82718-09 for ; Wed, 1 Dec 2010 03:07:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 6BD641335B36 for ; Tue, 30 Nov 2010 23:07:24 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id oB137IA19179; Tue, 30 Nov 2010 22:07:18 -0500 (EST) From: Bruce Momjian Message-Id: <201012010307.oB137IA19179@momjian.us> Subject: Re: BBU Cache vs. spindles In-Reply-To: <4CC1094C.1090306@2ndquadrant.com> To: Greg Smith Date: Tue, 30 Nov 2010 22:07:18 -0500 (EST) CC: Kevin Grittner , jd@commandprompt.com, Scott Marlowe , Steve Crawford , pgsql-performance@postgresql.org, Ben Chobot X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1291172838-22505-0_" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/426 X-Sequence-Number: 41450 --ELM1291172838-22505-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" Greg Smith wrote: > 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 Based on this report, I think we need to update our documentation and backpatch removal of text that says that BBU users can safely turn off full-page writes. Patch attached. I think we have fallen into a trap I remember from the late 1990's where I was assuming that an 8k-block based file system would write to the disk atomically in 8k segments, which of course it cannot. My bet is that even if you write to the kernel in 8k pages, and have an 8k file system, the disk is still accessed via 512-byte blocks, even with a BBU. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --ELM1291172838-22505-0_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/pgpatches/bbu" diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index a2724fa..1e67bbd 100644 *** /tmp/pgrevert.14281/7sLqTb_wal.sgml Tue Nov 30 21:57:17 2010 --- doc/src/sgml/wal.sgml Tue Nov 30 21:56:49 2010 *************** *** 164,173 **** PostgreSQL periodically writes full page images to permanent WAL storage before modifying the actual page on disk. By doing this, during crash recovery PostgreSQL can ! restore partially-written pages. If you have a battery-backed disk ! controller or file-system software that prevents partial page writes ! (e.g., ZFS), you can turn off this page imaging by turning off the ! parameter. --- 164,175 ---- PostgreSQL periodically writes full page images to permanent WAL storage before modifying the actual page on disk. By doing this, during crash recovery PostgreSQL can ! restore partially-written pages. If you have file-system software ! that prevents partial page writes (e.g., ZFS), you can turn off ! this page imaging by turning off the parameter. Battery-Backed unit ! (BBU) disk controllers do not prevent partial page writes unless ! they guarantee that data is written to the BBU as full (8kB) pages. --ELM1291172838-22505-0_--