Re: lifetime of the old CTID

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Matthias Apitz <guru(at)unixarea(dot)de>
Cc: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: lifetime of the old CTID
Date: 2022-07-06 12:32:48
Message-ID: 20220706123248.6uy4sgf3owl64kbr@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2022-Jul-06, Matthias Apitz wrote:

> This gives in the DB layer a CURSOR of say 100.000 rows of the
> 3.000.000 in the table. Now the application fetches row by row and see
> if something should be done with the row. If so, the DB layer must
> LOCK the row for update. It does so using the CTID.

This is a bad idea, for reasons already explained. The CTID is not for
user consumption. If it breaks, as it does for you here, it's your
fault for using it. Your rows need to have a key that you can use. The
CTID is not it.

> Of course there is a key in the row (d01gsi, the signature of the
> book), but this is not uniqu and can't be used to lock exactly this
> row for update.

Well, you need something. It is beginning to sound like your database
model is wrong, because it lacks sufficient keys.

> Interestingly, I tested today morning how long the new CTID can be
> seen with currtid2(). I did 10 or more updates of a row and the then
> new CTID could always be seen with the old CTID from the moment before
> the 10 updates. I even found no way to get this tuple broken. Only
> deletion of the row helped to make currtid2() loosing the relation.
> This is with a 14.1 server. Why the 13.1 behaves different?

There are implementation details that you shouldn't concern yourself
with. Quite likely, the reason it stayed unchanged has nothing to do
with the server version, and is instead related to other things
happening in the server at the same time.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"I suspect most samba developers are already technically insane...
Of course, since many of them are Australians, you can't tell." (L. Torvalds)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2022-07-06 13:53:54 Re: lifetime of the old CTID
Previous Message Matthias Apitz 2022-07-06 12:26:00 Re: lifetime of the old CTID