PG::UniqueViolation Problem during 3.1.0.beta4 upgrade

Thanks Jay
I was able to rebuild and get my website online again.

First as you suggested the solution is to reindex, fix and repeat until done. I used the following command to see how many

SELECT username_lower, count(*) from users GROUP by username_lower HAVING count(*) > 1;

it was giving me zero.

Of course there are many duplicated and wanted to know how many. so I slightly adjusted the query:

SELECT username_lower, count(username) from users GROUP by username_lower HAVING count(username) > 1;

This worked and returned about 50 duplicates, so I fixed them, reindexed rebuilt successfully.