You don't need a prescription as it's over the counter aka OTC. It's perfectly safe, but the recommended dosages for children are between 1-3 milligrams. Melatonin is sold in tablets in 1 mg and higher and is also sold as a liquid.
The reason it's safe is because Melatonin is a hormone that the body naturally produces that let's us know when we're tired and supposed to go to bed. When you feel tired and you're drowsy and yawning? That's your body's melatonin kicking in and saying "go to bed." People with insomnia don't produce enough (or any) Melatonin. So if you give 1 mg to your child, or even start with .5 mg and go up to 1 mg and go up .5 mg until it starts to work, it's safe to continue to give because the body metabolizes the Melatonin within 3 hours or so. There are no remnants of it in the morning or even halfway through the night.
I have to use it for my daughter that has Autism because, as is common with autistic people, her body simply doesn't make enough Melatonin. She could wake up at 6 AM and still be awake until 2 AM wide awake yet exhausted. The Melatonin helps her body's sleep-wake disorder adjust, if only for a few hours, so that she can rest and get a normal night's sleep.
Once in a while I use it myself if I find that I've taken my Trazadone too late in the evening. I've also had to rarely give it to one of my other children.
I have the okay from our pediatric neurologist and it's in the file with our pediatrician that we use it. For proper dosing, speak with your pediatrician.
EDIT: I do want to add that our routine is very simple and soothing at bed time. We also have a simplified, restricted diet that contains no HFCS, very little sugar, no artificial food dyes, no caffeine, and is relatively allergen free. We have a lot of health issues/sensitivities to watch out for, so we know that she's not getting overly stimulated by processed chemicals in her foods.