I had a lot of odd disturbances to my sleep routine after surgery. At first, all was fine. Then a few weeks after surgery, I found that I would fall asleep OK but wake up at 2 or 3 AM, unable to get back to sleep for hours. At first I found this really unnerving, as I was used to needing my rest at night to get to work the next day. But I was off on medical leave for a while, so I gradually convinced myself that I would sleep when I could, and if I was awake for a while in the middle of the night, so be it. I would have a light snack and maybe read or surf the web for an hour or two, then go back to bed. Usually I was able to get back to sleep.
My doctor prescribed Ambien, but after I filled the prescription and read the potential side-effects, I never took any.
The one thing I did try, and had pretty good results from, was ordinary over-the-counter Benadryl. This is sold as an allergy medication, an antihistamine. My daughter was, at the time, working in the mental health profession, and she told me that they often gave patients Benadryl when they needed just a bit of help sleeping but not enough to warrant prescription meds. The Benadryl was available without prescription and had minimal side effects when used at the recommended dosage. I tried it, taking it at bedtime, and was able to stay asleep for the night. I think I used it for 2 or 3 weeks, until my normal sleep cycle was re-established.