SELECT setval(pg_get_serial_sequence('users','id'), COALESCE(MAX(id),1)) FROM users;