The line sits between green pastures and paths of righteousness, and it is the hinge of the psalm. He restoreth my soul. The Hebrew is closer to he brings back my life — the word used for a sheep that has wandered and is retrieved, and for breath returning to someone who had none.
It is worth noticing what precedes it. He maketh me to lie down in green pastures; he leadeth me beside the still waters. Sheep will not lie down when they are afraid, hungry, or harassed. Rest is evidence that something has been dealt with. The shepherd does not order the sheep to relax; he removes what was preventing it.
Restoration in this psalm is not a single dramatic rescue. It is repeated, ordinary, and mostly quiet: food, water, rest, then movement again. He leadeth me in the paths of righteousness for his name's sake — and the reason given for all of it is his reputation, not the sheep's merit. He does this because of who he is.
David goes on to the valley of the shadow of death, so this is not a life without danger. But the shepherd who restores in the pasture is the same one who is present in the valley, and the psalm's confidence in the dark comes from what was learned in the light.