a) do you have an interrupt storm? b) what does postgres do before the hang? c) do you have anyother software running? Including contrib modules. It may be a dns lookup timeout (watch port 53 tcp/udp) d) what filesystem? Needs filesystem some kind of "maintenance window"? I mean flush dirty caches, metadata, wake up barriers...
At initial glance, I suspect adjusting these values may resolve the issue as SHMALL should be set either total max memory size or in number of pages. I think the value set is too large therefore recommend comment this SHMALL parameter and set only SHMMAX value with 24GB.
Request to verify the server logs if there are any share memory errors and assume that work_mem value is not set to extreme higher value as the max connections has set to 500.