Psalm 118:28 You are my God, and I will praise You; You are my God, I will exalt You.
David was under no illusion about God. He may have forgotten his duties toward God and set aside his praise from time to time, but he knew God was God!
For all the promises God had made to his descendants, David was thankful and tried never to forget them.
These sort of words come from the heart and allow us to see just how much he did love God.
It does not mean David was perfect; far from it. But he loved God and showed us all!