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