explort LANG only when determining version

even if LANG is assigned inside a function, it affects
the rest of the script, which causes problems during
the postgresql upgrade