Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJtin-0004oM-9k for pgsql-bugs@arkaria.postgresql.org; Sun, 11 Jun 2017 03:39:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dJtim-0001g2-SP for pgsql-bugs@arkaria.postgresql.org; Sun, 11 Jun 2017 03:39:24 +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 1dJtil-0001ZO-Dm for pgsql-bugs@postgresql.org; Sun, 11 Jun 2017 03:39:23 +0000 Received: from mail-qk0-x234.google.com ([2607:f8b0:400d:c09::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dJtih-0002kv-GN for pgsql-bugs@postgresql.org; Sun, 11 Jun 2017 03:39:22 +0000 Received: by mail-qk0-x234.google.com with SMTP id r62so18264881qkf.0 for ; Sat, 10 Jun 2017 20:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=zKtk94NvmgBOf/uNsXGYociMLVCy9ZDjPKR4VyywieU=; b=YwFZk6OPVx5OxxdGm6RVrWdvsNn6j4JMA99Zb+c1c4i3F4wzuYDHC+VIZ115ZMrneY lqLhqu6e9X7yN87w0IEnzh1saDwRFFEfalA0wSH3ctKGBSVG7IRQP8Muss4PX1VChRRM kY2yCuLMJL0jZte0pIFVmVG/NaI376CO5Cr6vw8F8U/9F7mfaUW+gvSwd5yENr9EME/T kYRN7iewmibX2Xumm+b0fiK6pnvMQ1O01p0QmbDbJc/uqVE9lvtk/fCLupZegJ5Y/GzX dfr/5zjHFjs+V6bskl1XwB++8uBm/lHNUVF3EpnQcqxTAn2KRwC/VPxkrTFTvjT260kO U0iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=zKtk94NvmgBOf/uNsXGYociMLVCy9ZDjPKR4VyywieU=; b=amJ5PWSFwye4R4iQQKUtxYqsmEU8WnxzyglM7+bHuhoiB7/vldYHof9tZ89cyPIfDa vzOy1Ee99VP6ItI0/KRxZ7V96dnkvo/gYj1rP7UiQ/Okzoe2/bNjs0KpFEBNjyJJf/Kf Zcp+6odbf3i/jwsiEAbTCxIz7QQ2fGLH1G5Ku2CvnB5ajZvao1KEQNCYAhrU26x4FXdS Ds0Fq3v4xojzBiclKe92vQop9ethnST+sTRHjRiSt2Onjm4osD+8V8gOlbDByunKLUoG C1c35hM7AIdJWZlr201y5yOCRHKYD+ouEDB1YvZJR0tV3STAgiiALK3MWP85EwgFwBBz xZuA== X-Gm-Message-State: AKS2vOyw1noMWcDKJtVXo8kbz3+zDU+1XI4XBM76oxzWwcP4sVpe3l+F pCQVh2Jd8xr1IyjrAiifxg== X-Received: by 10.55.212.3 with SMTP id l3mr48371824qki.112.1497152357956; Sat, 10 Jun 2017 20:39:17 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([186.9.128.128]) by smtp.gmail.com with ESMTPSA id f53sm4119166qta.67.2017.06.10.20.39.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Jun 2017 20:39:17 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 4C1C9218E; Sun, 11 Jun 2017 00:24:48 -0300 (-03) Date: Sat, 10 Jun 2017 23:24:48 -0400 From: Alvaro Herrera To: Michael Paquier Cc: wangchuanting , PostgreSQL mailing lists Subject: Re: Re: BUG #14680: startup process on standby encounter a deadlock of TwoPhaseStateLock when redo 2PC xlog Message-ID: <20170611032448.f2da5epz5pnbfmmj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170611022536.goef4cdbmgicye5g@alvherre.pgsql> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Alvaro Herrera wrote: For some reason I sent a preliminary version of the email I was writing. Some additional thoughts that were supposed to be in there: > I also agree that restoreTwoPhaseData doesn't need to hold the lock, > since we don't expect anything running concurrently, but that it's okay > to hold it and makes the whole thing simpler. It's okay to hold the lock for the whole duration of the function. > We could try to apply an equivalent rationale to > RecoverPreparedTransactions: even though we have already been running in > HOT standby mode for a while, there's no possibility of concurrent > activity either: since we exited recovery, master cannot write any more > 2PC xacts, and we haven't yet set the flag that lets open sessions write > WAL. However, it seems mildly dangerous to run the bottom sections of > the loop with the lock held, since it acquires other lwlocks and > generally does a lot of crap. Therefore, let's adopt your idea of acquiring the lock only for the specific low-level calls that require it. But the comment atop the loop needs a lot of work to explain why it's doing that (i.e. how come it's reading TwoPhaseState without a lock), as in my proposed patch. (At first, I didn't really like this very much and wanted to add more locking to that function, but it turned quite messy, so I back-tracked). Thanks -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs