p-type conductivity and crystal quality of Mg-doped GaN grown by MOCVD have been improved through opti- mization of the magnesium flow rate. The hole concentration first increased and then decreased with the magnesium flow rate while the mobility decreased monotonously. The optimum sample reached a hole concentration of 4. 1×10^17cm -3 and a resistivity of 1Ω·cm. Based on a self-compensation model involving the deep donor Mo, VN, we calculate the hole con- centration as a function of magnesium doping concentration NA ,which indicates that the self-compensation coefficient in- creases with NA;the hole concentration first increases with NA and reaches a maximum at NA≈4×10^19 ,then decreases rapidly as doping concentration increases. XRD also indicate that dislocation density decreased as magnesium flow rate decreased.