King David declares to G-d, "Your rod and your staff – they comfort me" (Psalm 23:4). "Staff" is a leaning stick, like the cane that an old man leans on. As such, "staff" symbolizes the comforting presence of G-d, which King David could lean on during all his troubled times. "Rod" symbolizes the punishment stick. King David in effect says to G-d, "Whether You console me and resemble a staff, or whether You torment me and resemble a rod, I am comforted by Your presence." Such a righteous man knows the value of the "rod", which is nothing other than the seemingly bad.
King David, as a three-year old shepherd, killed both a lion and a bear that threatened his flocks. As a twelve year old, he killed the giant Philistine warrior Goliath. David remained undaunted. Only one thought scared him: "Don't cast me away from you, G-d, and don't remove your spirit of holiness from me" (ibid. 51:13). King David's only fear in life was losing the proximity of G-d.
Just as a gold-medal Olympic sprinter cannot be a world champion without supreme effort, King David could not have become G-d's anointed, the head of the messianic dynasty, and role model for subsequent generations to this day, without the many arduous experiences in his life.
When you're able to treat the trying situations of your life as precious gifts designed to enhance your spiritual and emotional growth, then you're well on the way to inner peace.