Skip to content

PG19: use ShareUpdateExclusiveLock for REPACK CONCURRENTLY - #8805

Draft
ibrahim halatci (ihalatci) wants to merge 1 commit into
mainfrom
ihalatci-pg19-repack-lock-fix
Draft

ibrahim halatci (ihalatci) wants to merge 1 commit into
mainfrom
ihalatci-pg19-repack-lock-fix

Conversation

@ihalatci

Copy link
Copy Markdown
Contributor

Draft fix for #8756.

This keeps Citus from taking AccessExclusiveLock before handing REPACK (CONCURRENTLY) to PostgreSQL. PostgreSQL uses ShareUpdateExclusiveLock for concurrent repack, and taking AEL in the Citus preprocessing path can block the repack worker even for local tables in a Citus database.

Stack: base PR.

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.77%. Comparing base (991faa8) to head (df2f245).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8805      +/-   ##
==========================================
- Coverage   88.77%   88.77%   -0.01%     
==========================================
  Files         290      290              
  Lines       65132    65133       +1     
  Branches     8223     8223              
==========================================
- Hits        57823    57822       -1     
+ Misses       4936     4935       -1     
- Partials     2373     2376       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ihalatci

Copy link
Copy Markdown
Contributor Author

Beta 4 disposition: retained and still relevant. Please rebase onto current main and refresh the PG19 lock-contention regression; this PR should remain independent of the closed eager-aggregation stack.

PreprocessClusterStmt resolved the target relation with
AccessExclusiveLock unconditionally.  That is correct for CLUSTER and
for plain REPACK, but PostgreSQL deliberately runs REPACK
(CONCURRENTLY) under ShareUpdateExclusiveLock (RepackLockLevel() in
repack.c).  Taking the stronger lock has two consequences:

  * On a distributed table, a session holding only AccessShareLock
    makes Citus block on AccessExclusiveLock, so the intended
    "CONCURRENTLY is unsupported" error is masked by a lock wait.

  * The lock is taken before the !IsCitusTable() early return and is
    held until end of transaction, so on a plain local table the
    repack decoding worker cannot lock the relation to export its
    logical snapshot and the command waits forever on
    RepackWorkerExport.

Resolve the relation with ShareUpdateExclusiveLock when CONCURRENTLY
is requested and keep AccessExclusiveLock for every other case, so
ordinary CLUSTER and REPACK locking is unchanged.

The unsupported-feature guard for distributed tables is retained; this
commit only stops it from being masked.

Add PG19-only regression coverage for both paths: a distributed table
whose rejection must not be masked by a concurrent reader, and a plain
local table whose REPACK (CONCURRENTLY) must complete.

Fixes #8756

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 61c1aeb4-1b56-4313-a35e-d65b59a557de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants