Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZC8h6-0002ii-4K for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2015 15:52:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZC8h5-0006pT-HR for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2015 15:52:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZC8eh-0004FK-1e for pgsql-hackers@postgresql.org; Mon, 06 Jul 2015 15:50:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZC8ee-0002IW-31 for pgsql-hackers@postgresql.org; Mon, 06 Jul 2015 15:50:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t66FnsID028416; Mon, 6 Jul 2015 11:49:54 -0400 From: Tom Lane To: Andres Freund cc: Fujii Masao , Martijn van Oosterhout , PostgreSQL-development Subject: Re: WAL logging problem in 9.4.3? In-reply-to: <20150706152123.GK8902@alap3.anarazel.de> References: <20150703060137.GB20285@svana.org> <28320.1435935120@sss.pgh.pa.us> <20150703164931.GI3291@awork2.anarazel.de> <20150703170229.GJ3291@awork2.anarazel.de> <20150703172605.GM3291@awork2.anarazel.de> <27532.1436195680@sss.pgh.pa.us> <20150706152123.GK8902@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Mon, 06 Jul 2015 17:21:23 +0200" Date: Mon, 06 Jul 2015 11:49:54 -0400 Message-ID: <28415.1436197794@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andres Freund writes: > On 2015-07-06 11:14:40 -0400, Tom Lane wrote: >> The COUNT() correctly says 11 rows, but after crash-and-recover, >> only the row with -1 is there. This is because the INSERT writes >> out an INSERT+INIT WAL record, which we happily replay, clobbering >> the data added later by COPY. > ISTM any WAL logged action that touches a relfilenode essentially needs > to disable further optimization based on the knowledge that the relation > is new. After a bit more thought, I think it's not so much "any WAL logged action" as "any unconditionally-replayed action". INSERT+INIT breaks this example because heap_xlog_insert will unconditionally replay the action, even if the page is valid and has same or newer LSN. Similarly, TRUNCATE is problematic because we redo it unconditionally (and in that case it's hard to see an alternative). > It'd not be impossible to add more state to the relcache entry for the > relation. Whether it's likely that we'd find all the places that'd need > updating that state, I'm not sure. Yeah, the sticking point is mainly being sure that the state is correctly tracked, both now and after future changes. We'd need to identify a state invariant that we could be pretty confident we'd not break. One idea I had was to allow the COPY optimization only if the heap file is physically zero-length at the time the COPY starts. That would still be able to optimize in all the cases we care about making COPY fast for. Rather than reverting cab9a0656c36739f, which would re-introduce a different performance problem, perhaps we could have COPY create a new relfilenode when it does this. That should be safe if the table was previously empty. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers