David, as a shepherd, had a lot of time to observe the heavens and let the wonders of God sink into his spirit. He saw them day and night. Look at his descriptions. Indeed the heavens do declare the glory of God.
It was in the fields that he learned the statutes of God and the truth thereof. His apprenticeship was nearly perfect because it was uninterrupted by the things of men.
David only got into trouble when he was embroiled in the king's house and the affairs of men. In the fields, alone with God, it was a different story. There was nothing to stand between him and his knowledge of God and God's sovereignty.
In keeping the Lord's statutes there is great reward.
He closes with the prayer that all of us must have in our hearts.
May the words of my mouth and the meditation of my heart be pleasing in Your sight, O Lord, my Rock and my Redeemer.
In Jesus' most precious name.