The Psalm is one of repentance, and is rooted in the story of David, Nathan, and Bathsheba. As it goes, King David spied a beautiful woman bathing from the roof of his palace, while all the other men were off at war. Enraptured, David sent for the woman and pursued her as a lover despite her being married to one of his captains. When she revealed she was pregnant, David realized his reputation would be destroyed -- and so he attempted to sully it further, by calling for Bathsheba's husband Uriah to return from the front. David then encouraged Uriah to spend some family time with his wife, but Uriah refused; how could be he comfortable in bed with his wife when his men were out on the lines? Uriah persisted in this noble refusal even after David got him liquored up, so the king sent Uriah to the roughest part of the lines out of desperation. There he died, David married Bathsheba, and everything stayed hush-hush.
Until....a preacher named Nathan showed up and delivered to David a sad story about a rich man who wanted to entertain some guests, who so decided to seize his poor neighbor's pet lamb and kill it for dinner, rather than departing with any of his own stock. David, incensed, roared that the man should be put to death, at which point Nathan replied....thou art the man. Enter the Psalm. I've linked to the full version there, but here's a small portion:
Behold, thou desirest truth in the inward being;
therefore teach me wisdom in my secret heart.
7 Purge me with hyssop, and I shall be clean;
wash me, and I shall be whiter than snow.
8 Fill[b] me with joy and gladness;
let the bones which thou hast broken rejoice.
9 Hide thy face from my sins,
and blot out all my iniquities.
10 Create in me a clean heart, O God,
and put a new and right[c] spirit within me.
11 Cast me not away from thy presence,
and take not thy holy Spirit from me.
12 Restore to me the joy of thy salvation,
and uphold me with a willing spirit.