Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZjZwN-0006XN-OM for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Oct 2015 21:38:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZjZwM-0000CS-M2 for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Oct 2015 21:38:30 +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) (envelope-from ) id 1ZjZwK-0000C7-RX for pgsql-bugs@postgresql.org; Tue, 06 Oct 2015 21:38:29 +0000 Received: from nm2-vm2.bullet.mail.gq1.yahoo.com ([98.136.218.129]) by magus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZjZwB-0007mk-On for pgsql-bugs@postgresql.org; Tue, 06 Oct 2015 21:38:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1444167496; bh=FrCO21K9THvsxphGmZKc7HDEeRQjiZhGiOx2EgFP0xI=; h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject; b=g6cvr4wtRbrTPjk12o6I8Rh20W82az8u2CfS6IBC6kwGKhJjrOIrfbp+DvKXONXD4F1tm5LX36ikOrJkI4sKafsPMZQ3bXkA0wvnPUcJ+cEmz2d3LGYejDLtleMZdaODYDfQTG3YmM0PM7dJXrPgYuWYi1xvk4wZHB+gCA1BcKuiBLA5zFHfMaiuTezK6ZJEf1uK5TRrL4Ou50omYon9S4RJ+d2IkoR8wFEHps3YWGo21mH+uWongW3P8kiPeaELCoeuMegoUipO5hBGbZDsy5mbYiaJTYeNkq1whWxIelN0wIUGExITS+WpqsESh37K0yR/aAaSyyZBtM1nPGr3HA== Received: from [98.137.12.174] by nm2.bullet.mail.gq1.yahoo.com with NNFMP; 06 Oct 2015 21:38:16 -0000 Received: from [98.137.12.226] by tm13.bullet.mail.gq1.yahoo.com with NNFMP; 06 Oct 2015 21:38:16 -0000 Received: from [127.0.0.1] by omp1034.mail.gq1.yahoo.com with NNFMP; 06 Oct 2015 21:38:16 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 564878.85145.bm@omp1034.mail.gq1.yahoo.com X-YMail-OSG: 4KGJIQoVM1kBqw8PYnHa4f18oXGYPXJLlbCYVqNE6XR.HEHQKpxPqLPqQ4OyAbi ulf0EfOGtzxmbjeZ2RPohRWcL_KLS9_KNH7_kC6AkHFkPt4fi3i3ZHb2po6ePWmhWk7tqwJXfiuZ 40_6oha_eXCdLgOik9KjdnSlFHY8QA9CqsmOhewtCnz.4VZXXTTEU0PkzELYv3ElFinnOSoglFrb Uv1cgAD.1FGrE5zGSBY2SQ1AntJHE0K4XZJnNT.gYhQ7rc1IgRLjXjwRFQRf5jRT4XGrJl4PLEC1 q32H1HwFlvRqk6Ha3HRk8_7NnYSKklxC53h_ncz.E4E8QgviPQIyJq9phImBdPOp0PmzFxxXZm4K nmWeKHlA8g8v1zuBd5Ai97XqDG_mwYiJpBAsqj4IzYULT5d6Ng9b_f.P6Fvp1Ifz9iSPfx1DvNJk JZ1P.ziijUNcl61fPLpZSozexyWixgAuMk7fUmz_dc57LNut80sNnhX11KbL6nUNuiSMrBXDfUSu iAs8eZV6R1fXOtVKZ4.zbN1.N Received: by 216.39.60.155; Tue, 06 Oct 2015 21:38:16 +0000 Date: Tue, 6 Oct 2015 21:38:15 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: "cpacejo@clearskydata.com" , "pgsql-bugs@postgresql.org" Message-ID: <1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <20151001185144.335.99956@wrigleys.postgresql.org> References: <20151001185144.335.99956@wrigleys.postgresql.org> Subject: Re: BUG #13660: serializable snapshotting hangs MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1267647_1963795160.1444167495617" Content-Length: 9916 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 ------=_Part_1267647_1963795160.1444167495617 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thursday, October 1, 2015 9:19 PM, "cpacejo@clearskydata.com" wrote: > PostgreSQL version: 9.4.4 > After running fine for weeks, we now find that serializable snapshots han= g: > > our_db=3D> START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY, DEF= ERRABLE; > START TRANSACTION > our_db=3D> SELECT pg_export_snapshot(); > (...hangs indefinitely...) > Killing all backends (i.e. including those accessing other databases) > unblocked serializable snapshotting. > > Is this expected behavior? What should be happening is that when the serializable read only deferrable transaction executes the first statement that needs a snapshot, it grabs a snapshot and looks for concurrent read write transactions.=C2=A0 If there are none, the snapshot is safe and it goes ahead with execution; otherwise it goes into a loop where it delays (to avoid sucking 100% CPU for a core) by calling ProcWaitForSignal().=C2=A0 Each time that function returns it checks whether any of the concurrent read write transactions developed a read-write conflict out (i.e., it read data which was modified by a transaction concurrent to *it*) to a transaction which committed before this read only transaction got its snapshot.=C2=A0 If so, this snapshot is unsafe and we need to discard it, get a new snapshot, and go back into the loop.=C2=A0 If all read write transactions concurrent to the read only transaction complete without developing such a conflict our snapshot is safe and we can proceed to run without taking predicate locks or risking a serialization failure. Now, that's pretty technical, and you definitely don't need to follow all of the above to safely use deferrable transactions.=C2=A0 The short version is that your initial statement that needs a snapshot cannot begin to execute *at least* until any concurrent transactions which are not READ ONLY complete.=C2=A0 One connection stuck "idle in transaction" can hold it up indefinitely.=C2=A0 A prepared transaction also counts as a transaction which has not yet completed. So if you had any long-running READ WRITE transactions (including one stuck "idle in transaction" or prepared but not committed), it is expected behavior.=C2=A0 If not, we should try to gather more information to figure out what's going on. One other possibility is that your workload has changed such that there are now so many read write transactions reading data modified by other transactions that it is just not finding a safe snapshot very quickly.=C2=A0 Even when running benchmarks at saturation levels on a 16 core machine we rarely saw a delay more than six seconds, but there is no upper bound on how long it might take.=C2=A0 In such a case you would have a few options, but let's not get ahead of ourselves -- the first thing is to check for "idle in transaction" or prepared transaction issues. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company ------=_Part_1267647_1963795160.1444167495617 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thursday, October 1, 2015 9:19 PM, "cpacejo@clearskydata.c= om" <cpacejo@clearskydata.com> wrote:

