I discovered it by accident. Years ago I was having terrible patterns, so out of desperation I tried melatonin. I'm a little paranoid of taking anything to the point of dependency so I would only do a couple of nights in a row, then not use it until I needed it.
It works quite well for me this way, but I must say that occasionally I'll have dreams that are vivid and intense (meaning it get's my adrenaline going). Not nightmares, more anxiety-like.
I haven't asked a doctor for it, and I don't know what their reaction would be.
When I've struggled with insomnia I've been given advice about sleep hygiene; then had someone give me help with sleep hygiene; then got a prescription for zopiclone.
That was great for me, at that time. (I really needed sleep!!) but unfortunately the care got handed back to my GP and he was careless about the repeat prescriptions. SO, I ended up being able to get it for about a year. Luckily I didn't suffer too much from it, but some people find zopiclone addictive and there are other risks from it.
What I'd really want, before getting to zopiclone (and probably before melatonin) would be access to a cognitive behaviour therapy course for insomnia.
For example:
Then I read gwern's article on melatonin[1], and it changed everything. I don't get the shorter sleep he describes, but I take it once or twice a week to give me what feels like complete control over my sleep cycle. In addition the alertness/grumpiness benefits, it is truly great just being able to go to sleep and wake up at the same time as my wife (who seems to be on a 23-hour day).
[1] http://www.gwern.net/Melatonin