I've found re-establishing a natural circadian rhythm and correcting magnesium deficiency to work best. Dr. Jack Kruse is a retired brain surgeon who preaches that 80% of health is just waking up to watch the sun rise barefoot everyday, getting as much sun exposure as possible, and avoiding all sources of non-native EMF. This means your kindle before bed, and as crazy as it may sound in the 21st century, replacing all the LEDs and CFLs in your house with incandescent bulbs, as these new energy efficient technologies produce a blue light spectrum similar to noon time sun. So if you're exposing yourself to noon time sun in the form of non-native EMF like screens and blue light, you're tricking your body into thinking it's high noon, when it's actually 8pm. This is the source of melatonin deficiency. It can take your brain something like 4 hours to start producing natural melatonin after exposure to blue light, so the best cheat code I've found to get around the screens at night issue is blue light blocking glasses. There's a lot of untested brands out there, and I don't gain anything from promoting this, but BonCharge has 3rd party tested their lenses to block 100% of the blue light spectrum, and their red lenses instantly relax me when I put them on after sunset. Taking exogenous melatonin down-regulates your endogenous melatonin production, so overtime your body produces less of it, making dependency a risk. I think it can be through addressing the light hygiene issue.
https://boncharge.com/collections/blue-light-blocking-glasses
https://youtu.be/T5TvHd7WnIE - Jack Kruse quickie on melatonin
As for the magnesium, I take magnesium breakthrough, which contains all 7 bio-available forms of magnesium. I used to experience painful leg cramps that would wake me in the middle of the night after a surgery, and this stopped it. I'd recommend getting a few bottles to start and following their recommended protocol to optimize your magnesium levels (unless you're 100% sure you're levels are good, worst case is loose stools if you overdo it.)
https://bioptimizers.com/magnesium-breakthrough?gl=646393f83f5d600d3b8b4567
Hope something in here is helpful. Sweet dreams!
-bryce