Postgres fixes

@sminnee @ajshort @simon_w Its important to get this reviewed and merged quickly since it prevents module builds from effectively checking Postgres+3.1 compatibility, making it more likely that build breakages there will be ignored completely.