This paper explores an optimal investing problem for a retiree facing longevity risk and living standard risk. We formulate the optimal investing problem as an optimal portfolio choice problem under a time-varying risk capacity constraint. Under the specific condition on model parameters, we show that the value function is a $C^2$ solution of the HJB equation and derive the optimal investment strategy in terms of second-order ordinary differential equations. The optimal portfolio is nearly neutral to the stock market movement if the portfolio's value is at a sufficiently high level; but, if the portfolio is not worth enough to sustain the retirement spending, the retiree actively invests in the stock market for the higher expected return. In addition, we solve an optimal portfolio choice problem under a leverage constraint and show that the optimal portfolio would lose significantly in stressed markets. This paper shows that the time-varying risk capacity constraint has important implications for asset allocation in retirement.