There is a lot of difference in quality when it comes to mattresses. A bad and not supportive mattress can make sure that your back pain does not become less during sleep, and in some cases even worse. Test yourself what is most comfortable for you, a memory foam mattress, pocket sprung mattress or another type of mattress.
The problem may also be in the way you use your mattress. Do you have a pocket spring mattress, for example? Then there is a specific way to lie on this. Pocket springs means that there are several pockets in the mattress that springs in different ways. Logically, shoulders and hips can sink deeper than the rest of your body, this gives a better lying posture. But if you are lying on the mattress in reverse (ie with your head on the actual foot end), the pockets do not match your body shape. In that case, try to lie in bed the other way around (or turn your mattress 180 degrees).