pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: cpacejo@clearskydata.com <cpacejo@clearskydata.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13660: serializable snapshotting hangs
Date: Tue, 6 Oct 2015 21:38:15 +0000 (UTC)
Message-ID: <1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <20151001185144.335.99956@wrigleys.postgresql.org>
References: <20151001185144.335.99956@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Thursday, October 1, 2015 9:19 PM, "cpacejo@clearskydata.com" <cpacejo@clearskydata.com> wrote:

> PostgreSQL version: 9.4.4

> After running fine for weeks, we now find that serializable snapshots hang:
>
> our_db=> START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ ONLY, DEFERRABLE;
> START TRANSACTION
> our_db=> 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.  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
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.  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.  One connection
stuck "idle in transaction" can hold it up indefinitely.  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.  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.  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.  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

view thread (9+ messages)  latest in thread

Message-ID: <1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com>
Permalink:  ../1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com/
Also on:    postgresql.org/message-id/1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kgrittn@ymail.com, cpacejo@clearskydata.com
  Subject: Re: BUG #13660: serializable snapshotting hangs
  In-Reply-To: <1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com>
  References: <20151001185144.335.99956@wrigleys.postgresql.org> <1379192640.1267648.1444167495623.JavaMail.yahoo@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox