Migrate db to pgsql and clean up, fix #2, fix #3, fix #4