David spent a lot of time at war with his enemies. Wars that were commanded by God to eradicate squatters in Israel's promised land. In spite of this command by God, and His blessings on military action, David still had fear. In spite of this fear, even more incredibly, David found time to praise God for the wonders He has done. David had this amazing realization that God's power and glory did not cease to be real in times where we think He may be distant. To praise God in time of trouble is a hard thing to grasp, especially when all you may be thinking about is taking your next breath. But in David's mind, God didn't stop being awesome or worthy of his praise.
The ninth Psalm paints a rather hopeless picture for those who refuse to turn to God, those who are wicked. They will be ruined, forgotten and destroyed with a vengeance. However, the righteous, those who praise God and walk in His covenant will be protected and blessed and provided for.
David appears to see God as his avenger of blood, a concept spoken of in Numbers 35. Someone who would avenge a murdered family member. That is a snapshot of the closeness David felt with God. That God would avenge David if anyone took his life. And its likely refuge cities would not apply.