BackgroundTo investigate the difference of demographic, health status and clinical characteristics of patients with or without insomnia postoperatively, and to identify the potential risk factors of insomnia.Methods299 patients undergoing surgery were included. Patients were divided into group A (insomnia, N = 78) and group B (without insomnia, N = 221). Insomnia Severity Index (ISI), Patient Health Questionnaire-9 (PHQ-9), Generalized Anxiety Disorder (GAD-7), and Montreal cognitive assessment (MoCA) were applied to all patients preoperatively. Visual Analogue Scale (VAS) was assessed preoperatively, and at the end of the surgery, one day after surgery, two days after surgery and three days after surgery. The PHQ-9, the GAD-7 and the ISI were reassessed three days after surgery. Information on sociodemographic variables and demographic data were collected.ResultsAmong the two groups, the average points patients got in the ISI, PHQ-9 and the GAD-7 in group A were also significantly higher than those in group B. The VAS score 3 days after surgery was significantly higher in group A. The PHQ-9 and the GAD-7 3 days after surgery showed significantly higher depression and anxiety scores in group A. Logistic regression showed ISI (P < 0.001, 95%CI = 1.218-1.500), the GAD-7 (P = 0.01, 95%CI = 0.712–0.954) preoperatively and the PHQ-9 postoperatively (P < 0.001, 95%CI = 1.226–1.555) were risk factors of insomnia.ConclusionsInsomnia is common in patients, which worsen after surgery. The present study suggests that depression and anxiety are risk factors of poor sleep quality after surgery. There is a need for further research and strategies for depression and anxiety management to achieve better sleep and significant health benefits in these patients.Trial registration: clinical trial, NCT04027751. Registered 22 July 2019, https://clinicaltrials.gov/ct2/show/NCT04027751?cond=NCT04027751&cntry=CN&draw=2&rank=1.