Locke (5-1) ran his scoreless innings streak to 15 with the performance, in which he collared the Brewers on three hits while striking out seven. The left-hander issued three walks.
Alvarez connected for a two-run shot in the second, staking the Pirates to a 3-0 lead, and added a bases-empty clout in the ninth as Pittsburgh racked up its 10th win in 11 games.
Andrew McCutchen also went deep for Pittsburgh.
Michael Fiers (1-3) was tagged for four runs on five hits in a four-inning effort for Milwaukee, which fell to 4-18 in May.
Carlos Gomez smack a pair of solo homers for the Brewers.
Britney Spears debuts 'Perfume' video
Wisconsin business offering 'therapeutic cuddling' forced to close