Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3ywA-0008Cz-8h for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Mar 2019 08:08:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3yw8-0007MD-LM for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Mar 2019 08:08:28 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3yw8-0007M1-D6; Wed, 13 Mar 2019 08:08:28 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3yw2-0000WP-Ks; Wed, 13 Mar 2019 08:08:27 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2E29022079; Wed, 13 Mar 2019 04:08:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 13 Mar 2019 04:08:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=eGSvAz0TbKMVxYsTJcVzlU35qQp m2rCHw+OhDp9NXn0=; b=QJ9v1tfSbanYe8frh6XAbOSDArc+Z/NWsPsZv+nnL3Z xRyWw8cFPnsf1m26sWgQiazhTAYJlT8jI03ZL26rTa+AxT7nVE5KXzIYSW62mlAi bKlam7SFN2B2DO7LLuGc4Hiy+Vaz2kPxCcRO0gpzNpyNgAwzneE/YuLYCetoPNmN +hTVtMO2LC98r8rof9x9wPuUGKZ8TkDJal+uSR4w0z4Ps3pzap3cMBdBZZF1r9++ JTw6eaADzW0aEysd01lnJwVTRgC501Y8jRN3bv4WjUgMfrJGlWIWj1/dFB06tmIg VE9YOgCBbsNlrFPjCutjTrXeJ907XLBE40ujZSP9JXQ== 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=fm2; bh=eGSvAz 0TbKMVxYsTJcVzlU35qQpm2rCHw+OhDp9NXn0=; b=75hS0uYpXiLd7y+LMyl8+9 rntPPUvHQV5QOnpE5SPn97jHkwesumuh57Mj5ThsUU3gu4mrX/Tk0UaUsDE9zuoM ptZsVCHx/b0BaVrJ1u/W0jigMj0i9ZXxwhSF/TUpOj1+VNXBP+IeFUJGmPwFOoKn toFdsfh56luuTouSAY+QEQ9E6a/QXDgNZoI4LEHXgTFVum7GcBbWcH0+dSIM5lZL pYdrIIz5oZO7/6wflb+JbUOzF3Olc+1+T/zEGhFVqsIFrzMk7WyiYCAy8WnMQhay qzRL4fkUrT3oz+EYgtFpR5p+achS6CepWU1qqItemHwoZqPyS17T2C9arSAbVl5Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrgeelgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepiedurddvudehrddufeejrdduiedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id A84F310343; Wed, 13 Mar 2019 04:08:18 -0400 (EDT) Date: Wed, 13 Mar 2019 17:08:15 +0900 From: Michael Paquier To: Mithun Cy Cc: pgsql-bugs@lists.postgresql.org, pgsql-hackers@lists.postgresql.org, michael.paquier@gmail.com, fujii@postgresql.org, kuntalghosh.2007@gmail.com, Robert Haas Subject: Re: pg_rewind : feature to rewind promoted standby is broken! Message-ID: <20190313080815.GD2988@paquier.xyz> References: <20190312092301.GL13812@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="//IivP0gvsAy3Can" Content-Disposition: inline In-Reply-To: <20190312092301.GL13812@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --//IivP0gvsAy3Can Content-Type: multipart/mixed; boundary="Q0rSlbzrZN6k9QnT" Content-Disposition: inline --Q0rSlbzrZN6k9QnT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Mar 12, 2019 at 06:23:01PM +0900, Michael Paquier wrote: > And you are pointing out to the correct commit. The issue is that > process_target_file() has added a call to check_file_excluded(), and > this skips all the folders which it thinks can be skipped. One > problem though is that we also filter out pg_internal.init, which is > present in each database folder, and remains in the target directory > marked for deletion. Then, when the deletion happens, the failure > happens as the directory is not fully empty. Okay, here is a refined patch with better comments, the addition of a test case (creating tables in the new databases in 002_databases.pl is enough to trigger the problem). Could you check that it fixes the issue on your side? -- Michael --Q0rSlbzrZN6k9QnT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="rewind-filter-fix-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c index bb4ffd0e38..57b77e1840 100644 --- a/src/bin/pg_rewind/filemap.c +++ b/src/bin/pg_rewind/filemap.c @@ -334,12 +334,13 @@ process_target_file(const char *path, file_type_t typ= e, size_t oldsize, file_entry_t *entry; =20 /* - * Ignore any path matching the exclusion filters. This is not actually - * mandatory for target files, but this does not hurt and let's be - * consistent with the source processing. + * Do not apply any exclusion filters here. The folders marked for + * deletion on the target should be entirely empty, and we also + * check after pg_internal.init which is present in each database + * folder. Not applying any exclusion filters here also has the + * advantage to remove any files on the target which have been filtered + * from the source. */ - if (check_file_excluded(path, false)) - return; =20 snprintf(localpath, sizeof(localpath), "%s/%s", datadir_target, path); if (lstat(localpath, &statbuf) < 0) diff --git a/src/bin/pg_rewind/t/002_databases.pl b/src/bin/pg_rewind/t/002= _databases.pl index 6dc05720a1..0562c21549 100644 --- a/src/bin/pg_rewind/t/002_databases.pl +++ b/src/bin/pg_rewind/t/002_databases.pl @@ -15,19 +15,27 @@ sub run_test RewindTest::setup_cluster($test_mode, ['-g']); RewindTest::start_master(); =20 - # Create a database in master. + # Create a database in master with a table. master_psql('CREATE DATABASE inmaster'); + master_psql('CREATE TABLE inmaster_tab (a int)', 'inmaster'); =20 RewindTest::create_standby($test_mode); =20 - # Create another database, the creation is replicated to the standby + # Create another database with another table, the creation is + # replicated to the standby. master_psql('CREATE DATABASE beforepromotion'); + master_psql('CREATE TABLE beforepromotion_tab (a int)', + 'beforepromotion'); =20 RewindTest::promote_standby(); =20 # Create databases in the old master and the new promoted standby. master_psql('CREATE DATABASE master_afterpromotion'); + master_psql('CREATE TABLE master_promotion_tab (a int)', + 'master_afterpromotion'); standby_psql('CREATE DATABASE standby_afterpromotion'); + standby_psql('CREATE TABLE standby_promotion_tab (a int)', + 'standby_afterpromotion'); =20 # The clusters are now diverged. =20 diff --git a/src/bin/pg_rewind/t/RewindTest.pm b/src/bin/pg_rewind/t/Rewind= Test.pm index 85cae7e47b..2c98fa5712 100644 --- a/src/bin/pg_rewind/t/RewindTest.pm +++ b/src/bin/pg_rewind/t/RewindTest.pm @@ -68,18 +68,20 @@ our $node_standby; sub master_psql { my $cmd =3D shift; + my $dbname =3D shift || 'postgres'; =20 system_or_bail 'psql', '-q', '--no-psqlrc', '-d', - $node_master->connstr('postgres'), '-c', "$cmd"; + $node_master->connstr($dbname), '-c', "$cmd"; return; } =20 sub standby_psql { my $cmd =3D shift; + my $dbname =3D shift || 'postgres'; =20 system_or_bail 'psql', '-q', '--no-psqlrc', '-d', - $node_standby->connstr('postgres'), '-c', "$cmd"; + $node_standby->connstr($dbname), '-c', "$cmd"; return; } =20 --Q0rSlbzrZN6k9QnT-- --//IivP0gvsAy3Can Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlyIum8ACgkQnvQgOdby QH0mahAAqA8Rnmf7j8Cw0NvnrUjG5tAESzKBUUw68kdYq1/f3HbqXWE2kzoGozXV ef48QFU0zeoNwvlwH3mok1UCinvT+fLR98apjSTuy1KqDyGUZ/PQbq86M4uILklD r2ptCtpIR/OxZW9GuiGGFpPntJDgkK851n+ib4N68Sapzj6yiMavYPOwoOfsa2Uv VNwpJB1OTBbshgKgesZlYMpdUQqa9YkwOD6cWha4c3nUdm0W8EC3phoDAn96mZDG /b1vOuVPFLsALHRk6omnnWDb/sMbMZLPBhGIeD0FkwVDYSnckAld/IncfzV6do9d EOoJMGr+/U5DqoQnoUo7j77Tihh/GWiuyY3R7X3ii5b2+55g9jEdRteO3gSFBBxR 3ogweXeBRF3vrsJUsQCUocTVedsvTkOCNRCy0gqY1UrjGfrEzBV9AF5kquRbkSBQ +K0vYzKY23cY/EBdoWoq7eptzvqLqHtZGNpe2f+TnyclxstUaPpeHr20KyGOwolR YGIW54KYfoxleWdqFI98kZuMA6HgTCUEQSJgGT1qF71hNKusMTNEaoCFhKE2lqIN 1QJueH+bDQbxX0jEL56IoZ4BxqeJk5thsJq5woxX+XEOtuDzHkuJd1r/pwCR4aHN CZC/4VCG+PzNvRwH4jaJAk/6cfSV7hUpSsIkpBkRpvKzTfPJ8jU= =B8fb -----END PGP SIGNATURE----- --//IivP0gvsAy3Can--