This psalm references the narrative in 1 Samuel 21-22. The story is filled with violations against the Covenant. Doeg was an Edomite, a foreigner from a tribe notorious for treachery and shocking immorality at times, though obviously he was a convert under the Law. Saul’s reign was more like that of a primitive tribal warlord than an actual king. Doeg was his chief herdmaster with heavy responsibilities but not treated as a counselor, especially in national politics and warfare. Saul was going insane and Doeg was ambitious to ingratiate himself, so he tattled about David’s quiet visit to the priest, Ahimelech. For this, Saul permitted Doeg to slaughter the inhabitants of the priestly village of Nob and keep the plunder. David’s song of curse on him was not for telling the truth about what he saw, but for Doeg’s self-serving and unjust nature.
It would be typical of treacherous people to enjoy the sorrow and agony of their enemies. Such a man as Doeg would also crow about his rise in status and wealth, all the more so at the cost of lives for which he was contemptuous. David wastes no effort trying to explain why God should protect him and let the entire priestly village be murdered. What he does understand is Jehovah’s promise to protect him personally and make him king. He’s quite humble about it, but seizes the mission implied by this calling while waiting until God deals with Saul His own way. He curses Doeg based on God’s past miracles and upon His revealed character in the Law.
Where Doeg had snickered about his own corrupt prosperity for a short time, the servants of God would live long marveling at divine wrath on Doeg. They would have the last laugh, mocking such an evil man. Thus, David celebrates that God has placed him as an olive tree, the ancient symbol for one of the two primary offices witnessing of His Law and His glory (the other office is High Priest). Rather than trust in his ambition and talent, David always waited on God to deliver him and provide for the mission. God’s loyalty is the ultimate contrast to Doeg’s treachery.
David’s final line is celebration: We who trust in God enough to follow His will have already tasted the goodness of His mercy.