Duplicate key value errors in log while being on the site

(Evert Meulie) #1
`Job exception: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_users_on_email"
DETAIL:  Key (lower(email::text))=(emeulie@gmail.com) already exists.
: UPDATE "users" SET "last_seen_at" = '2016-04-27 06:07:08.139024' WHERE "users"."id" = 2`

Seeing these while I’m logged in on my site. Can I repair that table somehow?

(Jeff Atwood) #2

I’d start by removing the duplicate user – we key users by email so dupe users by email is a very, very bad thing.

(Evert Meulie) #3

Sounds like a logical plan :slight_smile:

When I search in admin on emeulie@gmail.com , only 1 account appears. How do I locate/remove that duplicate account?

(Dean Taylor) #4

Any ideas how you got into this odd situation? DB Import?

Before you do anything - make sure you have a backup

You’re probably going to have to use an SSH console / terminal…

SSH into the server and run the following one line at a time:

cd /var/discourse/
./launcher enter app
su - postgres
psql -d discourse

This will get you to the “PSQL interactive terminal” where you can execute queries.

Something like this will display the details of the two accounts:

SELECT id, username, created_at, last_seen_at FROM users WHERE email = 'emeulie@gmail.com';

(make sure you include the semi-colon on the end)

Here is where you are going to want probably report back what you see.

To exit the SQL console type: \q and press enter.