This is a song about a war. In it, David the king is receiving various kinds of advice, some of which tells him that he should "flee as a bird to" his "mountain," possibly a mountain fortress outside Jerusalem. The thought is that he could be safe there.
David's answer to this advice is in three parts. First, he points out that fleeing to such a mountain fortress won't do any good, because the "bow" of the wicked is already "bent," so that if David exited Jerusalem he would be shot upon leaving. Secondly, David points out that if he left Jerusalem, then Jerusalem itself would be taken by the enemy. This would be disastrous, because Jerusalem is the hub, the center, or to use the language used here, the "foundation" of Israel, and if it's taken by the enemy, there really wouldn't be much use fighting any longer - Israel would be defeated already.
Thirdly, David doesn't need to "flee." Why? Because "The Lord is in His holy temple, The Lord's throne is in heaven; His eyes behold, His eyelids test the sons of men." In other words, the Lord knows all about David's predicament, and He can, at any time, bring His righteous wrath upon David's enemies - and the war will be over!
David points out that "the Lord tests the righteous - but the wicked and the one who loves violence His soul hates. Upon the wicked He will rain coals - fire and brimstone and a burning wind shall be the portion of their cup." He's just expressing the fact that he doesn't need to worry, because the Lord can and will take care of the wicked enemy. He's just saying, in other words, that if he, David, is righteous, then the Lord will take care of him. As he says, "the Lord is righteous. He loves righteousness; His countenance beholds the upright." David needn't worry.
David leads the people in singing this psalm so that they too might place their trust where it really belongs - not in fortresses, not in armor, not in horses, but in the Lord. All they have to do is to be sure they are righteous before Him Who alone is their safety.
How about you? Do you get worried about what human beings can do to you? Your best course of action is to busy yourself in becoming more and more righteous before God. When you're doing that, no human being can harm you, for God will take care of you quite adequately! Fleeing won't help, but righteously trusting God will.