The invention relates to a medicine for preventing or treating insomnia. A traditional Chinese medicine composition is prepared from the bulk drugs in parts by weight of 20-30 parts of radix paeoniaealba, 20-30 parts of radix bupleuri, 10-15 parts of radix angelicae sinensis, 10-15 parts of radix astragali seu hedysari, 10-15 parts of radix rehmanniae, 10-15 parts of rhizoma anemarrhenae, 10-15 parts of gentian, 10-15 parts of cortex moutan radicis, 10-15 parts of fructus psoraleae, 10-15 parts of rhizoma drynariae, 5-10 parts of cortex albiziae, 5-10 parts of semen ziziphi spinosae, 5-10 parts of radix polygalae, 5-10 parts of raw malt, 5-10 parts of rhizoma atractylodis macrocephalae, 5-10 parts of poria cocos and 5-10 parts of radix glycyrrhizae. The traditional Chinese medicine composition is a decoction, or is prepared into tablets, powder, capsules, granules and pills by screening, processing and crushing the medicinal raw materials into medicinal powder and adding auxiliary materials. Physiological characteristics of perimenopausal women are theoretically dialectical, insomnia pathogenesis is analyzed, liver conditioning is taken as the center, liver soothing and kidney nourishing are taken as the key point, viscera are regulated to form a closed loop, blood production and qi tonifying are achieved, qi and blood hyperactivity is improved, qi activity is regulated, and perimenopausal women insomnia is effectively treated.