Fresh from earning his 100th ATP singles title a week ago in Dubai, the Swiss fourth seed repelled a tough second set challenge from the world No. 85 to book his third-round place.
World number two Rafa Nadal brushed aside American Jared Donaldson 6-1 6-1 and will next face Diego Schwartzman after the Argentine beat Roberto Carballes 6-3 6-1.
Federer to auction off Grand Slam memorabilia
Earlier in the day, Japan's Kei Nishikori narrowly avoided a second round defeat to Frenchman Adrian Mannarino before battling through 6-4 4-6 7-6(4).
Federer said he was happy to get into his stride early in the tournament.
"For the first round I actually felt really good," he told reporters. "If I maybe would have served a little bit better, I think things would have gone faster.
But at the end it was a tough second set, and it's maybe exactly what I needed.
Federer, who won the last of his Indian Wells titles two years ago but lost in the 2018 final, used his backhand slice to keep Gojowczk from gaining any rhythm in the first set. Yet the second proved more of a challenge as the German saved four break points in his first service game, then used his momentum to break for a 3-1 lead. Federer immediately broke back before later benefiting from an untimely double fault for another break and serving out for victory in just over an hour and a quarter.
World number seven Nishikori was not at his best, with the left-handed Mannarino's flat groundstrokes neutralising his attacks and the Frenchman seemed to be heading for victory when he served for the match at 6-5.
Yet he double faulted on the third break point he faced in the game and Nishikori raced into a 6-2 lead in the deciding tiebreak.
Still, Mannarino kept fighting, saving two match points before the Japanese finally wrapped up victory after two hours and 33 minutes.
"I was really focused on that last tiebreak," Nishikori said.
I think we both played good, and I think in the tiebreak I played the best tennis.
Eighth seeded American John Isner swept past Australian Alexei Popyrin 6-0 6-2, 10th seeded Croatian Marin Cilic beat Dusan Lajovic of Serbia 6-3 6-4, while Russia's 14th seed Danill Medvedev beat American Mackenzie McDonald 7-5 6-0.
Federer 'lagging behind' with fitness, but 'big titles' still the aim
Federer 'probably third or fourth best player on clay' but can he win Roland-Garros?