Posey ends long homerless drought, Giants edge Pirates 3-2