Cherry picked 1e29e5e90e to fix db syncing.