Fix Postgre issues

This fixes 30545, 30282, 30132 and 29220

Fixes for 29220 and 30132 came from Elin - but her branch was out of sync and I wanted to get these postgre issues in before 3.1!