Re: Adding REPACK [concurrently]

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Antonin Houska <ah(at)cybertec(dot)at>, Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>
Cc: alvherre(at)alvh(dot)no-ip(dot)org, Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Robert Treat <rob(at)xzilla(dot)net>
Subject: Re: Adding REPACK [concurrently]
Date: 2026-03-23 16:07:24
Message-ID: 713021dd-bf6c-407a-8c9d-f79ecbd1c2ee@uni-muenster.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

while reviewing another patch I noticed that REPACK is trying to access
temp tables from other sessions.

== session 1 ==

$ psql postgres
psql (19devel)
Type "help" for help.

postgres=# SELECT pg_backend_pid();
pg_backend_pid
----------------
730392
(1 row)

postgres=# CREATE TEMP TABLE tmp AS SELECT generate_series(1, 1000) AS id;
SELECT 1000
postgres=# BEGIN;
LOCK TABLE tmp IN SHARE MODE;
BEGIN
LOCK TABLE
postgres=*#

== session 2 ==

$ psql postgres
psql (19devel)
Type "help" for help.

postgres=# REPACK;
(waits for LOCK)

== session 3 ==

$ psql postgres
psql (19devel)
Type "help" for help.

postgres=# SELECT pid, relation::regclass, mode, granted
FROM pg_locks
WHERE relation::regclass::text ~~ '%.tmp%';
pid | relation | mode | granted
--------+----------------+---------------------+---------
730608 | pg_temp_12.tmp | AccessExclusiveLock | f
730392 | pg_temp_12.tmp | ShareLock | t
(2 rows)

The same applies for REPACK USING INDEX if indisclustered is true.

I played a bit with the code and perhaps skipping temp relations in
get_tables_to_repack() before they're added to the list can do the
trick. I tried the draft attached and REPACK could run despite the LOCK
in the other session... in case it helps.

Best, Jim

Attachment Content-Type Size
nocfbot-0001-Fix-REPACK-to-skip-temporary-tables-of-other-sess.patch text/x-patch 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2026-03-23 16:14:19 Re: DOCS - System Applications 'datadir' parameter
Previous Message Bharath Rupireddy 2026-03-23 16:00:00 Re: Introduce XID age based replication slot invalidation