pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Sebastien Flaesch <sebastien.flaesch@4js.com>
To: Kirk Wolak <wolakk@gmail.com>
Cc: Geoff Winkless <pgsqladmin@geoff.dj>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Using CTID system column as a "temporary" primary key
Date: Wed, 29 Mar 2023 17:53:08 +0200
Message-ID: <f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.camel@cybertec.at> (raw)
In-Reply-To: <DBAP191MB128988C5A20F0A8714111FA6B0899@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
References: <DBAP191MB12891F47802C3674F77BF751B0889@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
	<CAEzk6feEGHzS_TexvevFmWhsYt7MYhUUEUE54stO7SPNbL_Ypg@mail.gmail.com>
	<DBAP191MB1289536BFF22FD8BD5FFEC61B0889@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>
	<CACLU5mQ2XMd5c4tetUHacVE538c8nd1t2CWSfDvis2GCKg0L9A@mail.gmail.com>
	<be2240923b8017b0c03f980772cdd6ef0678200a.camel@cybertec.at>
	<DBAP191MB128988C5A20F0A8714111FA6B0899@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM>

On Wed, 2023-03-29 at 14:23 +0000, Sebastien Flaesch wrote:
> From: Laurenz Albe <laurenz.albe@cybertec.at>
> > It is safe to assume that the CTID is stable within a single transaction
> > only if you use REPEATABLE READ or better transaction isolation level.
> >
> > With READ COMMITTED, you see updated rows (and consequently changed CTID)
> > within a single transaction.  And if you use SELECT ... FOR UPDATE, you
> > could even see a changed CTID within a single statement.
> >
> > So don't use CTID to identify rows unless you use REPEATABLE READ or better.
>
> Thanks for the advice about REPEATABLE READ isolation level!


... but that is only useful in a read-only scenario.

If you try to UPDATE the row in a REPEATABLE READ transaction, you
will get a serialization error if there was a concurrent update.

In short: don't use the CTID to identify a row.

Yours,
Laurenz Albe





view thread (28+ messages)  latest in thread

Message-ID: <f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.camel@cybertec.at>
Permalink:  ../f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.camel@cybertec.at/
Also on:    postgresql.org/message-id/f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.camel@cybertec.at

 · 

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-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, sebastien.flaesch@4js.com, wolakk@gmail.com, pgsqladmin@geoff.dj
  Subject: Re: Using CTID system column as a "temporary" primary key
  In-Reply-To: <f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.camel@cybertec.at>
  References: <DBAP191MB12891F47802C3674F77BF751B0889@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <CAEzk6feEGHzS_TexvevFmWhsYt7MYhUUEUE54stO7SPNbL_Ypg@mail.gmail.com> <DBAP191MB1289536BFF22FD8BD5FFEC61B0889@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <CACLU5mQ2XMd5c4tetUHacVE538c8nd1t2CWSfDvis2GCKg0L9A@mail.gmail.com> <be2240923b8017b0c03f980772cdd6ef0678200a.camel@cybertec.at> <DBAP191MB128988C5A20F0A8714111FA6B0899@DBAP191MB1289.EURP191.PROD.OUTLOOK.COM> <f85a1d70ee8f9df8ec7be46cec623f11b43e4fb4.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