It has been used to treat insomnia and sleep-phase abnormalities.
The most interesting study I found regarding long-term use of melatonin was published in JAMA in 2008: http://www.ncbi.nlm.nih.gov/pubmed/18544724
In this prospective, blinded study, elderly patients with dementia were given 2.5 mg melatonin near bedtime, over an average of 15 months of follow-up. Patients in another group were exposed to bright light during the day (approximately 1000 Lux indoors, from 10:00 AM to 6:00 PM). A third group received both melatonin at night and bright light in the day. Placebo groups received no melatonin, or were exposed to typical indoor office lighting, of about 300 Lux.* Interestingly, caregivers were not able to tell whether their site had the ordinary lighting or the bright light (the increased light intensity was measurable with a meter, but was not noticeable subjectively).
However, the group receiving melatonin alone showed worsening mood (less positive affect & more negative affect).
The group exposed to bright light in the day, plus melatonin at night, did not show worsened mood.
The authors conclude that bright light in the day helps with mood, cognition, and function in elderly dementia patients. Melatonin alone helps with sleep but has a negative impact on mood. Bright light plus melatonin had a positive impact on all the symptoms studied.
Based on this study, I would encourage anyone using melatonin at night to ensure that they get plenty of bright light during the daytime. It also suggests that any study looking at melatonin treatments should also consider daytime bright light exposure as an important variable which could affect response to melatonin.
Here's a reference to a study showing that 2 mg of sustained-release melatonin improves sleep:
http://www.ncbi.nlm.nih.gov/pubmed/18036082
In this study, children with intellectual disabilities experienced relief of their insomnia (including reduced time to fall asleep, reduced time awake, and increased total sleep time) with 5 mg melatonin supplementation over a 4-week period:
http://www.ncbi.nlm.nih.gov/pubmed/18261024
Here's a study showing improved sleep, with no adverse effects, due to melatonin administration to autistic children:
http://www.ncbi.nlm.nih.gov/pubmed/18182647
Here's a study showing improved sleep in children with epilepsy who were treated with adjunctive melatonin (6-9 mg). There were no significant side-effects:
http://www.ncbi.nlm.nih.gov/pubmed/15794175
This study showed improved sleep in adolescents with ADHD, when they were given 5 mg melatonin over a 30-day trial. However there was no improvement in ADHD symptoms:
http://www.ncbi.nlm.nih.gov/pubmed/16670647
Melatonin has been associated with autoimmune conditions. Here is a case report associating melatonin use with autoimmune liver disease:
http://www.ncbi.nlm.nih.gov/pubmed/9412927
Here is an article about melatonin possibly exacerbating rheumatoid arthritis (various reports show increased melatonin levels in rheumatoid arthritis patients):
http://www.ncbi.nlm.nih.gov/pubmed/19069959
Yet, in various other reports, melatonin has been shown in animals to protect the liver from various forms of artificially-induced toxicity. (e.g. http://www.ncbi.nlm.nih.gov/pubmed/15386534)
In conclusion, melatonin appears to be have a reasonable safety profile, and is a potentially effective treatment for insomnia, particularly "initial insomnia" in which there is difficulty falling asleep at the beginning of the night. Typical doses of melatonin range from about 2 mg - 6 mg.
The one main concern about adverse effects concerns possible exacerbation of autoimmune diseases such as rheumatoid arthritis, although the evidence is not clear on this point. Other types of toxicity, while possible, appear to be rare. Melatonin may even protect cells from a variety of different types of harm. But it is important to recognize the possibility that there could be other unknown adverse effects over long periods of time.
As with any treatment, we have to balance risks against benefits: insomnia itself clearly has a variety of negative long-term health effects (ranging from increased risk of physical and psychiatric illness, to increased risk of accidents). Other treatments for insomnia have their own risk/benefit profiles.
Cognitive-behavioural therapies for insomnia are clearly the safest and most beneficial, and should be optimized before any other medical therapy. But it appears to me that melatonin ought to have a place in the medical treatment of insomnia, alongside other established therapies.