Fatal error: Duplicate entry '0' for key 1 query: INSERT INTO sessions (uid, sid, hostname, timestamp) values(0, 'sessionIDisdeleted', 'IPaddressdeleted', 1109177779) in /home/asturlib/public_html/includes/database.mysql.inc on line 125

This was related to somebody trying to login and a >5000 rows session table ( never cleared by cron?). Nothing but this error came up site became inusable.

I emptied the session table and that fixed it, but I wonder what was behind it. That's why I marked as bug.

Comments

chx’s picture

stephenhendry’s picture

bslade’s picture

Version: » 4.6.0
Status: Closed (fixed) » Active

I don't understand this error:

Duplicate entry '0' for key 1 query: INSERT INTO sessions (uid, sid, hostname, timestamp) values(0, 'sessionIDisdeleted', 'IPaddressdeleted', 1109177779)

Assuming key 1 is the first index on "uid", it's not a primary or unique index. How can the database give an error for a duplicate entry when there's no uniqueness constraint in the index? Is this indicative of database corruption? Maybe some sort of mysql bug that gets exercised when there's a large number of duplicate entries in a non-unique indexed field? (eg. a gazillion zero's in the sessions.uid field for non-logged in Drupal clients)

On another site, after getting this error, they cleared out the sessions table (and maybe ran one of the consistency check commands) and this error went away (I'm a little fuzzy about exactly the db admin did)

Ben in DC
PublicMailbox at BenSlade dot com

stevryn’s picture

I had plenty of these errors and eventually found a post on here, look at the sequence table, that is where the "next" available number is determined. It's been a while so I dont exactly remember what I did, but check into sequences....

jairo.serrano’s picture

The same error, non-logged user, but the site it's down.

Fatal error: Duplicate entry '8cf2d0cfa89d20de162b37887cda4ba4' for key 1 query: INSERT INTO sessions (sid, uid, hostname, timestamp) VALUES ('8cf2d0cfa89d20de162b37887cda4ba4', 0, 'IPADDRESS', 1123014751) in /home/drupal/includes/database.mysql.inc on line 66

alexis’s picture

Any update on this? I'm receiving a email message from cron saying:

user error: Duplicate entry 'cron_busy' for key 1
query: INSERT INTO variable (name, value) VALUES ('cron_busy', 'b:1;') in /home/felafacs/public_html/includes/database.mysql.inc on line 66.

Which I think is part of the same problem. I'm using Drupal 4.6.2 on Red Hat Linux Enterprise 3.

Regards!

tomski777’s picture

Got the same problem today. The whole site went down after deleting a user & even when I emptied the sessions table the error was still there.

I got things up again by changing a newly added session UID to 1 (it was previously at set at 0). Ita be good to know whats causing this...

tomski777’s picture

Ok, I jumped the gun my above fix didn't work after all but this posting solved everything. Apparently its to do with there being to "user 0" in the users table.

tomski777’s picture

sorry- try this link:
/node/21120

magico’s picture

Is this still a problem?

magico’s picture

Status: Active » Closed (fixed)

To old and to quiet.

DiOne-1’s picture

You must use auto_increment for the primary key ;)

snowstorm’s picture

this cron error showed up after my drupal db was migrated to a new server.

I already haver user '0' in my users table.

I fixed the problem by emptying my sessions table(sessions table stores all the users'(logged-in or non-logged-in session info)