Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gBkPq-0008T9-9I for pgsql-committers@arkaria.postgresql.org; Sun, 14 Oct 2018 17:42:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gBkPm-000786-TQ for pgsql-committers@arkaria.postgresql.org; Sun, 14 Oct 2018 17:42:54 +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.89) (envelope-from ) id 1gBkPk-00077y-Sf for pgsql-committers@lists.postgresql.org; Sun, 14 Oct 2018 17:42:54 +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 1gBkPc-0006Z8-Ca for pgsql-committers@lists.postgresql.org; Sun, 14 Oct 2018 17:42:51 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id EAC5A21E5A; Sun, 14 Oct 2018 13:42:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 14 Oct 2018 13:42:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=FucTVc2L8znoVcdLW4ebRQam2dn FntmE/6XNeYsbbt8=; b=SSdaMkhrJGv2/qoHZTOW6KGr6KQsAAr6k7XclHyoMPD YAE5jDxE3C8UkSeOtQuIy23QJ4vYMGVCyBC+DXUeBsMkfGqCjEaaXhFX/Rkp2fTy xjjhnT4cdIP1j+/rMkN67l+ungMHZ2UwgMpDGzMDIzAt/BFdW5uNiG9ny3e0HLHq lBZEQFLK4ut1+kPE6/lmJzXMubK8xpeFHsH4szxE3VKj35Ha6ytAx8ejBbddm2LN ijbumbjkJMDz5ad6fat3Eqg9TLN6hUmeX7LIgICbIEga2lKqa3IScA+2kRgTNfOp FaF8et0DfYxpQfgqN+Xw69IFSuPD/3am512GNvFHO4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=FucTVc 2L8znoVcdLW4ebRQam2dnFntmE/6XNeYsbbt8=; b=DOV9DQY+olKBI0NNVS4kxg /iYVX3EdiRWNqm1C51QUeid0nemnQftSdmX1DTnuIsYJEEr2EPc66MSKXVgBnwl7 /JxxFag9Y8LGZL9YK+Z8njKCfvLZp7ikYLizePRhDkq0Ot3JVERRzFcBJZeY2/qT ycj+KgmWZC8iYeI0yrPqh2LAblsD8zYUO2sRS3rNVtek1OMgsb0tYRFi810WA3IK tzaCqfiuMU1tGDkDgj3OWKV+06FNN38z6xzDuTKtw+iPp8EyYqIjMjJF2rtjpWtQ dH34W5EflF7JeydvZBKLfJbSVGJTTQjuhV0c9Ru5C+4+mgWlt/V9woSnOHyK6FFw == X-ME-Sender: X-ME-Proxy: Received: from intern.anarazel.de (c-98-210-140-171.hsd1.ca.comcast.net [98.210.140.171]) by mail.messagingengine.com (Postfix) with ESMTPA id 0FB34102E9; Sun, 14 Oct 2018 13:42:42 -0400 (EDT) Date: Sun, 14 Oct 2018 10:42:40 -0700 From: Andres Freund To: Michael Paquier Cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot Message-ID: <20181014174240.byktkskdymae7kmy@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-10-14 13:26:24 +0000, Michael Paquier wrote: > Avoid duplicate XIDs at recovery when building initial snapshot > > On a primary, sets of XLOG_RUNNING_XACTS records are generated on a > periodic basis to allow recovery to build the initial state of > transactions for a hot standby. The set of transaction IDs is created > by scanning all the entries in ProcArray. However it happens that its > logic never counted on the fact that two-phase transactions finishing to > prepare can put ProcArray in a state where there are two entries with > the same transaction ID, one for the initial transaction which gets > cleared when prepare finishes, and a second, dummy, entry to track that > the transaction is still running after prepare finishes. This way > ensures a continuous presence of the transaction so as callers of for > example TransactionIdIsInProgress() are always able to see it as alive. > > So, if a XLOG_RUNNING_XACTS takes a standby snapshot while a two-phase > transaction finishes to prepare, the record can finish with duplicated > XIDs, which is a state expected by design. If this record gets applied > on a standby to initial its recovery state, then it would simply fail, > so the odds of facing this failure are very low in practice. It would > be tempting to change the generation of XLOG_RUNNING_XACTS so as > duplicates are removed on the source, but this requires to hold on > ProcArrayLock for longer and this would impact all workloads, > particularly those using heavily two-phase transactions. > > XLOG_RUNNING_XACTS is also actually used only to initialize the standby > state at recovery, so instead the solution is taken to discard > duplicates when applying the initial snapshot. > > Diagnosed-by: Konstantin Knizhnik > Author: Michael Paquier > Discussion: https://postgr.es/m/0c96b653-4696-d4b4-6b5d-78143175d113@postgrespro.ru > Backpatch-through: 9.3 I'm unhappy this approach was taken over objections. Without a real warning. Even leaving the crummyness aside, did you check other users of XLOG_RUNNING_XACTS, e.g. logical decoding? Greetings, Andres Freund