Fix some PgSQL schema issues

Bogdan, look please at this solution. If it's correct, I'll patch all supported previous versions.