Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZNmHr-0006SX-7l for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Aug 2015 18:22:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZNmHq-0004GY-Pr for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Aug 2015 18:22:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZNmGX-0000hY-51 for pgsql-hackers@postgresql.org; Fri, 07 Aug 2015 18:21:13 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZNmGT-0007Um-W1 for pgsql-hackers@postgresql.org; Fri, 07 Aug 2015 18:21:11 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [181.43.9.127]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id AB2E8401195; Fri, 7 Aug 2015 11:21:02 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id F29B0819; Fri, 7 Aug 2015 15:20:54 -0300 (CLT) Date: Fri, 7 Aug 2015 15:20:54 -0300 From: Alvaro Herrera To: Heikki Linnakangas Cc: pgsql-hackers Subject: Re: All-zero page in GIN index causes assertion failure Message-ID: <20150807182054.GX2441@postgresql.org> References: <55ACADCD.6020206@iki.fi> <55AD0266.4050300@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55AD0266.4050300@iki.fi> User-Agent: Mutt/1.5.23 (2014-03-12) 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 Heikki Linnakangas wrote: > BRIN update is not quite right, however. brin_getinsertbuffer() can > initialize a page, but the caller might bail out without using the page and > WAL-logging the change. If that happens, the next update that uses the same > page will WAL-log the change but it will not use the XLOG_BRIN_INIT_PAGE > option, and redo will not initialize the page. Redo will fail. Here's a fix for BRIN: when brin_getinsertbuffer extends the relation and doesn't return the page, it initializes and logs the page as an empty regular page before returning, and also records it into the FSM. That way, some future process that gets a page from FSM will use it, preventing this type of problem from bloating the index forever. Also, this function no longer initializes the page when it returns it to the caller: instead the caller (brin_doinsert or brin_doupdate) must do that. (Previously, the code was initializing the page outside the critical section that WAL-logs this action). > BTW, shouldn't there be a step in BRIN vacuum that scans all the BRIN pages? > If an empty page is missing from the FSM for any reason, there's nothing to > add it there. Probably. I didn't change this part yet. There are two things to fix: 1. since we use log_newpage_buffer(), we log the initialization but not the recording into FSM, so the page would be forgotten about. This can be tested with PageIsEmpty(). An alternative to the vacuum scan is to use our own WAL record that not only logs the initialization itself but also the FSM update. Not sure this is worth the trouble. 2. additionally, if brin_getinsertbuffer extends the relation but we crash before the caller initializes it, the page would be detected by PageIsNew instead and would also need initialization. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers