Thank you for the clarification, Laurenz.

That makes sense regarding the logical content and locking behavior. I
appreciate the insight.

Agreed on the locks, but I have a slight concern: we changed the completed
underlying file (actually rewriting the table),
while the transaction mode is READ ONLY.

My actual question is: how does a READ ONLY TRANSACTION rewrite the
complete table?

Shouldn't we restrict this activity during READ ONLY TRANSACTION?


On Tue, Nov 24, 2026 at 7:58 PM Laurenz Albe <[email protected]>
wrote:

> On Tue, 2026-11-24 at 13:48 +0530, dinesh kumar wrote:
> > On PostgreSQL 19.0, REPACK runs inside a READ ONLY transaction:
> >
> >   SELECT pg_relation_filenode('t');   -- 25599
> >
> >   START TRANSACTION READ ONLY;
> >   INSERT INTO t VALUES (0, 'x');
> >   ERROR:  cannot execute INSERT in a read-only transaction
> >   ROLLBACK;
> >
> >   START TRANSACTION READ ONLY;
> >   REPACK t;                           -- succeeds, AccessExclusiveLock
> >   COMMIT;
> >
> >   SELECT pg_relation_filenode('t');   -- 25607
> >
> >
> > I have a slight concern here, as the READ ONLY transaction is often
> considered safe on a
> > production server, and this one takes an exclusive lock. Would anyone
> suggest if we are missing anything here, please?..
>
> REPACK doesn't change the logical contents of the table.
>
> Since you are concerned about locking:
>
>   LOCK TABLE t IN ACCESS EXCLUSIVE MODE;
>
> also works in read-only transactions.
>
> I wouldn't consider a read-only transaction "safe" in the sense that it
> cannot
> cause any problems on the server.
>
> Yours,
> Laurenz Albe
>


-- 

Regards,
Dinesh
pgSherpa - https://cortexridge.com/

Reply via email to