We present a first-principles theoretical study of vibrational spectral diffusion and hydrogen bond dynamics in heavy water without using any empirical model potentials. The calculations are based on ab initio molecular dynamics simulations for trajectory generation and a time series analysis using the wavelet method for frequency calculations. It is found that, in deuterated water, although a one-to-one relation does not exist between the instantaneous frequency of an OD bond and the distance of its associated hydrogen bond, such a relation does hold on average. The dynamics of spectral diffusion is investigated by means of frequency-time correlation and spectral hole dynamics calculations. Both of these functions are found to have a short-time decay with a time scale of approximately 100 fs corresponding to dynamics of intact hydrogen bonds and a slower long-time decay with a time constant of approximately 2 ps corresponding to lifetimes of hydrogen bonds. The connection of the slower time scale to the dynamics of local structural relaxation is also discussed. The dynamics of hydrogen bond making is shown to have a rather fast time scale of approximately 100 fs; hence, it can also contribute to the short-time dynamics of spectral diffusion. A damped oscillation is also found at around 150-200 fs, which is shown to have come from underdamped intermolecular vibrations of a hydrogen-bonded water pair. Such assignments are confirmed by independent calculations of power spectra of intermolecular motion and hydrogen bond kinetics using the population correlation function formalism. The details of the time constants of frequency correlations and spectral shifts are found to depend on the frequencies of chosen OD bonds and are analyzed in terms of the dynamics of hydrogen bonds of varying strengths and also of free non-hydrogen-bonded OD groups.