In this science fiction short,
"Perchance to Dream" aka "Asleep in Armageddon" by Ray Bradbury, first published in Planet Stories, Winter 1948, available at the Internet Archive.
a man ends up marooned - perhaps his companions died, don't recall.
A spaceman, flying solo in his rocket ship, walks away from a crash-landing on an asteroid with a breathable atmosphere. (Bradbury was not known as a hard sf writer.) He radios for help:
Sale pried himself out of the small airlock and stood breathing the atmosphere. Luck. Sheer luck. The air was breathable. An instant's checking showed him that he had two months' supply of food with him. Fine, fine! And this—he fingered at the wreckage. Miracle of miracles! The radio was intact.
He stuttered out the message on the sending key. CRASHED ON PLANETOID 787. SALE. SEND HELP. SALE. SEND HELP.
The reply came instantly: HELLO, SALE. THIS IS ADDAMS IN MARSPORT. SENDING RESCUE SHIP LOGARITHM. WILL ARRIVE PLANETOID 787 IN SIX DAYS. HANG ON.
Sale did a little dance.
The place is haunted / inhabited by nightmares
Yes, it's haunted by the ghosts of ancient warriors from the planet whose destruction resulted in the asteroid belt. Spaceman Sale can fight them off while he's awake, but they take over his mind and turn it into a battleground when he sleeps:
At last, at last, sang a high voice. Now, now. The long time, the waiting. Over, over, sang the high voice. Over, over at last!
It was like being under sea. Green songs, green visions, green time. Bubbled voices drowning in deep liquors of sea tide. Far away choruses, chanting senseless rhymes. Leonard Sale stirred in agony.
Mine, mine, cried a loud voice. Mine, mine! shrieked another. Ours, ours! shrieked the chorus.
The din of metal, the crash of steel, the conflict, the battle, the fight, the war. All of it exploding, his mind fiercely torn apart!
Eeeeeeee!
He leaped up, screaming. The landscape melted and flowed.
A voice said, "I am Tylle of Rathalar. Proud Tylle, Tylle of the Blood Mound and the Death Drum. Tylle of Rathalar, Killer of Men!"
Another spoke, "I am Iorr of Wendillo, Wise Iorr, Destroyer of Infidels!"
The chorus chanted, *And we the warriors, we the steel, we the warriors, we the red blood rushing, the red blood falling, the red blood steaming in the sun—
Leonard Sale staggered under the burden. "Go away!" he cried. "Leave me, in God's name, leave me!"
Eeeeeeeee, shrieked the high sound of steel hot on steel.
Silence.
He stood with the sweat boiling out of him. He was trembling so violently he could not stand. Insane, he thought. Absolutely insane. Raving insane. Insane.
that he can avoid only by staying awake, which he does for many days with will-power and drugs.
Now that he was feeling better, it was all silly. All I have to do, he thought, is stay awake six nights. They won't bother me that way. When I'm awake, I'm dominant. I'm stronger than those crazy monarchs and their silly tribes of sword flingers and shield bearers and horn blowers. I'll stay awake.
But can you? he wondered. Six whole nights? Awake?
There's coffee and medicine and books and cards.
But I'm tired now, so tired, he thought. Can I hold out?
Well, if not . . . There's always the gun.
After many days of this, he is "rescued" and despite protest is given an injection to help him sleep.
"No sedative, no sleep, please, don't, don't, don't!" screamed Sale, trying to get up. "You don't—understand!"
"Take it easy, old man, you're safe among us now, nothing to worry about," said the rescuer above him.
Leonard Sale slept. The two men stood over him.
Insanity soon follows ...
As they watched, Sale's features changed violently. He groaned and cried and snarled in his sleep. His face was riven with emotion. It was the face of a saint, a sinner, a fiend, a monster, a darkness, a light, one, many, an army, a vacuum, all, all!
I believe the story was written first person, like a diary.
The story is told in the third person, but the narrator reports the spaceman's thoughts in the first person:
I'll play solitaire until dawn, he thought. I'll sit up and drink hot black coffee and play solitaire, no cheating, until sunrise.