Re: lifetime of the old CTID - Mailing list pgsql-general

From Christophe Pettus
Subject Re: lifetime of the old CTID
Date
Msg-id 9B418AE6-EA48-4493-B1D1-566708ADC9AC@thebuild.com
Whole thread Raw
In response to Re: lifetime of the old CTID  (Matthias Apitz <guru@unixarea.de>)
Responses Re: lifetime of the old CTID
Re: lifetime of the old CTID
List pgsql-general

> On Jul 5, 2022, at 22:35, Matthias Apitz <guru@unixarea.de> wrote:
> Internally, in the DB layer, the read_where() builds the row list matching
> the WHERE clause as a SCROLLED CURSOR of
>
>    SELECT ctid, * FROM d01buch WHERE ...
>
> and each fetch() delivers the next row from this cursor. The functions
> start_transaction() and end_transaction() do what their names suggest and
> rewrite_actual_row() does a new SELECT based on the ctid of the actual row
>
>    SELECT * FROM d01buch WHERE ctid = ... FOR UPDATE
>    ...
>    UPDATE ...

On first glance, it appears that you are using the ctid as a primary key for a row, and that's highly not-recommended.
Thectid is never intended to be stable in the database, as you have discovered.  There are really no particular
guaranteesabout ctid values being retained. 

I'd suggest having a proper primary key column on the table, and using that instead.


pgsql-general by date:

Previous
From: Matthias Apitz
Date:
Subject: Re: lifetime of the old CTID
Next
From: Andreas Kretschmer
Date:
Subject: Re: lifetime of the old CTID