agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't lock tables in get_tables_to_repack()
Date: Fri, 10 Jul 2026 14:11:22 +0000
Message-ID: <E1wiBwn-000SOP-39@gemulon.postgresql.org> (raw)
Don't lock tables in get_tables_to_repack()
When doing a whole database repack, we build a list of tables to process
taking a lock on each. But because it's a regular transaction-scoped
lock, it's automatically released immediately after building the list
anyway, which makes it not very useful. (Also, we have three ways to
obtain a list of tables to repack, and only one of them acquired this
lock.) Remove that lock acquisition, as it's useless and inconsistent.
We acquire a lock properly afterwards (and recheck that the table can
still be repacked as indicated), so we don't need to do anything other
than drop that initial lock acquisition and harden the code in
repack_is_permitted_for_relation() against possible concurrent drops.
This is similar to how vacuum does it in get_all_vacuum_rels().
In order for this to work reliably, also change
repack_is_permitted_for_relation() to cope with the possibility of the
table going away partway through. Similarly, in ExecRepack(), be
prepared for what we believed to be a table or matview to now be
something else, and skip it without erroring out, by changing
try_table_open() to try_relation_open() and testing the relkind
separately.
While at it, replace one relation_close() call in get_tables_to_repack()
with table_close() to match the table_open() that opened the catalog.
Author: ChangAo Chen <cca5507@qq.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/tencent_9F290B256A3F52B66542F1140E32ECC64309@qq.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c71d43025d7aaf12fe461ec635bd2eda220c9f4a
Modified Files
--------------
src/backend/commands/repack.c | 117 +++++++++++++++++++-----------------------
1 file changed, 54 insertions(+), 63 deletions(-)
view thread (2+ messages) latest in thread
Message-ID: <E1wiBwn-000SOP-39@gemulon.postgresql.org>
Permalink: ../E1wiBwn-000SOP-39@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wiBwn-000SOP-39@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Don't lock tables in get_tables_to_repack()
In-Reply-To: <E1wiBwn-000SOP-39@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox