Hi hackers,

I've been looking at the code for CLUSTER/VACUUM FULL, and whether it is
possible to do a concurrent version of it using a multi-transactional
approach similar to concurrent reindexing and partition detach.

The idea would be to hold weaker locks in TX1 when doing the heap rewrite
(essentially allow reads but prevent writes), and then do the actual heap
swap in a second TX2 transaction.

Having experimented a bit with this approach, I found that reindexing is an
issue because that happens after the new heap has been swapped in. The
current reindex during a heap swap effectively blocks reads so if one
starts a new transaction after swapping heaps, it will block reads for a
long time.

This made me think about two ways to handle this:

1. Rebuild indexes on the temporary heap in TX1 and then swap in the new
indexes along with the new heap in TX2.

2. Do a concurrent index rebuild after the heap swap.

Of the two approaches above, (2) seems easiest to implement, but the
downside is that indexes would be invalid while indexes are rebuilt.
Therefore, (1) seems to be the more desirable one because all the heavy
lifting would be done in TX1 on the temporary heap.

Does anyone have a sense of whether approach (1) is feasible or whether
there are any major blockers?

Is this worth pursuing at all or am I missing something?

Best regards,

Erik
-- 
Database Architect, Timescale

Reply via email to