This was because of a cultural obligation in ancient hebrew culture:
If a man dies without a son (to inherit his name, property, and lands), then his brother was to stand in, and perform the needful to supply that heir in his brother's stead.
This was intended to be a one-time kind of thing, for the sole purpose of this utilitarian objective. In the case of Onan, the guy was abusing this cultural requirement to bang his brother's widow repeatedly, denying her the child (by said pulling out.) God punished him for the transgression.
Despite what many strange people may claim, it is not about wasting semen on the ground, or a prohibition against non-reproductive sex in general. It was a prohibition against abusing what was meant to be a solemn familial duty, into a license to fuck somebody other than his wife, while denying the actual intended result (which as the whole reason for the practice in the first place), and likely to try to claim his brother's property and lands once the woman became too old to bear children.
As far as I know, there is precisely zero prohibition against non-reproductive sex, or against masturbation in the bible. The only restriction is that sex is meant to be 1) with people, 2) with the opposite sex and 3) after marriage. Exactly what kind of kinky crazy assed sex that married couple wants to do is completely unrestricted.
In terms of alcohol consumption, the bible actually ADVOCATES for drinking wine, at least in moderation. See for instance, 1 Timothy 5:23.