139:19-22 With these thoughts in his mind, David turned his attention to his present situation. His enemies were attacking him. He prayed that the Lord would slay those who were trying to kill him (v. 19). These enemies were evidently hostile to God as well as David and were using the Lord's name for an evil purpose. In loyalty to God David affirmed his hatred for those who hated God. By "hate"David meant he rejected them (cf. Mal. 1:3).
139:23-24 The psalmist concluded with a prayer that God would search Him so it would be clear that he was not like these enemies. Thus he ended this psalm as he began it with a reference to God's searching knowledge (cf. v. 1). David wanted God to test him as a refiner tests metal to show that he was loyal to the Lord. Since God knows all, he would know David's anxious thoughts. He would discover no pain that God's afflicting him for doing wrong had caused him. Consequently God would preserve his life.
Knowledge of God's attributes can bring great peace into the lives of believers. His comprehensive knowledge, personal presence, and absolute power are all working for the welfare of His people. Therefore we should commit ourselves to Him in loyalty and resist those who oppose Him.