Re: REPACK (CONCURRENTLY) can silently lose updates when the toast table is rewritten

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Manu <manuelreyesbravo(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: REPACK (CONCURRENTLY) can silently lose updates when the toast table is rewritten
Date: 2026-09-23 12:08:31
Message-ID: CAGRkXqQu=9iPLAnykmKa1TJcvuT0fipHpAwL+nNLEcP=PdMbug@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> + UnlockRelationOid(toastrelid, ShareUpdateExclusiveLock);
> + stop_repack_decoding_worker();
>
> Is there any opportunity for another rewrite to sneak in between these
two?

Yes, but it doesn't matter. The old worker is thrown away and nothing has
been copied yet. The new worker reads the relfilenode itself when it
starts, so a rewrite before that is simply what it sees. A rewrite after
that is caught by the next check, which is made under the lock again.

The unlock has to come before starting the new worker anyway, or we
are back to the deadlock.

Thanks,
Shihao

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-09-23 12:17:50 Re: aio: worker: Free SMGR objects when idle
Previous Message Nazir Bilal Yavuz 2026-09-23 11:35:01 Re: aio: worker: Free SMGR objects when idle