SAN FRANCISCO -- Jhonny Peralta knew he hit it well. He didn't know how well until the ball landed in the seats.
Peralta's two-run homer produced the first runs scored by St. Louis in its first at-bat since June 18, a span of 14 games, leading the Cardinals past the reeling San Francisco Giants 7-2 on Thursday.
"I'd heard from the guys that you need to hit it hard to get it out here," Peralta said.
Carlos Martinez (2-3) earned his second win as a starter and added a two-run single for the Cardinals, who won their second straight after losing three in a row. Martinez allowed a run and five hits in five innings. He walked one and struck out six.
"We've had our struggles at the plate," Peralta said. "It was good to start it off in the first inning."
Madison Bumgarner (9-6) fell to 0-3 over his past four home starts after allowing five runs -- four earned -- and six hits over five innings. He walked three and struck out six.
Bumgarner also drove in a run for the Giants, who have lost 17 of 22 and fell out of first place in the NL West.
"You always want to play at home and I haven't pitched very good here all year," Bumgarner said. "I don't know what it is. You can't give in, you have to keep grinding."
Help could be on the way. The Giants optioned first baseman Adam Duvall to Triple-A Fresno after the game in anticipation of recalling Brandon Belt in time for Friday's game in San Diego.
"He's somebody we like having out there," Bumgarner said. "It's not going to do anything but help us."
Angel Pagan may return to the Giants lineup early next week, giving them some semblance of order at the top of the lineup.
Matt Carpenter continued ripping Giants pitching, extending his hitting streak against them to 11 games with a 2-for-4 effort. He has a .519 (28 for 54) career average against the Giants and has hit safely in 18 of his 20 games, including the post-season, against them.
"It's one of those crazy things," Carpenter said. "Luck has been on my side so far I guess."
Yadier Molina added three hits and Oscar Tavares, John Jay and Shane Robinson each drove in a run for the Cardinals.
Peralta's first-inning home run, after Carpenter drew a walk, put St. Louis ahead to stay.
"I was able to work the walk and Jhonny hit the home run," Carpenter said. "That kind of set the tone and we found a way to pile it on."
Bumgarner drove in a run for the Giants in the third, but then gave up three runs in the fourth -- two on a single from Martinez.
Robinson, pinch hitting for Martinez in the sixth, tripled home a run. Tavares added an RBI in the seventh.
The Giants loaded the bases with two outs in the fifth, but Martinez got Buster Posey on a swinging strike three to end the threat.
In the sixth, Tyler Colvin walked, Adam Duvall singled and Brandon Crawford punched a single into right field. An error allowed Colvin to score.
Sam Freeman, Seth Maness and Jason Motte combined to keep the Giants at bay.
NOTES: Giants INF Joe Panik batted second, where he hit for Triple-A Fresno, as manager Bruce Bochy tweaked the lineup. "He has some sense of comfort there," Bochy said. ... OF Hunter Pence hit lead off and OF Gregor Blanco was dropped to eighth. ... INF Marco Scutaro continues to make progress and if he's fine after playing for the second straight day for the Arizona Rookie League Giants, he could be elevated to Fresno by Sunday. . RHP Matt Cain (1-6, 4.38) pitches for the Giants when they open a three-game series at San Diego on Friday. He's 7-13 lifetime against the Padres. ... RHP Lance Lynn (8-6, 3.38) pitches for the Cardinals when they open a three-game set with the Miami Marlins in St. Louis. He's 2-0 with a 5.79 ERA against the Marlins. ... Cardinals OF Allen Craig was given a day off. He was hitting .176 on the road trip. ... Cardinals RHP Joe Kelly will make two more rehab starts and return after the All-Star Break. . 49ers head coach Jim Harbaugh met with Cardinals manager Mike Matheny after the game.