We consider several modified versions of the Positivstellensatz for global analytic functions that involve infinite sums of squares and/or positive semidefinite analytic functions. We obtain a general local-global criterion which localizes the obstruction to have such a global result. This criterion allows us to get completely satisfactory results for analytic curves, normal analytic surfaces and real coherent analytic sets whose connected components are all compact.