The aim of the study was to explore the relationship between type 2 diabetes (T2DM) and postoperative pneumonia, and the effects of T2DM and postoperative pneumonia on the mortality in inpatients with surgery. Methods: A retrospective study was conducted on 43,174 inpatients with surgery in The First Hospital of Qinhuangdao. These patients were divided into four groups according to T2DM and postoperative pneumonia, Group A subjects without T2DM and postoperative pneumonia, Group B subjects with T2DM only, Group C subjects with postoperative pneumonia only and Group D subjects with T2DM and postoperative pneumonia. Inhospital mortality was collected. Results: The incidences of postoperative pneumonia were higher in patients with T2DM than patients without T2DM (T2DM 3.2% vs Non-diabetes 1.7%, χ 2 =36.219, P<0.001). The mortalities were 0.3% in Group A, 0.3% in Group B, 4.6% in Group C and 8.6% in Group D. In multiple logistic regression analysis, adjusted for sex, age, emergency admissions, coronary heart disease, heart failure, chronic kidney disease, hypoproteinemia, stroke and transient ischemic attack, the mortalities of Group C and Group D were 4.515 (95% CI: 2.779~7.336, P<0.001) times and 8.468 (95% CI: 3.567~20.099, P<0.001) times than the mortality of Group A. Conclusion: T2DM is susceptible to postoperative pneumonia. The mortality increased in patients with postoperative pneumonia. When patients with T2DM and postoperative pneumonia at the same time, the mortality increased further. In T2DM patients with postoperative pneumonia, perioperative management should be improved for patient safety.