A Commentary, Critical, Practical, and Explanatory on the Old and New Testaments, by Robert Jamieson, A.R. Fausset and David Brown  at sacred-texts.com
psa 23:1Under a metaphor borrowed from scenes of pastoral life, with which David was familiar, he describes God's providential care in providing refreshment, guidance, protection, and abundance, and so affording grounds of confidence in His perpetual favor. (Psa 23:1-6)
Christ's relation to His people is often represented by the figure of a shepherd (Joh 10:14; Heb 13:20; Pe1 2:25; Pe1 5:4), and therefore the opinion that He is the Lord here so described, and in Gen 48:15; Psa 80:1; Isa 40:11, is not without some good reason.
psa 23:2green pastures--or, "pastures of tender grass," are mentioned, not in respect to food, but as places of cool and refreshing rest.
the still waters--are, literally, "waters of "stillness," whose quiet flow invites to repose. They are contrasted with boisterous streams on the one hand, and stagnant, offensive pools on the other.
psa 23:3To restore the soul is to revive or quicken it (Psa 19:7), or relieve it (Lam 1:11, Lam 1:19).
paths of righteousness--those of safety, as directed by God, and pleasing to Him.
for his name's sake--or, regard for His perfections, pledged for His people's welfare.
psa 23:4In the darkest and most trying hour God is near.
the valley of the shadow of death--is a ravine overhung by high precipitous cliffs, filled with dense forests, and well calculated to inspire dread to the timid, and afford a covert to beasts of prey. While expressive of any great danger or cause of terror, it does not exclude the greatest of all, to which it is most popularly applied, and which its terms suggest.
thy rod and thy staff--are symbols of a shepherd's office. By them he guides his sheep.
psa 23:5Another figure expresses God's provided care.
a table--or, "food," anointing
oil--the symbol of gladness, and the overflowing
cup--which represents abundance--are prepared for the child of God, who may feast in spite of his enemies, confident that this favor will ever attend him. This beautiful Psalm most admirably sets before us, in its chief figure, that of a shepherd, the gentle, kind, and sure care extended to God's people, who, as a shepherd, both rules and feeds them. The closing verse shows that the blessings mentioned are spiritual.