If he's had pain while deficating then he may be holding back to avoid more pain. He may also be holding back because he doesn't want to take the time to go to the bathroom. To help with both of these causes, take him to the toilet regularly. Watch to see when he does have a bowel movement and time your trips accordingly. Then stay with him. Distract him with a book or toys.
If he's getting plenty of fiber I'd focus on making sure he gets plenty of water. My grandchildren had a sippy cup of water available all of the time. We would remind them to drink if the cup was still full.
Have you tried giving him prunes or prune juice? I don't know anyone who likes the juice. He can eat dried prunes as they are. Or you can cook them. My grandchildren like them both ways. My granddaughter loves plums and I see that they're back in the stores.
In what form is he getting fruits and vegetables? They have more fiber if skins are left on and they're eaten raw.
Have you looked up the fiber amount and totaled how much fiber he gets. I don't know what the optimal amount is. Perhaps your doctor can tell you. I began reading labels and discovered that many cold cereals and crackers do not have enough fiber in them to count.
How much milk does he drink? How much cheese? Dairy products can be constipating.
If your son just started being constipated this won't apply. My grandson was constipated until around age 3. Then he wasn't. I think that his system may have not be fully working earlier and he needed the extra fiber. More fiber than the average preschooler.
Constipation is no fun for everyone involved. I hope that you will be able to find a way to prevent it.
You might try using a small potty chair. After reading one of the posts I remembered that some toddlers feel that the poop is a part of them and when it lands in the big toilet they fear that they too can be flushed down the drain.