Sharp pain in rectum after sex?

Every now and then I get a very sharp stabbing pain in my rectum after sex, it's pretty high inside me. And it hurts to pass gas or try to poop... & hurts for a day or two. what could this be ?