Pecan forests (Carya illinoinensis) are significant contributors to both food and oil production, and thrive in diverse soil environments, including coastal regions. However, the interplay between soil microbes and pecan forest health in coastal environments remains understudied. Therefore, we investigated soil bacterial and fungal diversity in coastal (Dafeng, DF) and inland (Guomei, GM) pecan plantations using high-throughput sequencing. The results revealed a higher microbial diversity in the DF plantation than in the GM plantation, significantly influenced by pH and edaphic factors. The dominant bacterial phyla were Proteobacteria, Acidobacteriota and Bacteroidota in the DF plantation, and Acidobacteriota, Proteobacteria, and Verrucomicrobiota in the GM plantation. Bacillus, Nitrospira and UTCFX1 were significantly more abundant bacterial genera in DF soil, whereas Candidatus Udaeobacter, HSB_OF53-F07 and ADurbBin063-1 were more prevalent in GM soil. Basidiomycota dominated fungal sequences in the GM plantation, with a higher relative abundance of Ascomycota in the DF plantation. Significant differences in fungal genus composition were observed between plantations, with Scleroderma, Hebeloma, and Naucoria being more abundant in DF soil, and Clavulina, Russula, and Inocybe in GM soil. A functional analysis revealed greater carbohydrate metabolism potential in GM plantation bacteria and a higher ectomycorrhizal fungi abundance in DF soil. Significantly positive correlations were detected between certain bacterial and fungal genera and pH and total soluble salt content, suggesting their role in pecan adaptation to coastal environments and saline–alkali stress mitigation. These findings enhance our understanding of soil microbiomes in coastal pecan plantations, and are anticipated to foster ecologically sustainable agroforestry practices and contribute to coastal marshland ecosystem management.