Notice the contrasts given by David. In verse 17, David is talking about how the whole world benefits from our relationship with God. In verses 18 and 19, David jumps back to the benefits to believers who call on Him.
We do not struggle with the concept of how God is right (that is "righteous") in all He does. He allows evil to exist, ultimately to be defeated and bring Him glory. However, we do struggle with the question regarding how can God be "nigh" (near) and show love toward all He has made? Yes, most people do suffer due to the evil that exists in this world. Explaining evil is one of the most difficult aspects of any religion let alone Christianity. The quick answer is that due to mankind's sinful nature, evil exists in this world and God allows it. He does this in order to draw us to Him for protection.
That thought will lead us well into verses 18 and 19. How is God near to those who trust in Him, if God is everywhere? It is not about God's physical location. Rather, it is about those who do trust in Him, can talk to Him and let Him guide their lives. Verse 19 says, He fulfills our desires. Obviously God does not give us everything we want. The point is if we desire to do His will, He gives us the desire of His will and in that sense He watches over all who call on Him.