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 1fq2p6-0005bI-5k for pgsql-general@arkaria.postgresql.org; Wed, 15 Aug 2018 20:55:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fq2p4-00085F-HP for pgsql-general@arkaria.postgresql.org; Wed, 15 Aug 2018 20:55:18 +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.89) (envelope-from ) id 1fq2p4-000855-8q for pgsql-general@lists.postgresql.org; Wed, 15 Aug 2018 20:55:18 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fq2ow-0003aN-IR for pgsql-general@lists.postgresql.org; Wed, 15 Aug 2018 20:55:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 827FD21BF1; Wed, 15 Aug 2018 16:55:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 Aug 2018 16:55:07 -0400 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=fm3; bh=TPScBfS1xyQYFILbJntemxnOHpwby RV1QnQRFQynhug=; b=qmTv+5vEI4EtdTIfkYVIANmfJ7v1XHL2712VL5bz/XcUH j46m+0bQmh33zIwXaJ4aGi7aGw5ZyMasnZxn+ZX+T0lCjRG/otH36/BwY03pDJvx hSm5ELzc4BIlUlRHChm+Pe21L84ml/ohvqiskS8SuFAL/Q+ctulYE+uEPHl330B2 3GiO8FluKVAtpgnSRg8OFjGqFQJViRi9vyv8NdBKfcL4gLES4sSr/TUMOmn97bS4 GuC1O3jtO/D/HOH9L4xYuRngKucl59foYGD8zda/x1/cU+P5bTKhy6XIxjW0w2s4 qN7vGXDv70nRrE8Xtc6sqnVQNE8ru2wW7ek6oLjIg== 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=fm3; bh=TPScBf S1xyQYFILbJntemxnOHpwbyRV1QnQRFQynhug=; b=dY21IVwmecrJYCmcSyrRcZ uBVU+Zk8P2BcgT4DIKMupAYbLCPN8KJdal3GA36yQHGNUo5STw91UXZ2ncMkQOTh FuR8nytxiLiP34Od1hLUuF6LbJsHdlevWo7ZMeoKGmyoq+lLy/rpcLt0PFG28NuK +0wokMv2mJ23kFc6STFKNk27Oua7eMXVUEeZDiA9AU+W39HCVGmBRdns8XFb2Y3F FCxV1yD2S+y7uSBAoyP6LWSKrygCJduLHkVz5YcOANSFqInuYN+6hcYkep9Ol8RR wHDySol91WitheX7S20TUSEryajG9c5xFJ0KZDQbj+Ddh7WiA4sDIwNAj0TQ4Vqg == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 700CEE4696; Wed, 15 Aug 2018 16:55:06 -0400 (EDT) Subject: Re: During promotion, new master tries to archive same segment twice To: Phil Endecott , pgsql-general@lists.postgresql.org References: <1534364719828@dmwebmail.dmwebmail.chezphil.org> From: Adrian Klaver Message-ID: <5e8344fd-e736-9439-9a10-eb8838e51c03@aklaver.com> Date: Wed, 15 Aug 2018 13:55:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1534364719828@dmwebmail.dmwebmail.chezphil.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 08/15/2018 01:25 PM, Phil Endecott wrote: > Dear Experts, > > Here is my latest issue with replication: > > I have 3 systems, X, Y and Z. Initially X is replicated to Y > and Y is replicated to Z; in each case the replication involves > log-shipping using archive_command and restore_command (via a > 4th system called "backup") and then streaming. > > The plan is to shut down X and to promote Y to be the new master. > > I shut down X, and as expected Y complains that it con no longer > connect to it: > > 2018-08-15 15:10:58.785 UTC [617] LOG: replication terminated by primary server > 2018-08-15 15:10:58.785 UTC [617] DETAIL: End of WAL reached on timeline 1 at 7/E9000098. > 2018-08-15 15:10:58.785 UTC [617] FATAL: could not send end-of-streaming message to primary: no COPY in progress > scp: backup/postgresql/archivedir/0000000100000007000000E9: No such file or directory > 2018-08-15 15:10:59.928 UTC [354] LOG: invalid resource manager ID 22 at 7/E9000098 > 2018-08-15 15:11:00.092 UTC [5856] FATAL: could not connect to the primary server: FATAL: the database system is shutting down > > Note that in the middle of that, after streaming has failed it > tries to fetch the next WAL segment, E9, from the backup; this > fails because this segment doesn't exist. > > Then I pg_ctl promote on Y: > > 2018-08-15 15:12:11.888 UTC [354] LOG: received promote request > 2018-08-15 15:12:11.888 UTC [354] LOG: redo done at 7/E9000028 > 2018-08-15 15:12:11.888 UTC [354] LOG: last completed transaction was at log time 2018-08-15 14:45:05.961153+00 > scp: backup/postgresql/archivedir/0000000100000007000000E9: No such file or directory > scp: backup/postgresql/archivedir/00000002.history: No such file or directory > 2018-08-15 15:12:13.316 UTC [354] LOG: selected new timeline ID: 2 > 2018-08-15 15:12:13.368 UTC [354] FATAL: could not open file "recovery.conf": Permission denied > > So in the process of exiting recovery mode it tries to rename > recovery.conf to recovery.done, but it fails to do so because > my recovery.conf was owned by root, not user postgres. Oooops. > Perhaps it would be appropriate to check for that when it > initially reads recovery.conf? Anyway, I fix the permissions > and restart it. It starts in recovery mode and cannot connect > to the master, as expected. > > 2018-08-15 15:16:58.061 UTC [6036] LOG: restored log file "0000000100000007000000E8" from archive > 2018-08-15 15:16:58.108 UTC [6036] LOG: redo starts at 7/E8678300 > 2018-08-15 15:16:58.731 UTC [6087] LOG: archive command failed with exit code 1 > 2018-08-15 15:16:58.731 UTC [6087] DETAIL: The failed archive command was: ssh backup test ! -f backup/postgresql/Y/0000000100000007000000E8 && scp pg_xlog/0000000100000007000000E8 backup:backup/postgresql/Y/0000000100000007000000E8 > scp: backup/postgresql/archivedir/0000000100000007000000E9: No such file or directory The above is not clear to me. My best guess: 1) The ssh backup ... is archiving WAL's from Y to Y specific archive on 'backup'? 2) The scp: backup ... is the restore_command fetching archived WAL's that originated on X and where sent to backup/postgresql/archivedir/ ? 3) If 2) is true why is it showing up in the error for the archive command? Can you show us your actual archive and restore commands? More below. > 2018-08-15 15:16:58.823 UTC [6036] LOG: consistent recovery state reached at 7/E9000098 > 2018-08-15 15:16:58.823 UTC [6036] LOG: invalid resource manager ID 22 at 7/E9000098 > 2018-08-15 15:16:58.824 UTC [6035] LOG: database system is ready to accept read only connections > 2018-08-15 15:16:58.855 UTC [6094] FATAL: could not connect to the primary server: could not connect to server: Connection refused > > > I can now connect to the db and do read/write operations, but it > continues to try and fail to re-write segment E8 to its archive. > > Eventually I manually delete E8 from the archive; it then > succeeds at writing it with the same content as before and seems to > continue to function normally. Which archive? > > Questions: > > - Can all of this be blamed on the failure of the first attempt > to promote due to the wrong permissions on recovery.conf? > > - Should my archive_command detect the case where it is asked to > write the same file again with the same contents, and report > success in that case? > > - Is this a bug? > > > Thanks, > > Phil. > > > > -- Adrian Klaver adrian.klaver@aklaver.com