Few fixes in the postgres backend.

see #589