"Resetting topic counters" takes forever and crashes

I was just about to finish migration (~50k users, ~300k posts, ~100k PMs).

While the data migration worked ~okay, the scripts are getting stuck on “resetting topic counters” step. Last time it even crashed on “postgre no free space” (I have ~500 GB free).

Can this step be somehow split to smaller chunks or even omited completely? From the code I got an impression that these counters are being reset anyway for the particular topic when posting or so.

I think the thing to do is increase memory settings for postgres. Maybe “free space” refers to space in some data structure rather than disk space. I’d search for things about postgres tuning, maybe.