Re: How do concurrent inserts work?

From: Serge Fonville <serge(dot)fonville(at)gmail(dot)com>
To: Yaroslav <ladayaroslav(at)yandex(dot)ru>
Cc: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: How do concurrent inserts work?
Date: 2014-12-27 11:08:06
Message-ID: CAOAS_+LEe9dxq=vCf_oOBTrB10b-YurxT9WmLD0ocwFD0ajkOA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

Perhaps because your second session doesn't specify an isolation level?

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

2014-12-27 11:11 GMT+01:00 Yaroslav <ladayaroslav(at)yandex(dot)ru>:

> Hi. After reading this:
>
>
> http://postgresql.nabble.com/Re-BUG-12330-ACID-is-broken-for-unique-constraints-td5832085.html
>
> I've come to conclusion that I don't understand PostgreSQL transaction
> isolation. :(
>
> Here's the example:
> > CREATE TABLE t(a INT PRIMARY KEY);
> > INSERT INTO t VALUES(1);
>
> -- Test number 1:
> > START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> > SAVEPOINT a;
> > INSERT INTO t VALUES(1);
> -- This results in 'duplicate key' error, so I reason there is a row with
> this value, check it:
> > ROLLBACK TO SAVEPOINT a;
> > SELECT * FROM t WHERE a = 1;
> 1 -- 1 row. So yes, there is such row.
> > COMMIT; -- done with this test
>
>
> -- Test number 2:
> > START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> > SELECT * FROM t WHERE a = 1;
> 1 -- 1 row
> > SAVEPOINT a;
>
> In other session> INSERT INTO t VALUES(2);
> -- Back to my session:
> > INSERT INTO t VALUES(2);
> -- This results in 'duplicate key' error, so I reason there is a row with
> this value, check it:
> > ROLLBACK TO SAVEPOINT a;
> > SELECT * FROM t WHERE a = 2;
> -- 0 rows
> -- So, I reason... Stop, what? Error told me that there IS such row, but
> now
> I see there ISN'T?!
>
> Can you enlighten me?
>
>
>
>
> -----
> WBR, Yaroslav Schekin.
> --
> View this message in context:
> http://postgresql.nabble.com/How-do-concurrent-inserts-work-tp5832157.html
> Sent from the PostgreSQL - novice mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Yaroslav 2014-12-27 11:54:47 Re: How do concurrent inserts work?
Previous Message Yaroslav 2014-12-27 10:11:15 How do concurrent inserts work?