Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZjVt0-0001ww-5p for pgsql-general@arkaria.postgresql.org; Tue, 06 Oct 2015 17:18:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZjVsz-0000Xd-Nw for pgsql-general@arkaria.postgresql.org; Tue, 06 Oct 2015 17:18:45 +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 1ZjVsy-0000VM-On for pgsql-general@postgresql.org; Tue, 06 Oct 2015 17:18:44 +0000 Received: from mail1.openerp.com ([46.105.124.125]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZjVsv-0001R4-6U for pgsql-general@postgresql.org; Tue, 06 Oct 2015 17:18:43 +0000 Received: by mail1.openerp.com (Postfix, from userid 10002) id 195F7BF5B3; Tue, 6 Oct 2015 19:18:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.openerp.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [10.10.23.17] (host-109-89-171-142.dynamic.voo.be [109.89.171.142]) (Authenticated sender: odo@mail1.openerp.com) by mail1.openerp.com (Postfix) with ESMTPSA id 738E5BF40D; Tue, 6 Oct 2015 19:18:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=odoo.com; s=mail; t=1444151917; bh=xbMw3vY8UkjWfwOV7PSb8EfxB7nAHf054yVQWKZgkz4=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From; b=n1Ix/B3a05+SLt6gy2CiLEGFHh89yfQQBbrn6L/9cg8EFjvdZq87aajnMXTwO9JCc 3nPyRq346qiOHZUJWjkJ2O7MqtMH3H4MkzzUmu4pyxrnlrzA4/4/0encmGk/NbXogA 6KoKkgSri5QUOHtzIJMBHGk1z9b09LB7USlRhUPA= Subject: Re: Serialization errors despite KEY SHARE/NO KEY UPDATE To: Kevin Grittner , Jim Nasby References: <560ED745.3050009@BlueTreble.com> <1354271993.744124.1444079872314.JavaMail.yahoo@mail.yahoo.com> Cc: "pgsql-general@postgresql.org" From: Olivier Dony Message-ID: <5614026C.10404@odoo.com> Date: Tue, 6 Oct 2015 19:18:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <1354271993.744124.1444079872314.JavaMail.yahoo@mail.yahoo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 10/05/2015 11:17 PM, Kevin Grittner wrote: > Jim Nasby wrote: >> On 10/2/15 11:44 AM, Olivier Dony wrote: >>> On 10/02/2015 12:28 AM, Jim Nasby wrote: >>>> On 9/29/15 9:47 AM, Olivier Dony wrote: > >>>>> -- Setup tables >>>>> CREATE TABLE users ( id serial PRIMARY KEY, >>>>> name varchar, >>>>> date timestamp ); >>>>> CREATE TABLE orders ( id serial PRIMARY KEY, >>>>> name varchar, >>>>> user_id int REFERENCES users (id) ); >>>>> INSERT INTO users (id, name) VALUES (1, 'foo'); >>>>> INSERT INTO orders (id, name) VALUES (1, 'order 1'); >>>>> >>>>> >>>>> -- Run 2 concurrent transactions: T1 and T2 >>>>> T1 T2 >>>>> |-----------------------------|----------------------------------| >>>>> BEGIN ISOLATION LEVEL >>>>> REPEATABLE READ; >>>>> >>>>> UPDATE orders >>>>> SET name = 'order of foo', >>>>> user_id = 1 >>>>> WHERE id = 1; >>>>> >>>>> BEGIN ISOLATION LEVEL >>>>> REPEATABLE READ; >>>>> >>>>> UPDATE users >>>>> SET date = now() >>>>> WHERE id = 1; >>>>> >>>>> COMMIT; >>>>> >>>>> UPDATE orders >>>>> SET name = 'order of foo (2)', >>>>> user_id = 1 >>>>> WHERE id = 1; >>>>> >>>>> T1 fails with: >>>>> ERROR: could not serialize access due to concurrent update >>>>> CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."users" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x" >>>> >>>> This isn't a locking failure, it's a serialization failure. I'm not sure >>>> why it's happening though... is there an index on date? >>> >>> I don't think so. I can reproduce the problem with the queries quoted >>> above, and the only index that seems to be present is the PK > >> I'm not sure. Perhaps Kevin Grittner (author of serializable patch) can >> shed some light. > > This has nothing to do with the serializable patch[1], but it is > related to the new multixact code in 9.3. I thought I remembered > that this was a regression from 9.2 behavior which was fixed in a > patch after being reported, and sure enough tests of the tips of > branches showed that prior to 9.3 T2 blocked until T1 committed, > rather than generating a serialization failure, while on 9.5 and > master there was no blocking or error. > > Using `git bisect` to see where this was fixed shows: > > commit 05315498012530d44cd89a209242a243374e274d > Author: Alvaro Herrera > Date: Tue Jul 29 15:41:06 2014 -0400 > > Avoid uselessly looking up old LOCK_ONLY multixacts > > Commit 0ac5ad5134f2 removed an optimization in multixact.c that skipped > fetching members of MultiXactId that were older than our > OldestVisibleMXactId value. The reason this was removed is that it is > possible for multixacts that contain updates to be older than that > value. However, if the caller is certain that the multi does not > contain an update (because the infomask bits say so), it can pass this > info down to GetMultiXactIdMembers, enabling it to use the old > optimization. > > Pointed out by Andres Freund in 20131121200517.GM7240@alap2.anarazel.de That's exactly it, thanks a lot for tracking down the root cause! I understand (a little bit) better now. > I don't know whether, after being in 9.5 for over a year it could > be considered for a back-patch to 9.3 and 9.4; I leave that to > Álvaro and others who have been repairing the multixact problems to > determine. From what I understand of the original discussion between Andres, Álvaro and Tom, a back-patch seemed desirable because this issue has performance consequences. I have to add that in our case it also causes spurious serialization failures that were not present in 9.2 and aren't either in 9.5. The backwards-compatibility problem of the patch might however apply to both 9.3 and 9.4 now... For what it's worth, our system uses many long-running transactions (background jobs, batch data imports, etc.) that are frequently interrupted and rolled back by micro-transactions coming from users who just happen to update minor data on their records (such as their last login date). Having to replay those long transactions is particularly expensive and they stand a good chance of being interrupted again during the replay, etc. We would happily skip the micro-transactions (as a perf workaround) if there was a way to detect this situation, but we couldn't find a way to do that in 9.3. <9.3 we used SELECT FOR UPDATE NOWAIT to guard similar cases. If there is any way I could help to make the back-patch happen, please let me know! -- Olivier > > [1] The serializable patch has no effect if there are not > serializable transactions in use, and it doesn't generate errors > "due to concurrent update" in any new situations. > -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general