Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8U1q-0004a8-7q for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jun 2015 13:50:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z8U1p-0005LF-L6 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jun 2015 13:50:49 +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.84) (envelope-from ) id 1Z8U1n-0005IW-IU for pgsql-hackers@postgresql.org; Fri, 26 Jun 2015 13:50:47 +0000 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Z8U1k-00070n-OJ for pgsql-hackers@postgresql.org; Fri, 26 Jun 2015 13:50:46 +0000 Received: by wibdq8 with SMTP id dq8so18603659wib.1 for ; Fri, 26 Jun 2015 06:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant.it; s=google; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=JBGEo+mu/MYoJgXpoFKW1AP/IjW45mLGpCs9WlgTYuk=; b=OC41vRzam8Hs4V/F2z/EZf3Dqbskc5daZWL6c6RJLn05OglVwx4VmYOmETEr2/3t0a ZXHVQqS/yj+QD4tOlsC0oXVpGR4SP5WsUlLWa6T01tVrfIf9Md/6l7uyGmbe5+Q0jN// 4JEP1jPy/kLLbq+fYJLNc0gF/GoRVGZC7058U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=JBGEo+mu/MYoJgXpoFKW1AP/IjW45mLGpCs9WlgTYuk=; b=DtWWC3bUaLDa1zBOcWrOqPu+YoKb3XpcFx5YxjfOM3X+sqEn9sQF+9l6//L8JJV65Z uhrKOKT1XQWN3i8ixm+sX7AlLlynrGUgbPMyDBrVEVH/r7aMIgB3lwdF89kMT4/0rEZ4 skRbmodRF94IkTV7MHk7bMAPeXwcqJhjy+MACVRZThu2avKrIvwqzGgc/ct4YAdAbMe2 TOm6qXKUCRTeJ5mh9qX977V5w4x5pF6u7GV/S2tkNcscA2uHsfxJbqzoIUIyYdrn/SXB qR00DpuTiXPQ0xBUPBHtHDYXNsZ2Oh1Y5HD9RMWFhtce0mpgrkYF17ULlfrESYnntSMs LJTw== X-Gm-Message-State: ALoCoQkgGUTjN09BGqWgGIlG1lYqCM1bkUlWjSZadE75hSEDteaOgD+mAxy7jYF6hkRz2znyyI8V X-Received: by 10.180.7.199 with SMTP id l7mr5292783wia.28.1435326643163; Fri, 26 Jun 2015 06:50:43 -0700 (PDT) Received: from savant.local ([93.188.113.99]) by mx.google.com with ESMTPSA id u7sm2356074wif.3.2015.06.26.06.50.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 06:50:42 -0700 (PDT) Message-ID: <558D58B1.70400@2ndquadrant.it> Date: Fri, 26 Jun 2015 15:50:41 +0200 From: Marco Nenciarini User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org, PostgreSQL-development Subject: Re: [BUGS] BUG #13473: VACUUM FREEZE mistakenly cancel standby sessions References: <20150626134310.3876.82768@wrigleys.postgresql.org> In-Reply-To: <20150626134310.3876.82768@wrigleys.postgresql.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="C2WH7ErH61dAGiQuNTINVchafODPOqgEE" X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --C2WH7ErH61dAGiQuNTINVchafODPOqgEE Content-Type: multipart/mixed; boundary="------------010305080207070209060305" This is a multi-part message in MIME format. --------------010305080207070209060305 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Il 26/06/15 15:43, marco.nenciarini@2ndquadrant.it ha scritto: > The following bug has been logged on the website: >=20 > Bug reference: 13473 > Logged by: Marco Nenciarini > Email address: marco.nenciarini@2ndquadrant.it > PostgreSQL version: 9.4.4 > Operating system: all > Description: =20 >=20 > =3D Symptoms >=20 > Let's have a simple master -> standby setup, with hot_standby_feedback > activated, > if a backend on standby is holding the cluster xmin and the master runs= a > VACUUM FREEZE > on the same database of the standby's backend, it will generate a confl= ict > and the query > running on standby will be canceled. >=20 > =3D How to reproduce it >=20 > Run the following operation on an idle cluster. >=20 > 1) connect to the standby and simulate a long running query: >=20 > select pg_sleep(3600); >=20 > 2) connect to the master and run the following script >=20 > create table t(id int primary key); > insert into t select generate_series(1, 10000); > vacuum freeze verbose t; > drop table t; >=20 > 3) after 30 seconds the pg_sleep query on standby will be canceled. >=20 > =3D Expected output >=20 > The hot standby feedback should have prevented the query cancellation >=20 > =3D Analysis >=20 > Ive run postgres at DEBUG2 logging level, and I can confirm that the va= cuum > correctly see the OldestXmin propagated by the standby through the hot > standby feedback. > The issue is in heap_xlog_freeze function, which calls > ResolveRecoveryConflictWithSnapshot as first thing, passing the cutoff_= xid > value as first argument. > The cutoff_xid is the OldestXmin active when the vacuum, so it represen= ts a > running xid.=20 > The issue is that the function ResolveRecoveryConflictWithSnapshot expe= cts > as first argument of is latestRemovedXid, which represent the higher xi= d > that has been actually removed, so there is an off-by-one error. >=20 > I've been able to reproduce this issue for every version of postgres si= nce > 9.0 (9.0, 9.1, 9.2, 9.3, 9.4 and current master) >=20 > =3D Proposed solution >=20 > In the heap_xlog_freeze we need to subtract one to the value of cutoff_= xid > before passing it to ResolveRecoveryConflictWithSnapshot. >=20 >=20 >=20 Attached a proposed patch that solves the issue. Regards, Marco --=20 Marco Nenciarini - 2ndQuadrant Italy PostgreSQL Training, Services and Support marco.nenciarini@2ndQuadrant.it | www.2ndQuadrant.it --------------010305080207070209060305 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="hs_freeze_offby1.v1.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="hs_freeze_offby1.v1.patch" ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2FjY2Vzcy9oZWFwL2hlYXBhbS5jIGIvc3JjL2Jh Y2tlbmQvYWNjZXNzL2hlYXAvaGVhcGFtLmMKaW5kZXggY2FhY2MxMC4uMjhlZGIxNyAxMDA2 NDQKLS0tIGEvc3JjL2JhY2tlbmQvYWNjZXNzL2hlYXAvaGVhcGFtLmMKKysrIGIvc3JjL2Jh Y2tlbmQvYWNjZXNzL2hlYXAvaGVhcGFtLmMKQEAgLTc1NzEsOSArNzU3MSwxMiBAQCBoZWFw X3hsb2dfZnJlZXplX3BhZ2UoWExvZ1JlYWRlclN0YXRlICpyZWNvcmQpCiAJaWYgKEluSG90 U3RhbmRieSkKIAl7CiAJCVJlbEZpbGVOb2RlIHJub2RlOworCQlUcmFuc2FjdGlvbklkIGxh dGVzdFJlbW92ZWRYaWQgPSBjdXRvZmZfeGlkOworCisJCVRyYW5zYWN0aW9uSWRSZXRyZWF0 KGxhdGVzdFJlbW92ZWRYaWQpOwogCiAJCVhMb2dSZWNHZXRCbG9ja1RhZyhyZWNvcmQsIDAs ICZybm9kZSwgTlVMTCwgTlVMTCk7Ci0JCVJlc29sdmVSZWNvdmVyeUNvbmZsaWN0V2l0aFNu YXBzaG90KGN1dG9mZl94aWQsIHJub2RlKTsKKwkJUmVzb2x2ZVJlY292ZXJ5Q29uZmxpY3RX aXRoU25hcHNob3QobGF0ZXN0UmVtb3ZlZFhpZCwgcm5vZGUpOwogCX0KIAogCWlmIChYTG9n UmVhZEJ1ZmZlckZvclJlZG8ocmVjb3JkLCAwLCAmYnVmZmVyKSA9PSBCTEtfTkVFRFNfUkVE TykK --------------010305080207070209060305-- --C2WH7ErH61dAGiQuNTINVchafODPOqgEE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJVjViyAAoJEFifA/AbpVA43b0P/1LuJ3Jzb+WOw6HSMfoSCIb6 cdo3gVhhhKlbJSYJ9ShBHfZOw2h6TMovv0Liewiefak2cu5S0dTj3mOL82qlq/d4 +MJ92FRE/OSnEp3wFu66Crfj5phezx43CVuKddHx8KExLV+6cEFLzV1uxfl3+uEd LIUCPA2KJRXuo4JJtvvYV51qne5QCTP0QwHQEwV414X+Dh//zrAn0XJmkV8mSgok sAZPL6rkJyRVxNH9CyghyLuMffr4ANBcRti93PCTqt3MQP4pNt6zGALH1gWBQbNl ikQdJIdBCLhtQsxN82rfTKYCeV+K2o22A33MP3B+ejb8jTLEWZOQUbb6ixH3VGmM mzWi/KbSEevwiMZJDh3mUwZP/XOrn/sLm+I4cgKmZjHe69u0UluT9HoNB1kYn/35 DgrTTq0yStdMis/EtvPGvWVV9JuKIOtr4ffjeBy5AGu4fsVfGsl9Uai9ekvIdw1b RhWmQ88s2DEJy9qpps+lsThLCLg0VuaaUKsfFWoqFP66OcyOsg/Hx8KRV+S+R28i 0iXD3pb7KQeghoQRLrVirKCVXcxEu8bw0NkA+fWMSfO03Y8ZZG9QLnnfeIAW24Aq 9T2AkIio8vj9S2s4rwHa5kwLZRJGKelYjRHzaJwH8Tfjf279AVJkq66ErhDDyzD1 iI+UQ67oDJGW6bjklISl =BfAs -----END PGP SIGNATURE----- --C2WH7ErH61dAGiQuNTINVchafODPOqgEE--