Re: Adding REPACK [concurrently] - Mailing list pgsql-hackers

From Jim Jones
Subject Re: Adding REPACK [concurrently]
Date
Msg-id 713021dd-bf6c-407a-8c9d-f79ecbd1c2ee@uni-muenster.de
Whole thread Raw
In response to Re: Adding REPACK [concurrently]  (Antonin Houska <ah@cybertec.at>)
Responses Re: Adding REPACK [concurrently]
List 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

pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Introduce XID age based replication slot invalidation
Next
From: Bruce Momjian
Date:
Subject: Re: DOCS - System Applications 'datadir' parameter