To avoid this unpleasant punishment in the grave of חיבוט הקבר or the BEATING OF THE GRAVE just have the 4th meal after shabbat Havdalah called Melava Malka or the Fourth Meal of King David.
After a person dies and is buried in the ground, immediately four angels come and lower the ground of the grave. They deepen it below resulting in a hollow space that is as deep as the height of the person buried there.
Then they return his soul to his body like during his life. The reason being that the KLIPAH is still attached to the soul and the body and has not separately from them. Therefore the soul must be returned to the body as one.
Then each of the angels mentioned holds an end of the body and smash the body against the walls of the hollow grave and also they shake him similar to the way a garment is held from its two ends and shaken to remove dust that is stuck to it. They beat him with sticks of fire, until the KLIPAH separates from him completely. Then he is ready for resurrection when he time comes without the KLIPAH that is what is for us a cleanse of the KLIPOT.
When the soul departs from the body it still has an attachment to the physical pleasures it enjoyed in this world and since it can no longer enjoy them as a physical body it feels a separation pain described as חיבוט הקבר.