Psalm 139:1 (ESV) … “O Lord, you have searched me and known me!”
Although Psalm 139 deals with some of the highest and most important of all theological concepts, the omniscience, omnipresence, and omnipotence of God, it nevertheless has two practical aims that become clear at its close (vv. 19–24). First, the writer wants to separate himself from all who deliberately practice evil. Second, he wants God to search him out thoroughly and purge him of anything that might be offensive to God so that he might walk in the way everlasting. It is hard to think of any more practical reasons for theology than those.
The psalm’s seven stanzas fall into four easily recognizable parts: praise of God for his omniscience (vv. 1–6); praise to God for his omnipresence (vv. 7–12); praise to God for his omnipotence, especially in the creation of the psalmist himself (vv. 13–18); and a response to what has been said, indicating the two ways a person can relate to the all-knowing God (vv. 19–24). Each of these sections has six verses that fall into two parts each. The first four verses are descriptive; they introduce the main idea of the section. They are followed by two more verses that are reflective. Each stanza of this brilliant composition anticipates and leads into the ideas to be developed in the following verses. We will look at the first two of these sections (vv. 1–12) in this chapter and the last two sections (vv. 13–24) in the following chapter.
Looking at verse 1 we see the unique quality of the knowledge possessed by God is perfection. God knows all things, and he knows them exhaustively. We also know things, therefore we have some idea of God’s omniscience, but our knowledge is only partial and imperfect. 
Arthur W. Pink wrote,
God.… knows everything; everything possible, everything actual; all events, all creatures, of the past, the present, and the future. He is perfectly acquainted with every detail in the life of every being in heaven, in earth, and in hell.… Nothing escapes his notice, nothing can be hidden from him, nothing is forgotten by him.… He never errs, never changes, never overlooks anything.
A. W. Tozer expands this description by adding negatives.
God has never learned from anyone. God cannot learn. Could God at any time or in any manner receive into his mind knowledge that he did not possess and had not possessed from eternity, he would be imperfect and less than himself. To think of a God who must sit at the feet of a teacher, even though that teacher be an archangel or a seraph, is to think of someone other than the Most High God, maker of heaven and earth.…
God knows instantly and effortlessly all matter and all matters, all mind and every mind, all spirit and all spirits, all being and every being, all creaturehood and all creatures, every plurality and all pluralities, all law and every law, all relations, all causes, all thoughts, all mysteries, all enigmas, all feeling, all desires, every unuttered secret, all thrones and dominions, all personalities, all things visible and invisible in heaven and in earth, motion, space, time, life, death, good, evil, heaven, and hell.…
Because God knows all things perfectly, he knows no thing better than any other thing, but all things equally well. He never discovers anything, he is never surprised, never amazed. He never wonders about anything nor (except when drawing men out for their own good) does he seek information or ask questions. 
 Boice, J. M. (2005). Psalms 107–150: An Expositional Commentary (p. 1202). Grand Rapids, MI: Baker Books.  Arthur W. Pink, Gleanings in the Godhead (Chicago: Moody, 1975), 19.  A. W. Tozer, The Knowledge of the Holy: The Attributes of God, Their Meaning in the Christian Life (New York: Harper & Row, 1961), 61–62.