Refactor the code of pgconf.sh