> PostgreSQL version: 9.4.4

> After = running fine for weeks, we now find that serializable snapshots hang:
>
> our_db=3D> START TRANSACTION ISOLATI= ON LEVEL SERIALIZABLE, READ ONLY, DEFERRABLE;
> START TRANSACTION
> our_db=3D> SELECT pg_export_snapshot();> (...hangs indefinit= ely...)

> Killing all backends (i.e. inc= luding those accessing other databases)
> unblocked serializable snapshotting.
>
> Is this expected behavior?

What should be happening is that when the serializable read only<= br class=3D"" id=3D"yui_3_16_0_1_1444165651267_5764">deferrable transaction= executes the first statement that needs a
snapshot, it grabs a snapshot and looks for concurrent= read write
transactio= ns.  If there are none, the snapshot is safe and it goes
ahead with execution; otherwise it = goes into a loop where it delays
(to avoid sucking 100% CPU for a core) by calling
ProcWaitForSignal().  Each time= that function returns it checks
whether any of the concurrent read write transactions developed = a
read-write conflict = out (i.e., it read data which was modified by a
transaction concurrent to *it*) to a transaction = which committed
before= this read only transaction got its snapshot.  If so, this
snapshot is unsafe and we need to= discard it, get a new snapshot,
and go back into the loop.  If all read write transactions<= br class=3D"" id=3D"yui_3_16_0_1_1444165651267_5788">concurrent to the read= only transaction complete without developing
such a conflict our snapshot is safe and we can pro= ceed to run
without ta= king predicate locks or risking a serialization failure.

Now, that's pretty technical, and you definitely don't need= to
follow all of the = above to safely use deferrable transactions.  The
short version is that your initial stateme= nt that needs a snapshot
cannot begin to execute *at least* until any concurrent
transactions which are not READ ONLY c= omplete.  One connection
stuck "idle in transaction" can hold it up indefinitely.  Aprepared transaction als= o counts as a transaction which has not yet
completed.

So if you = had any long-running READ WRITE transactions (including
one stuck "idle in transaction" or prepar= ed but not committed), it
is expected behavior.  If not, we should try to gather more
information to figure out wh= at's going on.

One other possibility is tha= t your workload has changed such that
there are now so many read write transactions reading data = modified
by other tran= sactions that it is just not finding a safe snapshot
very quickly.  Even when running benchm= arks at saturation levels on
a 16 core machine we rarely saw a delay more than six seconds, butthere is no upper bound= on how long it might take.  In such a case
you would have a few options, but let's not get = ahead of ourselves
-- = the first thing is to check for "idle in transaction" or
prepared transaction issues.

--
Kevin Grittner
ED= B: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

------=_Part_1267647_1963795160.1444167495617--