Drink much water or eat soup more often. It will help tp avoid this unpleasant feeling. I had the same trouble and I got rid of it after I have changed my lifestyle to the healthier one.
Usually getting constipated will cause it to hurt a lot when waste finally passes. Constipation happens for a variety of reasons, but waste kind of piles up at the end, gets a little larger, and thus hurts when it goes out. To prevent constipation, the basic three things are: Drink extra water, exercise regular, and eat enough fiber foods (to include oat cereal, whole wheat bread, dark green vegies and salads). If you are in a situation where you are stuck right now and the waste won't come out, you can use some sort of laxative, with Senokot being natural and mild, producing a movement the next morning if you take it in the evening, or squirting BabyLax or PediaLax ointment in there, as examples. Also, consuming "probiotics" for a couple weeks now and then can help digestion do better, too, which you can get from Acidophilus milk or Activia yogurt or any yogurt with "live cultures or live bacteria" in it. It restores normal intestinal flora, which can be destroyed by some medications.