Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5cgP-0007u9-SL for pgsql-bugs@arkaria.postgresql.org; Wed, 25 May 2016 17:33:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b5cgP-0000nq-8W for pgsql-bugs@arkaria.postgresql.org; Wed, 25 May 2016 17:33:25 +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 1b5cgN-0000jn-ML for pgsql-bugs@postgresql.org; Wed, 25 May 2016 17:33:23 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b5cgK-0008Vt-Hk for pgsql-bugs@postgresql.org; Wed, 25 May 2016 17:33:23 +0000 Received: by mail-wm0-x229.google.com with SMTP id n129so193873798wmn.1 for ; Wed, 25 May 2016 10:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant.it; s=google; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to; bh=g+1OvHK+YaQvopjSI3q0VvE3qfgnTkDeo1rYojpF4dQ=; b=M9cnpJUlG8qM0VGREvaZEUPcYX7laI3Rv4EoL1MbVpexvvvLMGmWJdldeCfV0iBC3O NDXOTB/roWc1U8T6LRHoZeMtHkPDUVvAwWsbhGDwsn9H8yDcNC5PmBbzSwAhocOzFI3j 4qmPhxtsF5HDAobCohi5pLdu9PgngXAj+BcoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to; bh=g+1OvHK+YaQvopjSI3q0VvE3qfgnTkDeo1rYojpF4dQ=; b=EoLBxFjzI0DV8C8r4Y/9BzmGln7o3HKZ4LRA8krV9Ek6qw29+vQd7RFURUi/VPYoBm SBM7Fa+4safWoi9t31w6IwhYXwwNn8K2cqUjOLiGxVsxzcHGZ4vsVGJH6BlCHQGV0iUn PM4hrOrhRMpe0TSVFYUag++N+fa1iCf75cTwkXwUsSBnSB5oqjqeMkMgbrUxqa1TMzwR B59WQEYaa1qUsuaE/Ttl/EMbkO8Ap32eEmqAajE95Z6nLlT27wK+cbRTxE8ZoVF6TF3b 3j+tkqa7kMO3+8+XUWM1PUYY+PzK8XnHBCjqR4hmFCTrJe79DN9KZZYrETmdz79WaFDz Ysmw== X-Gm-Message-State: ALyK8tJo6TGxY1A7iHU9EXCNjTwTKC+4hZjNkQDzZAirlfSKOGCvS4SXmjkgwaO0C5s89JB0 X-Received: by 10.28.181.148 with SMTP id e142mr4603435wmf.38.1464197597999; Wed, 25 May 2016 10:33:17 -0700 (PDT) Received: from titanium.local (net-37-182-231-222.cust.vodafonedsl.it. [37.182.231.222]) by smtp.googlemail.com with ESMTPSA id lf9sm9950220wjc.44.2016.05.25.10.33.16 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 May 2016 10:33:17 -0700 (PDT) Subject: Re: [HACKERS] BUG #13473: VACUUM FREEZE mistakenly cancel standby sessions References: <20150626134310.3876.82768@wrigleys.postgresql.org> <558D58B1.70400@2ndquadrant.it> <558DDC9B.6090001@BlueTreble.com> From: Marco Nenciarini To: pgsql-bugs@postgresql.org, PostgreSQL-development Message-ID: <52fb5d06-ac66-ea1e-c6fd-46949d17962e@2ndquadrant.it> Date: Wed, 25 May 2016 19:33:12 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <558DDC9B.6090001@BlueTreble.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xQkvfIgxANTFbpWo8b9uVMe1hw0AdkDMN" X-Pg-Spam-Score: -2.7 (--) 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 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --xQkvfIgxANTFbpWo8b9uVMe1hw0AdkDMN Content-Type: multipart/mixed; boundary="IdWqsQaGTPl10B3lVTn58jVWJ3rXE1vJj" From: Marco Nenciarini To: pgsql-bugs@postgresql.org, PostgreSQL-development Message-ID: <52fb5d06-ac66-ea1e-c6fd-46949d17962e@2ndquadrant.it> Subject: Re: [HACKERS] [BUGS] BUG #13473: VACUUM FREEZE mistakenly cancel standby sessions References: <20150626134310.3876.82768@wrigleys.postgresql.org> <558D58B1.70400@2ndquadrant.it> <558DDC9B.6090001@BlueTreble.com> In-Reply-To: <558DDC9B.6090001@BlueTreble.com> --IdWqsQaGTPl10B3lVTn58jVWJ3rXE1vJj Content-Type: multipart/mixed; boundary="------------F5E1BDFE60CE9E2AAFD71819" This is a multi-part message in MIME format. --------------F5E1BDFE60CE9E2AAFD71819 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 27/06/15 01:13, Jim Nasby wrote: > On 6/26/15 8:50 AM, Marco Nenciarini wrote: >>> >In the heap_xlog_freeze we need to subtract one to the value of >>> cutoff_xid >>> >before passing it to ResolveRecoveryConflictWithSnapshot. >>> > >>> > >>> > >> Attached a proposed patch that solves the issue. >=20 I have hit the bug again, as it has been fixed only from 9.5+ The procedure to reproduce it sent in the original post is not fully accurate, below there is one that always works: Run the following operation on an idle cluster. 1) connect to the master and run the following script create table t(id int primary key); insert into t select generate_series(1, 10000); 2) connect to the standby and simulate a long running query: select pg_sleep(3600); 3) on the master and run the following commands: vacuum freeze verbose t; drop table t; 4) after 30 seconds the pg_sleep query on standby will be canceled. Attached there is a patch that apply on every version that misses the fix (9.0, 9.1, 9.2, 9.3, 9.4) Regards, Marco --=20 Marco Nenciarini - 2ndQuadrant Italy PostgreSQL Training, Services and Support marco.nenciarini@2ndQuadrant.it | www.2ndQuadrant.it --------------F5E1BDFE60CE9E2AAFD71819 Content-Type: text/x-patch; name="avoid-hot-standby-cancels-from-vac-freeze.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="avoid-hot-standby-cancels-from-vac-freeze.patch" diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/h= eapam.c index eb8eada..434880a 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -4764,7 +4764,13 @@ heap_xlog_freeze(XLogRecPtr lsn, XLogRecord *recor= d) * consider the frozen xids as running. */ if (InHotStandby) - ResolveRecoveryConflictWithSnapshot(cutoff_xid, xlrec->node); + { + TransactionId latestRemovedXid =3D cutoff_xid; + + TransactionIdRetreat(latestRemovedXid); + + ResolveRecoveryConflictWithSnapshot(latestRemovedXid, xlrec->node); + } =20 /* If we have a full-page image, restore it and we're done */ if (record->xl_info & XLR_BKP_BLOCK(0)) --------------F5E1BDFE60CE9E2AAFD71819-- --IdWqsQaGTPl10B3lVTn58jVWJ3rXE1vJj-- --xQkvfIgxANTFbpWo8b9uVMe1hw0AdkDMN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJXReHbAAoJEFifA/AbpVA4xfoQAJFGZBvwMMD8uq/mAnVvv0qm o6pdBrH50yc8yX276wL+tS7M4O5Im0SJ6C4sXQe4ZZTrKAmx5dTn1iLCb1+4E4UK bXIGcadEmpXS2xYMcSELbRRvdVGpgYRi7pcSopQXYevjdxa3zXC8xOp5CsZKUIIL r5jF6px/0F4ZFYSwdC8gt8V/ScdFzJht9H5nMDz5JpCh4z2QMyn1RoOhZEaVjTNN D93zirgZne2nabxoCMEyrGe8GdVJsPGzVa+tRo7Mkn7FiBJfNZ/lS7Pp3ioCL30Y 1t7E8BJ07F+EtiobrITOpOvgQfzrqnb1P+2aFHfKJg5qT2D97jRhfIkG5rVvri/p EFjiuKF52p8svqJV5ZFZ4d28Uuy85sdEfDa7BpRMmpogI2EqN1h0o/McVO3uQfZf ZBz2s05uSY8b4BYWYARgyd6fkMnxUCSzVXlqcHq42s20BTCnxeApbToxge1esZdb qDFcyJxZwrBq19pRhZiLEIQ1eIDXAbx9t/5iJCL78GS4nDGvPlj9Dk36WMWM2Eay iWMmMJATQ1gFKnlkMCiJs1MzTycTA7SfN8bzeE6q6GPSw2JuA0jBVklkRRsvxDO6 xj5ZZhdvMLYTqU+lSH80vlcOqUeTh7LU40QVyqTvRc+XTp3mWrxQ2uWK/tIJ1ZGQ xPQjyd5DjO+x7dHQ94kW =OMpq -----END PGP SIGNATURE----- --xQkvfIgxANTFbpWo8b9uVMe1hw0AdkDMN--