From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Yorwerth, Adam <Adam.Yorwerth@tesco.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: Cianciaruso, Lorenzo <lorenzo.cianciaruso@tesco.com>
Subject: Re: BigSerial and txid issuance
Date: Thu, 09 Jul 2020 09:35:01 +0200
Message-ID: <47559cf2b1efa2904ea3d86749c3d87f1a3993c8.camel@cybertec.at> (raw)
In-Reply-To: <4478EF79-0699-4FBA-B7C1-95561EF1DB5E@tesco.com>
References: <4478EF79-0699-4FBA-B7C1-95561EF1DB5E@tesco.com>
On Wed, 2020-07-08 at 14:09 +0000, Yorwerth, Adam wrote:
> We’re trying to solve a problem that relies on BigSerial and txid (as returned by txid_current() ) values being issued consistently.
>
> Is it possible for two transactions to interleave their issuance of these two variables?
>
> For example:
>
> Schema:
>
> CREATE TABLE EXAMPLE(
> offset bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY NOT NULL,
> txid BIGINT NOT NULL DEFAULT 1
> );
>
> Insert statement:
>
> "INSERT INTO EVENTS (txid) VALUES (txid_current());";
>
> Prior to transactions executing offset is 10 and txid is 1000.
>
> Transaction 1 and 2 occur concurrently.
>
> Is it possible for transaction 1 to be issued txid 1001 and offset 12 and transaction 2 to be issued txid 1002 and offset 11?
Sure.
Transaction IDs are assigned when a transaction is about to modify data,
and for identity columns you get the next value when the backing sequence is called.
There is no guarantee that both have to happen in the same order?
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
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-general@postgresql.org
Cc: laurenz.albe@cybertec.at, Adam.Yorwerth@tesco.com, lorenzo.cianciaruso@tesco.com
Subject: Re: BigSerial and txid issuance
In-Reply-To: <47559cf2b1efa2904ea3d86749c3d87f1a3993c8.camel@cybertec.at>
References: <4478EF79-0699-4FBA-B7C1-95561EF1DB5E@tesco.com> <47559cf2b1efa2904ea3d86749c3d87f1a3993c8.camel@cybertec.at>
* 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