We investigate two mean–variance optimization problems for a single cohort of workers in an accumulation phase of a defined benefit pension scheme. Since the mortality intensity evolves as a general Markov diffusion process, the liability is random. The fund manager aims to cover this uncertain liability via controlling the asset allocation strategy and the contribution rate. In order to have a more realistic model, we study the case when the risk aversion depends dynamically on current wealth. By solving an extended Hamilton–Jacobi–Bellman system, we obtain analytical solutions for the equilibrium strategies and value function which depend on both current wealth and mortality intensity. Moreover, results for the constant risk aversion are presented as special cases of our models.