Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egy4d-0005iY-Ja for pgsql-general@arkaria.postgresql.org; Wed, 31 Jan 2018 19:29:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egy4b-0004Em-7E for pgsql-general@arkaria.postgresql.org; Wed, 31 Jan 2018 19:29:33 +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_2) (envelope-from ) id 1egy4a-0004Ed-Fb for pgsql-general@lists.postgresql.org; Wed, 31 Jan 2018 19:29:32 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egy4S-0002CP-7L for pgsql-general@lists.postgresql.org; Wed, 31 Jan 2018 19:29:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6C9F420CA1; Wed, 31 Jan 2018 14:29:22 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 31 Jan 2018 14:29:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=DI1+p4VkqBiLs6omN87dJGCXnALKd OMut959Y3HCbB4=; b=WMtiyRdyX5VTqRM34Dr4LGvRi/UkYqJBnm+ipCrHETn6C 5ImxuczDa41ZszdQIKPMXh8IXHEAFnUdQ03D1oomUc2f0tp2kZcMXQqMLWyGnOou YGFGc9A/Pmgr4P5SpjUIGKvR3EL7h7Whi/hgtrYITipleJZROK8fqCi9yBEHGCQm hbo2DRJkAo9rg0qqZW1+2tW7fihlHZOrK8fGobF1KzEEr0HPdE1mj7xk3Pty9dUh 506SxaTJyXvU5BXr2weVyM8dGrRl3EDI5VkVAToeHqzpea5+NIMd4Q1ae4S1DlkZ 0gf03lUuIbBZkEnYScjWQxg9gnnjgloyLoB1tqrjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=DI1+p4 VkqBiLs6omN87dJGCXnALKdOMut959Y3HCbB4=; b=TOg300F5WsoeKjdVGzqY8I XwacBZm7gjYN0YRc7qgv395rgmcAXiAfazMedeN4R2n7dVpfM47eF6RUyF8SOlKT fEf0LF5e7+fX3pm3T55vseDzbDBcRcieMBMF49oRyNzobsCN+OntV5Hfm3+zChVh eYsq8z0XyeVg+C7i9lWRzOFBZQaogDNw8BSLx6d7/ge9xTZo1v6YfKl99fQlzuyg tkbZ6Q3j5AH9XFLHBhvTwXX8AAL+V34bgcnxGARVodsfHcdmUH6XxfZIxZ9v3HZP Sm7SJwbbiOVumr4v9/Zm3wjpHeDDUXF7fgtNMODdwaTLURuJZMo/R+J/3II+Dn4A == X-ME-Sender: Received: from ranger.suse (71-212-36-41.tukw.qwest.net [71.212.36.41]) by mail.messagingengine.com (Postfix) with ESMTPA id C077E246A5; Wed, 31 Jan 2018 14:29:21 -0500 (EST) Subject: Re: Issue with WAL logs temporary not replaying To: Eugene Pirogov , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Wed, 31 Jan 2018 11:29:20 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/31/2018 09:56 AM, Eugene Pirogov wrote: > Hi, > > We've experienced a DB incident related to WAL. The issue is now > somewhat resolved, and I'm trying to understand what could have caused > the problem to occur in the first place. Below is a full chronicle of an > incident we've ran into. > > At some point we realized almost no new data was coming in the DB during > the day. We quickly looked and realized the following: > > * our application was still writing data, unaware that there any > issues on the DB end, like if nothing happened at all, > * the database was accepting connections (we were able to connect and > query), > * the database was writing regular text logs, > * the database was not writing new data to the tables, > * the logical DB replica actually had the expected records replicated > and present in the replica tables, > * so we made assumption original source WAL data existed and was > correct (given the fact logical DB is relying on WAL). > > We tried to restart the DB, but it would not come up. Instead, a few > core dumps in the postgres data folder were generated during our attempts. > > This is what we saw in the postgres logs: > > LOG:  invalid resource manager ID 112 at 3/89005B10 > LOG:  invalid primary checkpoint record > LOG:  invalid resource manager ID 138 at 3/89005208 > LOG:  invalid secondary checkpoint record > PANIC:  could not locate a valid checkpoint record > > > To aid this we used pg_resetxlog. After running the pg_resetxlog > command, the DB successfully started and slowly began recovering the > data from WAL, automatically. During the recovery process, we ran VACUUM > ANALYSE couple of time, which seems to have somehow aided the speed of > recovery process (though I could have been a confirmation bias). > > The DB was fully recovered in 30 minutes. > > Upon closer inspection, however, we realized we've lost two records from > a particular table. The records were replicated to logical replica > though, and further inspection showed their insertion timestamp sometime > during the day, long after the database supposedly stopped applying new > data from WAL to tables. > > We don't know the reason why these two records were gone (no DELETE > statements ever happen in the table in question). The records in > question existed in replica table, luckly. > > The logs for the entire day when the incident happened are available > here >  (1.6 > Mb). Each log line was prepended with a timestamp. Also, we have the > core dumps that were generated during attempts to restart the database. What the role of the user 'db'? Any idea what is causing this?: WARNING: concurrent insert in progress within table "audit_log" ...repeated... many times WARNING: concurrent insert in progress within table "declarations_status_hstr" ...repeated many times Are either of these tables the one that had the two missing records? > > My questions are: > > * what would be some typical reasons for primary/secondary WAL > checkpoints to fail? Disk issues? File system issues? OS issues? I'm > running out of ideas here. > > Is there any way I could separate primary and secondary checkpoints > in space, so to increase postgres's chances to restore one of them? > > * how come postgresql would stop applying WAL logs to tables, and yet > keep silence? There was no indication WAL is not being applied, > postgres log would be silent (even though it kept writing other > commodity messages, such as "incomplete startup packet" and > malformed query attempts). > > Due to this, we noticed the issue only hours after postgres > supposedly stopped applying the WAL logs to tables. > > * Is there any other log (like some lower level system log?) where I > could see the status of writing / reading / applying WAL segments? > > * What measures could be done to prevent this in future, or at least > make the situation easier to recover from (e.g. without data loss)? > > Thank you in advance. > > -- > Eugene > > http://www.gmile.me -- Adrian Klaver adrian.klaver@aklaver.com