The Padres improved to an MLB-best 7-0 in interleague play this season. The Astros have lost five of six overall.
Pham's homer came in the third inning and Tatis tied it at 2-all with his solo shot in the eighth.
''Tatis and Pham get the solo homers and once we got into extra innings it was just a lot of guys grinding it out,'' manager Jayce Tingler said. ''Everybody giving everything they've got and it's nice when everything works out.''
It was tied at 3-all to start the 11th when Victor Caratini singled off Brooks Raley (2-3), setting up RBI singles by Ha-Seong Kim and Pham.
Brandon Bielak relieved and Jake Cronenworth hit an RBI single with one out and Tatis added a sacrifice fly that made it 7-3 before things really got out of hand.
Jorge Mateo reached on an error by second baseman Jose Altuve and a double by Wil Myers sent another runner home. Jurickson Profar's single on a ground ball to center field scored two more.
''We had the ability to really grind out at-bats to put those guys away,'' Myers said. ''It's great to see that this team has the ability to really explode in an inning.''
Manny Machado was 0 for 3 with three strikeouts and a walk in his first start since May 19 when he slapped a double off Ryne Stanek to score Pham and make it 3-2 to start the 10th.
Machado, who has been hampered by a shoulder injury, pinch hit in the last two games.
The Astros tied it in the bottom of the 10th when Alex Bregman scored on a sacrifice fly to right field by Chas McCormick off Mark Melancon (1-0) to make it 3-all. Altuve flied out with the bases loaded to end the inning.
Though Melancon was credited with the win, he also got a blown save, his first of the season after converting his first 17 opportunities.
The Astros left 15 men on base and went 0 for 10 with runners in scoring position.
''It was a tough night at the ballpark,'' manager Dusty Baker said. ''The gates opened up and they got hit after hit. They got a number of hits with runners in scoring position and we didn't.''
McCormick hit a two-run homer in the fourth.
There was one out in the eighth when Tatis launched an off-speed pitch onto the train tracks atop left field for his 14th homer to tie it at 2.
The Astros got four innings out of Framber Valdez in his season debut after he fractured his left index finger in his first spring start. He allowed two hits and a run with four strikeouts.
Cristian Javier, who was moved to the bullpen with the return of Valdez, took over and gave up two hits and a run in four innings.
San Diego starter Dinelson Lamet yielded five hits and two runs with two walks in three-plus innings in his first start since May 11 after making two relief appearances.
Padres first baseman Eric Hosmer was hit by a pitch on the upper right arm in the second inning. He remained in the game to run the bases before he was replaced in the lineup by Mateo in the bottom of the inning.
Tingler said that X-rays were negative, but that Hosmer's arm was swollen and sore after the game.
Padres: C Austin Nola was placed on the 10-day injured list with a sprained knee on Friday. ... C Webster Rivas, a 30-year-old who played 11 years in the minors, was called up from Triple-A El Paso to take his place and made his major league debut on Friday night. He went 0 for 3.
Astros: DH Yordan Alvarez missed a second straight game with a sore right wrist. ... OF Michael Brantley was placed on the injured list on Friday, retroactive to Tuesday, with tightness in his right hamstring. ... LHP Kent Emanuel was placed on the injured list, retroactive to Wednesday, with left elbow soreness. ... C Jason Castro was placed on the injured list, retroactive to Tuesday, with left Achilles tendon soreness.
HOME RUN MCCORMICK
McCormick has just nine hits this season, but four of them are home runs. His three RBIs on Friday night tied a career high for the rookie.
Houston's Jake Odorizzi (0-2, 10.13 ERA), who has been out since April 24 with a strained muscle in his right arm, will come off the injured list to start against Yu Darvish (5-1, 1.75) when the series continues Saturday.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.