Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Antonin Houska <ah@cybertec.at>
Дата:
Radim Marek wrote: > Hi Shihao, thank you for the confirmation. I wasn't aware of the enhancements series. > > It's definitely not a performance issue in the doc; rathe a resource limit. Since 19 will go with this limitation I attached a small doc patch > about this. Hope I got the use of 'other' correctly based on current version https://www.postgresql.org/docs/19/sql-repack.html It's unfortunate that REPACK is probably the only command that exercises this combo CID limit. However, there can be other limits, e.g. REPACK being unable to catch up if the change rate is too high, excessive usage of disk for the decoded changes, etc. I think that the most important thing for the user to know is that the purpose of REPACK is to improve performance (via bloat removal and/or clustering), whereas "failsafe VACUUM" (i.e. VACUUM with INDEX_CLEANUP set to off) should be used to avoid the risk of XID wraparound. This kind of VACCUM is probably much faster and less likely to fail. I don't have a good idea about the wording right now. -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
Hi Antonin,
> of REPACK is to improve performance (via bloat removal and/or clustering),
> whereas "failsafe VACUUM" (i.e. VACUUM with INDEX_CLEANUP set to off) should
> be used to avoid the risk of XID wraparound.
>
> I don't have a good idea about the wording right now.
Here is a try with Fable, as v2 of Radim's patch.
It adds a paragraph to Notes. REPACK is for bloat and clustering. For
wraparound uses VACUUM, because REPACK takes much longer and can fail
late.
Thanks,
Shihao
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
On 2026-Sep-27, shihao zhong wrote: > Here is a try with Fable, as v2 of Radim's patch. > > It adds a paragraph to Notes. REPACK is for bloat and clustering. For > wraparound uses VACUUM, because REPACK takes much longer and can fail > late. Yeah, that sounds appropriate. I think the original paragraph is worth rewriting more deeply though rather than just adding one more paragraph; I think some of the things it mentions are not so relevant from the user's POV, and also I think we can use some small changes elsewhere in the page. What do you think of the attached? I used -U7 in `git format-patch` so that the surrounding can be read directly from the patch. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Antonin Houska <ah@cybertec.at>
Дата:
Álvaro Herrera wrote: > On 2026-Sep-27, shihao zhong wrote: > > > Here is a try with Fable, as v2 of Radim's patch. > > > > It adds a paragraph to Notes. REPACK is for bloat and clustering. For > > wraparound uses VACUUM, because REPACK takes much longer and can fail > > late. > > Yeah, that sounds appropriate. > > I think the original paragraph is worth rewriting more deeply > though rather than just adding one more paragraph; I think some of the > things it mentions are not so relevant from the user's POV, and also I > think we can use some small changes elsewhere in the page. > > What do you think of the attached? I used -U7 in `git format-patch` so > that the surrounding can be read directly from the patch. I thought about this documentation update last week and wasn't sure it needs to be that exact about how much memory is consumed per changed tuple. I think we should rather encourage users to do monitoring in genaral: besides memory, the system can run out of disk space (REPACK w/o CONCURRENTLY also creates a copy of the table, but it's probably not used for big tables due to the stronger lock). Besides that, REPACK runs in a single transaction, so it might hold the xmin horizon(s) for too long (like any other long-running transactions). Finally, the processing of the concurrent changes might not be fast enough, in which case the AccessExclusiveLock may be needed for surprisingly long time. The paragraph about REPACK vs VACUUM LGTM. -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Oct-06, Antonin Houska wrote: > I thought about this documentation update last week and wasn't sure it needs > to be that exact about how much memory is consumed per changed tuple. True. I do want to clarify that the amount of memory used is not the size of the tuples, though. > I think > we should rather encourage users to do monitoring in genaral: besides memory, > the system can run out of disk space (REPACK w/o CONCURRENTLY also creates a > copy of the table, but it's probably not used for big tables due to the > stronger lock). Besides that, REPACK runs in a single transaction, so it might > hold the xmin horizon(s) for too long (like any other long-running > transactions). Finally, the processing of the concurrent changes might not be > fast enough, in which case the AccessExclusiveLock may be needed for > surprisingly long time. Hmm, I'll see what I can come up with. Note you say "it might hold the xmin horizon like any other long-running transactions", but that's not true for VACUUM, so I think it's worth pointing it out explicitly, since it's a clear disadvantage of REPACK. > The paragraph about REPACK vs VACUUM LGTM. Great, thanks for looking. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Tiene valor aquel que admite que es un cobarde" (Fernandel)
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
On 2026-Oct-06, Antonin Houska wrote: > I thought about this documentation update last week and wasn't sure it needs > to be that exact about how much memory is consumed per changed tuple. I think > we should rather encourage users to do monitoring in genaral: besides memory, > the system can run out of disk space (REPACK w/o CONCURRENTLY also creates a > copy of the table, but it's probably not used for big tables due to the > stronger lock). Besides that, REPACK runs in a single transaction, so it might > hold the xmin horizon(s) for too long (like any other long-running > transactions). Finally, the processing of the concurrent changes might not be > fast enough, in which case the AccessExclusiveLock may be needed for > surprisingly long time. I have revamped the reference page for REPACK rather heavily. What do you think of this? I attach the HTML for easy reading. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
Actually, after going over Thom Brown's report on MVCC unsafety, I looked again and decided to move the box and the list of restrictions for CONCURRENTLY to also appear in the "Notes on Concurrent Operation" subsection, instead of inside the "Parameters" section. So here it is again, both in patch form as well as HTML. Thanks -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "In Europe they call me Niklaus Wirth; in the US they call me Nickel's worth. That's because in Europe they call me by name, and in the US by value!"
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Antonin Houska <ah@cybertec.at>
Дата:
Alvaro Herrera wrote: > Actually, after going over Thom Brown's report on MVCC unsafety, I > looked again and decided to move the box and the list of > restrictions for CONCURRENTLY to also appear in the "Notes on Concurrent > Operation" subsection, instead of inside the "Parameters" section. > So here it is again, both in patch form as well as HTML. [ Thanks for the HTML. ] I suspect there's a thinko in the "Notes on Resources" section. Shouldn't the first paragraph start like this? "When the USING INDEX clause is given and an index scan is chosen, ..." No objections regarding the "Notes on Concurrent Operation" section. -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Oct-06, Antonin Houska wrote: > I suspect there's a thinko in the "Notes on Resources" section. Shouldn't the > first paragraph start like this? > > "When the USING INDEX clause is given and an index scan is chosen, ..." Hmm, no -- this paragraph tries to explain what happens when we use the unsorted option, _or_ we use the sorted option but we use a indexscan to implement it. So either the VACUUM FULL, or the indexscan based CLUSTER. In this case we only have one extra copy of the table. The second paragraph tries to describe what happens when we use a seqscan and sort -- that is, we have USING INDEX, but we don't scan using that index (that is, CLUSTER that uses a sort). That requires additional storage (the tuplestore that is sorted). Maybe we need to reword both so that this is more obvious? > No objections regarding the "Notes on Concurrent Operation" section. Thanks for reading! -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "I think my standards have lowered enough that now I think 'good design' is when the page doesn't irritate the living f*ck out of me." (JWZ)
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Radim Marek <radim@boringsql.com>
Дата:
Hey, what about wording
REPACK creates a temporary copy of the table and all of its indexes, so you need free disk space at least equal to the sum of the table size and the index sizes.
If clause `USING INDEX` is provided and the planner chooses a sequential scan and sort, a temporary sort file is also needed, so the maximum space requirement can reach twice the table size plus the index sizes. This method is usually faster than an index scan, but if disk space is tight, you might need to set `enable_sort` to `off` to force an index scan, or omit `USING INDEX` if the table does not need to be reordered.
If clause `USING INDEX` is provided and the planner chooses a sequential scan and sort, a temporary sort file is also needed, so the maximum space requirement can reach twice the table size plus the index sizes. This method is usually faster than an index scan, but if disk space is tight, you might need to set `enable_sort` to `off` to force an index scan, or omit `USING INDEX` if the table does not need to be reordered.
---
Radim
On Tue, 6 Oct 2026 at 22:05, Alvaro Herrera <alvherre@kurilemu.de> wrote:
On 2026-Oct-06, Antonin Houska wrote:
> I suspect there's a thinko in the "Notes on Resources" section. Shouldn't the
> first paragraph start like this?
>
> "When the USING INDEX clause is given and an index scan is chosen, ..."
Hmm, no -- this paragraph tries to explain what happens when we use the
unsorted option, _or_ we use the sorted option but we use a indexscan to
implement it. So either the VACUUM FULL, or the indexscan based
CLUSTER. In this case we only have one extra copy of the table.
The second paragraph tries to describe what happens when we use a
seqscan and sort -- that is, we have USING INDEX, but we don't scan
using that index (that is, CLUSTER that uses a sort). That requires
additional storage (the tuplestore that is sorted).
Maybe we need to reword both so that this is more obvious?
> No objections regarding the "Notes on Concurrent Operation" section.
Thanks for reading!
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"I think my standards have lowered enough that now I think 'good design'
is when the page doesn't irritate the living f*ck out of me." (JWZ)
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Antonin Houska <ah@cybertec.at>
Дата:
Alvaro Herrera wrote: > On 2026-Oct-06, Antonin Houska wrote: > > > I suspect there's a thinko in the "Notes on Resources" section. Shouldn't the > > first paragraph start like this? > > > > "When the USING INDEX clause is given and an index scan is chosen, ..." > > Hmm, no -- this paragraph tries to explain what happens when we use the > unsorted option, _or_ we use the sorted option but we use a indexscan to > implement it. So either the VACUUM FULL, or the indexscan based > CLUSTER. In this case we only have one extra copy of the table. ok. What I find disturbing in the first sentence is the "but" conjunction: "... that clause is given but an index scan is chosen ..." Shouldn't it rater be "and"? When I read "but", I usually expect a contradiction. However I see no contradiction between specifying the USING INDEX clause and choosing index scan. -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Oct-07, Antonin Houska wrote:
> ok. What I find disturbing in the first sentence is the "but" conjunction:
>
> "... that clause is given but an index scan is chosen ..."
>
> Shouldn't it rater be "and"?
>
> When I read "but", I usually expect a contradiction. However I see no
> contradiction between specifying the USING INDEX clause and choosing index
> scan.
You're right, that was pretty hard to read. How about this, following
Radim's suggestion?
REPACK creates a temporary copy of the table and all
of its indexes, so you need free disk space at least equal to the sum
of the table size and the index sizes.
If the USING INDEX clause is given and the planner
chooses a sequential scan and sort to implement it, a temporary sort
file that uses the table size again is needed in addition to the above.
This method is usually faster than an index scan, but if the disk space
requirement is intolerable, you can disable this choice by temporarily
setting to off; or
omitting USING INDEX if the table doesn't need to be
reordered.
The "... that uses the table size again is needed ..." bit looks
somewhat odd to me, but I don't know how to make it better.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
Are you not unsure you want to delete Firefox?
[Not unsure] [Not not unsure] [Cancel]
http://smylers.hates-software.com/2008/01/03/566e45b2.html
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Oct-07, Alvaro Herrera wrote:
> You're right, that was pretty hard to read. How about this, following
> Radim's suggestion?
I settled on this, which seems perfectly clear:
REPACK creates a temporary copy of the table and all
of its indexes, so you need free disk space at least equal to the sum
of the table size and the index sizes.
If the USING INDEX clause is given and the planner
chooses a sequential scan and sort to implement it, a temporary sort
file of up to the size of the table is needed in addition to the above.
This method is usually faster than an index scan, but if the disk space
requirement is intolerable, you can disable this choice by temporarily
setting to off; or
omitting USING INDEX if the table doesn't need to be
reordered.
Also, the note about REPACK being one long transaction preventing useful
vacuuming work applies to both regular one and concurrent, so it must
appear in the "Notes on Resources" section rather than "Notes on
Concurrent Operation". I'll move it up a subsection.
And with that, I will push it. Further changes are still possible and
suggestions are welcome, of course.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Cómo ponemos nuestros dedos en la arcilla del otro. Eso es la amistad; jugar
al alfarero y ver qué formas se pueden sacar del otro" (C. Halloway en
La Feria de las Tinieblas, R. Bradbury)
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Antonin Houska <ah@cybertec.at>
Дата:
Alvaro Herrera wrote: > On 2026-Oct-07, Antonin Houska wrote: > > > ok. What I find disturbing in the first sentence is the "but" conjunction: > > > > "... that clause is given but an index scan is chosen ..." > > > > Shouldn't it rater be "and"? > > > > When I read "but", I usually expect a contradiction. However I see no > > contradiction between specifying the USING INDEX clause and choosing index > > scan. > > You're right, that was pretty hard to read. How about this, following > Radim's suggestion? > > > REPACK creates a temporary copy of the table and all > of its indexes, so you need free disk space at least equal to the sum > of the table size and the index sizes. > > > > If the USING INDEX clause is given and the planner > chooses a sequential scan and sort to implement it, a temporary sort > file that uses the table size again is needed in addition to the above. > This method is usually faster than an index scan, but if the disk space > requirement is intolerable, you can disable this choice by temporarily > setting to off; or > omitting USING INDEX if the table doesn't need to be > reordered. > Yes, this looks well structured - first the simple case, then the "less simple". > The "... that uses the table size again is needed ..." bit looks > somewhat odd to me, but I don't know how to make it better. The only variant that occurs to me is "... that creates one more copy of the table ..." Just in case. -- Antonin Houska Web: https://www.cybertec-postgresql.com
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
Pushed this. Thanks for the reviews! -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "El sudor es la mejor cura para un pensamiento enfermo" (Bardia)
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Oct 07, 2026 at 02:26:54PM +0200, Alvaro Herrera wrote:
> Pushed this. Thanks for the reviews!
We talked about this one in today's RMT meeting.
Processing of these concurrent changes requires a fixed small amount of
memory for each tuple concurrently updated or deleted, not limited by
maintenance_work_mem; if more than about 104 million rows are
concurrently updated or deleted during the execution of REPACK, the
command fails.
This seems like a rather low limit that will definitely affect folks in the
field. The upthread discussion indicates that the "make REPACK
(CONCURRENTLY) MVCC-safe" work should fix this, but could there be an
incremental improvement that alleviates this limitation in the meantime?
--
nathan
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
От:
Alvaro Herrera <alvherre@kurilemu.de>
Дата:
On 2026-Oct-07, Nathan Bossart wrote: > We talked about this one in today's RMT meeting. > > Processing of these concurrent changes requires a fixed small amount of > memory for each tuple concurrently updated or deleted, not limited by > maintenance_work_mem; if more than about 104 million rows are > concurrently updated or deleted during the execution of REPACK, the > command fails. > > This seems like a rather low limit that will definitely affect folks in the > field. The upthread discussion indicates that the "make REPACK > (CONCURRENTLY) MVCC-safe" work should fix this, but could there be an > incremental improvement that alleviates this limitation in the meantime? The limit is caused by the dynahash used in combocid.c to store the CID mappings. An "easy" fix for this might be to mark that allocation as using palloc_huge() somehow. I haven't actually tried that, but I suspect it's not without its risks. (Since I didn't test it, I don't know either if there are any other limits beyond that one.) I'm not really sure that 105 million tuples modified concurrently during repack is really all that small a limitation. I mean, it's not **huge**, but it's not tiny either. If you update 1000 tuples per second while REPACK runs, you'd need a REPACK run that takes 28 hours to reach the limit. I guess it's definitely not impossible to hit it, if your workload is insane enough. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Re: REPACK (CONCURRENTLY) can't complete after ~105M concurrent updates/deletes
Hi Álvaro, Nathan,
> This seems like a rather low limit that will definitely affect
> folks in the field.
I am not a heavy user of pg_repack, just curious, why do we think
105 million is a very small number?
> An "easy" fix for this might be to mark that allocation as
> using palloc_huge() somehow.
The request that fails is the comboCids array in GetComboCommandId(),
not the hash table. 8 bytes times 209,715,200 entries is the
1677721600 in Radim's error. I do not see a limit in the hash table.
I tried repalloc_array_extended() there. With 110 million replayed updates
master fails with that error, and the patched build completes with
correct data. It only changes runs that fail today. From reading the
code, the next limits are the int array size at about 1.7 billion
entries, and then 2^32 commands.
> folks in the field.
I am not a heavy user of pg_repack, just curious, why do we think
105 million is a very small number?
> An "easy" fix for this might be to mark that allocation as
> using palloc_huge() somehow.
The request that fails is the comboCids array in GetComboCommandId(),
not the hash table. 8 bytes times 209,715,200 entries is the
1677721600 in Radim's error. I do not see a limit in the hash table.
I tried repalloc_array_extended() there. With 110 million replayed updates
master fails with that error, and the patched build completes with
correct data. It only changes runs that fail today. From reading the
code, the next limits are the int array size at about 1.7 billion
entries, and then 2^32 commands.
It does not lower the memory use. I measured 48 bytes for each
change, so the limit today also caps this at about 5 GB. Without it,
1 billion changes need about 50 GB, and a host with less gets the
OOM killer, not an ERROR.
change, so the limit today also caps this at about 5 GB. Without it,
1 billion changes need about 50 GB, and a host with less gets the
OOM killer, not an ERROR.
Experimental patch attached.
Thanks,
Shihao