St. Louis Cardinals’ Paul Goldschmidt round third on his way to score during the first inning of a baseball game against the Arizona Diamondbacks Sunday, July 14, 2019, in St. Louis. (AP Photo/Jeff Roberson)

ST. LOUIS (AP) — Adam Wainwright made the most of a couple of extra days of rest.

Paul Goldschmidt homered, Wainwright pitched seven scoreless innings, and the St. Louis Cardinals held on to beat the Arizona Diamondbacks 5-2 on Sunday.

Wainwright (6-7), who was scratched from Friday’s start due to back spasms, relied on a mixture of cutters, change-ups and curve balls. He allowed four hits, walked one and struck out seven as he improved 4-0 in day starts this season.

“There’s still some things I can do better, a few 2-0 counts that I had today that I would like to avoid to some pretty good hitters,” Wainwright said. “They had first and third a couple of times, we got out of it with a couple good pitches that we needed to make. Other than that, I’m throwing the ball like I expect to throw the ball.”

Arizona trailed 5-0 going to the ninth before Domingo Leyba and Jarrod Dyson had RBI singles against John Brebbia. The Diamondbacks had the bases loaded with two outs, but Carlos Martínez got Eduardo Escobar to hit a fly ball to center for the final out for his fifth save.

“It’s exactly the game were looking for,” Cardinals manager Mike Shildt said. “It’s exactly the game we’ve demonstrating. It gets punctuated with the run production, simple as that.”

Wainwright helped himself out offensively by walking and scoring to start a three-run third inning rally and he also laid down a sacrifice bunt leading to Matt Carpenter’s sacrifice fly as the Cardinals tacked on their fifth run in the fourth.

The 37-year-old and 3-time All-Star had some extra motivation facing Diamondbacks starter Zack Greinke, who beat Wainwright in the only two games the standout hurlers faced each other in 2012 and 2013.

“My first focus is winning a game against that team first, but especially against beating Zack because he’s such a great competitor, a great pitcher,” Wainwright said. “I wanted to get him on my list. I know I’m on his list.”

Goldschmidt’s 416-foot two-run shot into the upper deck in left field gave the Cardinals a 4-0 lead in the third. Yairo Muñoz started the rally with a single that drove in Wainwright, and advanced to third on Nick Ahmed’s throwing error.

It was Goldschmidt’s first career home run off of Greinke.

“He can throw any pitch at any time so as a hitter you can’t guess, just try to react,” Goldschmidt said. “Luckily I was able to get a couple of hits.”

Tyler O’Neill continued his RBI barrage by driving home Goldschmidt with a double that hugged the left field line to make it 1-0 in the first inning, ending Greinke’s 14-inning scoreless streak. O’Neill drove in all four Cardinals run in a 4-2 win on Saturday night.

Greinke (10-4) gave up five runs in six innings. The loss snapped a five-year July winning streak for the Arizona ace, who entered the game 14-0 with a 1.34 ERA in his last 18 starts in the month dating back to July 25, 2014.

“It’s a game of inches,” Greinke said. “Made some mistakes at the wrong times, some critical moments and they capitalized.”