Welcome on hcm.
You as per you story might be suffering from sciatica
In sleep you can use fetal posture.
If you lie on back than put a roll under knee to release pressure on nerve
Some over the counter analgesic
If these measures do not relieve the pain, than consult you gp and get investigated for the cause of sciatica and get treated accordingly.