Water
The idea that medieval people drank beer because they did not have access to safe drinking water is a complete and unfounded myth.
To quote <PERSON> and <PERSON> in their book Misconceptions About the Middle Ages:
“There is no specific reason then to believe that people of the time drank proportionately less water than we do today; rather, since water was not typically sold, transported, taxed, etc., there simply would have been no reason to record its use."
There are plenty of articles out there discussing this topic.
Small beer/ale (the type of beer drunk regularly in the Middle Ages) had a small alcohol content, typically less than 1% and never more than 3%. This would have had some anti-bacterial effect, but in given the life-span of small ale in the Middle Ages (it was usually drunk as soon as it was ready with little to no ageing process) I doubt it would have had too great an effect on the liquid's propensity to spoil (See <PERSON>'s link in comments on alcohol affect on bacteria over time). As a brewer of regular strength beer, I can tell you that some bacteria will infect a barrel of ale just as readily as a barrel of water.
Having said that, small ale in the medieval period was on some level less likely to make the drinker ill, solely for the fact that the water/wort used to make the ale was boiled before fermentation. 537
But this pales in comparison to the real reason small ale was drunk in such quantities in the Middle Ages: Medieval people drank small beer because it was a great way to squeeze as many calories out of their grain as possible. Off-cuts of stale bread, spare unusable grain were all 'recycled' back into small ale in an attempt to fuel a hungry population.
Without the invention of small ale/alcohol, medieval society would simply just continue drinking water, but in larger quantities. The two articles I have linked do a good job of explaining this, and if you want to make water safer in your world, just make boiling it more prevalent. It is already theorized that medieval folk knew that boiling made water safe through holistic means, just didn't know why :) 130