Also during index creation we are trying to do it multiple partitions at same time from multiple sessions.But seeing out of memory error in 5th or 6th session.
Had that same problem during pg_restore. Reduced maintenance_work_mem and the problem went away.