If so, how long did it take to get better?
Do not stretch your spine, as your structure is likely weak, and you can further damage your disks/vertebrae and the nerves therein by improperly applying changes to where the pain resides most frequently.
I suggest you look into foam rolling, and fasciae work in the glute/hamstring areas first. There are a lot of mobility youtubers that talk all about different techniques.
Also I have been studying the effects of LaJin (Traditional Chinese stretch series) and so far found the prolonged relaxation in the fascia to relieve chronic pain, and uncover structural improprieties that are the root cause.
Here is a long write-up over self healing with paida-lajin (拍打-拉筋 Basically slapping-stretching). http://www.dontow.com/wordpress/wp-content/uploads/2013/09/P...
As for how long it takes to get better... growth and entropy are in opposition. It may relieve your pain day 1 but it may come back halfway through the next day, it may take 6 weeks to feel the deep relief. Your structural damage could be well beyond simple tissue degeneration and nerve pain, in which case self treatment is not advised. You should have an MRI taken if you believe yourself to be in later stage deterioration of the affected area.
In short: When the problem was extreme - sought the help of an excellent physiotherapist. And once recovered - exercise to keep the problem at bay.
EDIT: Why I don't recommend doing exercises or stretches without consulting a good professional is that a good professional can tell you when you are "ready" for certain stretches, movements or exercises which would otherwise make the situation worse. Also of course s/he can evaluate your condition and tell you which ones are safe at which point of time. I didn't have many exercises for recovery. I had to do a handful but I didn't start with all of them and I had certain restrictions on movements in the beginning until I got a bit better and could do those safely.
EDIT2: Lifting weights also naturally improved my posture. I didn't even have to make conscious effort to maintain good posture when seated at the computer for instance. So, that is another way in which it prevents injury.
I do have to echo Yaa101 though: mobility exercise and stretching help, and my chiropractor helps counter some of the persistent pains. Stretches that target my legs and especially my hips are critical to helping the lower back relax and not hurt.
Ironically, the least pain I felt was when I played volleyball with some friends for 3-4 hours every weekend for a month or two.
- a solid core routine. Here's a good example: https://news.ycombinator.com/item?id=4988649
- if it persists, reading the book "Healing back Pain" by John Sarno (Countless people seem to have begun the book highly skeptical and finished it pain free)