Hi
Welcome to the MedHelp forum!
This type of pain with relief on passing gas can be due to chronic constipation or due to inflammatory bowel disorders like IBS, Crohn's and ulcerative colitis or food intolerance disorders like celiac disease.
Increase fiber and fluids in your diet and see if this helps. Also hemorrhoids and fissures at times cause pain and prevent passage of gas by tightening the anal sphincter.
It is difficult to diagnose on net. Please consult your PCP for primary examination followed by proper referral.
Take care!
if that was me i would go see my doc