David builds an altar
In order to stop the pestilence, David bought a threshing floor in Jerusalem and sacrificed on an altar there.
Key passages
2 Sa 24:18–25

Then Gad came to David on that same day and said to him, “Go up and erect an altar to Yahweh at the threshing floor of Araunah the Jebusite.” So David went up according to the word of Gad, as Yahweh had commanded. Araunah looked down and saw the king and his servants coming over to him, …

1 Ch 21:18–30

Now the angel of Yahweh had spoken to Gad to say to David that David should go up to erect an altar for Yahweh on the threshing floor of Ornan the Jebusite. So David went up at the word of Gad that he had spoken in the name of Yahweh. Now Ornan was threshing wheat, and …

See also
2 Ch 3:1;