Postgresql transaction fix