“Do I not know that today I am king over Israel?”
2 Samuel 19.22
King David is returning to Jerusalem after the whole Absalom mishap. He knows he is going back to be king, but there might be a little messy housekeeping to do, and he has lost one of his sons after treason against him.
As King David was leaving, Shimei came out and shouted curses down on him. He told him he was ungodly and a man of blood. David’s men offered to kill him, but David didn’t object. It seems like he let Shimei continue to rain down curses and ROCKS and DIRT on top of all of them. He said something mysterious about maybe God told him to do it, so don’t stop him.
Upon returning to Jerusalem, Shimei is one of the first people to come to David and his men and beg for mercy and confess and seek peace. David could have easily hacked his head off, and his men with him wanted him to. 
“Do I not know that today I am king over Israel?” So the king said to Shimei, “You shall not die.” And the king promised him on oath.”
(2Sam 19:22-23 NIV)
David is like, “this guy said a lot of stuff, and I can’t really argue that is wasn’t true, but now I’m the king, I know who I am, and little curse-boy can say all he wants. He is here begging for mercy and I’ll give it. I don’ t need the heads of my weakest enemies to show I’m king.”
then Mephibosheth comes along, and he is begging for mercy too. He’s been betrayed, or so he says, by his servant. it looks believable enough to David, but so does the story of his supposed betrayer Ziba, so instead of punishing either one, he splits their plunder between them. Then Meph gives up his share to Ziba. very curious. Could it be because Ziba told the truth and if Meph gets half his land, Ziba will come and kill him? Or could it be that Meph doesn’t care about all that inheritance, because he’s back with the king, and that’s all that matters for him? I guess it could go either way. Only God knows such motives.
Either way, in all of these cases, David knew who he was and didn’t have to show it through vengence. He showed who he was through his mercy.