Oxygen is widely used to tune the performance of chalcogenide phase-change materials in the usage of phase-Change random access memory (PCRAM) which is considered as the most promising next-generation non-volatile memory. However, the microscopic role of oxygen in the write-erase process, i.e., the reversible phase transition between crystalline and amorphous state of phase-change materials is not clear yet. Using oxygen doped GeTe as an example, this work unravels the role of oxygen at the atomic scale by means of ab initio total energy calculations and ab initio molecular dynamics simulations. Our main finding is that after the amorphization and the subsequent re-crystallization process simulated by ab initio molecular dynamics, oxygen will drag one Ge atom out of its lattice site and both atoms stay in the interstitial region near the Te vacancy that was originally occupied by the oxygen, forming a dumbbell-like defect (O-VTe-Ge), which is in sharp contrast to the results of ab initio total energy calculations at 0 K showing that the oxygen prefers to substitute Te in crystalline GeTe. This specific defect configuration is found to be responsible for the slower crystallization speed and hence the improved data retention of oxygen doped GeTe as reported in recent experimental work. Moreover, we find that the oxygen will increase the effective mass of the carrier and thus increases the resistivity of GeTe. Our results unravel the microscopic mechanism of the oxygen-doping optimization of phase-change material GeTe, and the present reported mechanism can be applied to other oxygen doped ternary chalcogenide phase-change materials.