Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYYXg-0000gc-MZ for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2017 13:32:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cYYXg-00017K-5f for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Jan 2017 13:32:16 +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_2) (envelope-from ) id 1cYYWG-0007zz-TP for pgsql-hackers@postgresql.org; Tue, 31 Jan 2017 13:30:49 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYYWE-0002pC-H0 for pgsql-hackers@postgresql.org; Tue, 31 Jan 2017 13:30:48 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id D6C2C21C2983; Tue, 31 Jan 2017 16:30:44 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Subject: Re: Deadlock in XLogInsert at AIX DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1485869444; bh=nlqGqqsNd3Rq9Ne3+gL99sGAr+uIPtRCTXQuBlEL0J4=; h=To:References:From:Date:In-Reply-To; b=lrFlbjVVB8rBOetuP1x60f1Fi5BzLPGfRyqwsevgMRbCcntoUwXFD9O/mY1wRBqLl 88Csp8s7xLnptloSZhGmVb7g76wXulhvBFDgz0P3YTxxHD57rrkO8ugBsckGmpA/Co 7rI6ewn7xi+jW05ZANDfbgayj2e432hoMBxNTwb8= To: Heikki Linnakangas , PostgreSQL Hackers References: <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi> From: Konstantin Knizhnik Message-ID: <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru> Date: Tue, 31 Jan 2017 16:30:52 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) 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 On 30.01.2017 19:21, Heikki Linnakangas wrote: > On 01/24/2017 04:47 PM, Konstantin Knizhnik wrote: > Interesting.. What should happen here is that for the backend's own > insertion slot, the "insertingat" value should be greater than the > requested flush point ('upto' variable). That's because before > GetXLogBuffer() calls AdvanceXLInsertBuffer(), it updates the > backend's insertingat value, to the position that it wants to insert > to. And AdvanceXLInsertBuffer() only calls > WaitXLogInsertionsToFinish() with value smaller than what was passed > as the 'upto' argument. > >> The comment to WaitXLogInsertionsToFinish says: >> >> * Note: When you are about to write out WAL, you must call this >> function >> * *before* acquiring WALWriteLock, to avoid deadlocks. This >> function might >> * need to wait for an insertion to finish (or at least advance to next >> * uninitialized page), and the inserter might need to evict an old WAL >> buffer >> * to make room for a new one, which in turn requires WALWriteLock. >> >> Which contradicts to the observed stack trace. > > Not AFAICS. In the stack trace you showed, the backend is not holding > WALWriteLock. It would only acquire it after the > WaitXLogInsertionsToFinish() call finished. > > Hmmm, may be I missed something. I am not telling about WALBufMappingLock which is required after return from XLogInsertionsToFinish. But about lock obtained by WALInsertLockAcquire at line 946 in XLogInsertRecord. It will be release at line 1021 by WALInsertLockRelease(). But CopyXLogRecordToWAL is invoked with this lock granted. > This line in the stack trace is suspicious: > >> WaitXLogInsertionsToFinish(upto = 102067874328), line 1583 in "xlog.c" > > AdvanceXLInsertBuffer() should only ever call > WaitXLogInsertionsToFinish() with an xlog position that points to a > page bounary, but that upto value points to the middle of a page. > > Perhaps the value stored in the stack trace is not what the caller > passed, but it was updated because it was past the 'reserveUpto' > value? That would explain the "request to flush past end > of generated WAL" notices you saw in the log. Now, why would that > happen, I have no idea. > > If you can and want to provide me access to the system, I could have a > look myself. I'd also like to see if the attached additional > Assertions will fire. I really get this assertion failed: ExceptionalCondition(conditionName = "!(OldPageRqstPtr <= upto || opportunistic)", errorType = "FailedAssertion", fileName = "xlog.c", lineNumber = 1917), line 54 in "assert.c" (dbx) up unnamed block in AdvanceXLInsertBuffer(upto = 147439056632, opportunistic = '\0'), line 1917 in "xlog.c" (dbx) p OldPageRqstPtr 147439058944 (dbx) p upto 147439056632 (dbx) p opportunistic '\0' Also , in another run, I encountered yet another assertion failure: ExceptionalCondition(conditionName = "!((((NewPageBeginPtr) / 8192) % (XLogCtl->XLogCacheBlck + 1)) == nextidx)", errorType = "FailedAssertion", fileName = "xlog.c", lineNumber = 1950), line 54 in "assert.c" nextidx equals to 1456, while expected value is 1457. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers