move postgres setup under if statements