This is a Ps. of simple and unclouded confidence in God, who is described first as a shepherd (Psalms 23:1-4) and next as an host (Psalms 23:5-6). The beautiful imagery of the first part would be natural on the lips of the king who was a shepherd in his youth. The reference to 'the house of the Lord' in Psalms 23:6 may be a continuation of the figure of the host, and need not indicate a date after the building of the Temple.
Related Commentaries of Psalms 23:1
Psalms 23:1-6
1 The LORD is my shepherd; I shall not want.
2 He maketh me to lie down in greena pastures: he leadeth me beside the still waters.
3 He restoreth my soul: he leadeth me in the paths of righteousness for his name's sake.
4 Yea, though I walk through the valley of the shadow of death, I will fear no evil: for thou art with me; thy rod and thy staff they comfort me
5 Thou preparest a table before me in the presence of mine enemies: thou anointestb my head with oil; my cup runneth over.
6 Surely goodness and mercy shall follow me all the days of my life: and I will dwell in the house of the LORD for ever.c