Fix bugs in pgsql support.