Re: Question about the isolation level and visible

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: 娄帅 <louis(dot)hust(dot)ml(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question about the isolation level and visible
Date: 2015-06-26 19:26:35
Message-ID: 1281996184.582805.1435346795596.JavaMail.yahoo@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

娄帅 <louis(dot)hust(dot)ml(at)gmail(dot)com> wrote:

> I start two session with the following execute time order:
>
> session1: START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
>
> session2: INSERT INTO t1 values(1);
> session2: COMMIT;
>
> session1: SELECT * FROM t1;
>
> I found session1 got the value 1 which is inserted by session2.
>
> Is there any way to make session1 not see the value session2
> inserted?

This was recently clarified in the documentation by changing:

| [...] as of the start of the transaction, [...]

to:

| [...] as of the start of the first non-transaction-control
| statement in the transaction, [...]

We don't acquire the snapshot at START TRANSACTION time because it
may be necessary to acquire locks or set transaction properties
(e.g., READ ONLY) before the snapshot is acquired. You could force
acquisition of a snapshot by running a short query (e.g., SELECT
1;) in session 1 before starting the transaction in session 2.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2015-06-26 19:31:21 Re: Foreign data wrappers and indexes on remote side
Previous Message Tim Smith 2015-06-26 19:09:33 Re: Functions, savepoints, autocommit = I am confused !