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 benefitting from an untimely double fault for another break and serving out for victory in just over an hour and a quarter.
Earlier, Japan's Kei Nishikori narrowly avoided a second round defeat against Frenchman Adrian Mannarino before battling through 6-4 4-6 7-6(4).
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, in the deciding tiebreak, Nishikori raced into a 6-2 lead.
Still, Mannarino kept fighting, saving two match points before the Japanese finally wrapped up victory after two hours and 33 minutes.