BUG #15875: Unexpected serializable isolation error when INSERTing into a table

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: github(at)henricook(dot)com
Subject: BUG #15875: Unexpected serializable isolation error when INSERTing into a table
Date: 2019-06-26 10:04:35
Message-ID: 15875-76bf5472863f6ce3@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 15875
Logged by: Henri Cook
Email address: github(at)henricook(dot)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>
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Munro 2019-06-26 10:33:48 Re: BUG #15875: Unexpected serializable isolation error when INSERTing into a table
Previous Message Thomas Kellerer 2019-06-26 05:53:08 Re: BUG #15874: How to Install Plug-ins on Windows System