pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: github@henricook.com
Subject: BUG #15875: Unexpected serializable isolation error when INSERTing into a table
Date: Wed, 26 Jun 2019 10:04:35 +0000
Message-ID: <15875-76bf5472863f6ce3@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15875
Logged by:          Henri Cook
Email address:      github@henricook.com
PostgreSQL version: 10.6
Operating system:   docker image, postgres:10.6
Description:        

Hi all,

When running the SQL below we get a serialisation error at the end of
Transaction 2. Because of the presence of the primary key PG isn't doing a
seq scan to perform the selects and manual inspection of pg_locks would seem
to imply it's not a page lock issue either. Can anyone shed some light on
why this query causes an isolation issue? The exact isolation error is:

```
ERROR:  could not serialize access due to read/write dependencies among
transactions
DETAIL:  Reason code: Canceled on identification as a pivot, during write.
HINT:  The transaction might succeed if retried.
```

Obviously in this case a retry will probably succeed, as per the docs - but
i'm not sure it should be necessary?

Thanks in advance for your attention

Henri


Steps to recreate:

```
DROP TABLE IF EXISTS foo;
CREATE TABLE foo(id int PRIMARY KEY);
INSERT INTO foo (id) VALUES (44);
INSERT INTO foo (id) VALUES (33);
```
-- Transaction 1:
    ```
    BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
    SELECT id FROM foo WHERE id = 44;
    ```
-- Transaction 2:
    ```
    BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
    SELECT id FROM foo WHERE id = 33;
    INSERT INTO foo (id) VALUES (1);
    COMMIT;
    ```

-- Transaction 1:
   ```
    INSERT INTO foo (id) VALUES (2);
     <observe serialisation error>
   ```



view thread (4+ messages)  latest in thread

Message-ID: <15875-76bf5472863f6ce3@postgresql.org>
Permalink:  ../15875-76bf5472863f6ce3@postgresql.org/
Also on:    postgresql.org/message-id/15875-76bf5472863f6ce3@postgresql.org

 · 

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: noreply@postgresql.org, github@henricook.com
  Subject: Re: BUG #15875: Unexpected serializable isolation error when INSERTing into a table
  In-Reply-To: <15875-76bf5472863f6ce3@postgresql.org>
  References: <15875-76bf5472863f6ce3@postgresql.org>

* 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