Interpreting Psalm 139 starts with a moral decision: are vv.19-22 (vv.18-21 in the Book of Common Prayer) templates for our prayers? Some traditions in both Testaments would support an affirmative answer (the imprecatory psalms, Jehu’s religious purge [2 Kings 10:18ff], Paul’s comments regarding his opponents in Galatians [1:9; 5:12 etc]). Others in both Testaments a negative answer (psalms like 143 [“for no one living is righteous before you”], Jesus’ command to love the enemy [Mt 5:44]).
My answer is negative, placing the verses in a position analogous to the many eloquent but wrong-headed speeches of Job’s friends. But why in God’s providence is it still there? A reminder, I think, that all of us remain capable of sentiments and acts good, bad, and ugly. Once we start cancelling what we don’t like we end up—if we’re consistent—cancelling ourselves (recall the guillotine). Better: that God got the divine hands dirty dealing with the author(s)/editor(s) of Psalm 139 gives me hope that God’s hands will keep dealing with me.
The Japanese have a custom of repairing pottery in a way that highlights the fractures with precious metals (kintsugi). Perhaps Psalm 139 is an exercise in kintsugi (like ourselves?).