DB Error: Duplicate entry 'xxxxxx' for key 'sessions_pkey'

Hey, i’ve got an error message after sign in to my OJS. After sign in, error show DB Error: Duplicate entry ‘xxxxxx’ for key ‘sessions_pkey’

I’ve tried to delete the session key, but still no result. What’s the solution of my problem?

In both OJS 2.x and OJS 3.x the session_pkey index is just sessions.session_id. This message would indicate that the primary key for that table is being duplicated.

When you “delete the session key”, what exactly are you doing?

What specific version of OJS are you using?

Now i’m using version 2.4.8.0

When i’m login, it is always show
DB Error: Duplicate entry ‘332d775e31544f92fa05d2668dc2102d’ for key ‘sessions_pkey’

This is not happen when i’m running it on localhost

The bug is resolved.

I just need to add php_value session.auto_start 0; in htaccess

Thanks

I have the same problem, could you please tell me where is htaccess file and how to add the value?

Regards.

Hi @gbcriado,

That would depend on your hosting provider’s configuration. I would suggest checking their knowledge base, and if they’re a large service provider, possibly StackOverflow.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi

I have the same problem if i delete the entry from the sessions table, it works for that instance, in the next click on any page or refresh of the ojs, it gives the same error.

what could be the issue?

I tried with the php_value session.auto.start 0; through .htaccess but i do not see any difference.

Appreciate your help on this.

Hi @Umadhar,

I would suggest checking your phpinfo output to ensure that the session auto-start is actually disabled by your .htaccess mechanism.

Regards,
Alec Smecher
Public Knowledge Project Team

Thank you for your immediate reply. Here is the phpinfo of my hosting environment:

http://tangentinfotech.com.fozzyhost.com/phpinfo.php

session.auto_start is already Off.

Why the duplicate issue is coming up? Any settings needs to be done? I am having this issue when i am moving the ojs from one hosting to another hosting.

Please guide and save me from this issue.

Thanks in advance and appreciate your help.

Hi @Umadhar,

Have you checked your PHP error log for any relevant entries – especially anything besides the message you already quoted?

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher ,

Please find the log here, Did not get the exact issue to fix it :

[Sat Jun 10 13:47:23.673742 2017] [lsapi:notice] [pid 467697] [client 122.172.129.23:35965] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n
[Sat Jun 10 13:48:11.410799 2017] [lsapi:notice] [pid 470967] [client 122.172.129.23:37678] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n, referer: AYUSHDHARA
[Sat Jun 10 13:49:07.555685 2017] [lsapi:notice] [pid 459236] [client 122.172.129.23:39677] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n, referer: Archives | AYUSHDHARA
[Sat Jun 10 13:49:22.096643 2017] [lsapi:notice] [pid 475945] [client 122.172.129.23:40242] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n, referer: Archives | AYUSHDHARA
[Sat Jun 10 13:49:25.105682 2017] [lsapi:notice] [pid 468020] [client 122.172.129.23:40359] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n, referer: Archives | AYUSHDHARA
[Sat Jun 10 13:49:38.289439 2017] [lsapi:notice] [pid 467697] [client 122.172.129.23:40799] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’\n, referer: Vol 3, issue 5: September - October 2016 | AYUSHDHARA
2017/06/10 13:51:57 [warn] 456084#456084: *55059038 an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/7/17/0000328177 while reading upstream, client: 66.249.69.207, server: ayushdhara.in, request: “GET /index.php/ayushdhara/article/download/154/172 HTTP/1.1”, upstream: “http://127.0.0.1:8080/index.php/ayushdhara/article/download/154/172”, host: “ayushdhara.in”
[Sat Jun 10 13:51:57.970529 2017] [lsapi:error] [pid 473274] [client 66.249.69.207:45924] [host ayushdhara.in] Backend fatal error: PHP Fatal error: Call to a member function getRequest() on null in /var/www/tangenti/data/www/ayushdhara.in/plugins/generic/usageStats/UsageStatsPlugin.inc.php on line 223\n
[Sat Jun 10 14:03:11.185643 2017] [lsapi:notice] [pid 504503] [client 188.233.132.1:41422] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘snmrq7smhgn313fq0gfejf0bv4’ for key ‘sessions_pkey’\n, referer: Login | AYUSHDHARA
[Sat Jun 10 14:03:11.392052 2017] [lsapi:notice] [pid 494521] [client 188.233.132.1:41428] [host ayushdhara.in] Backend log: ojs2: DB Error: Duplicate entry ‘snmrq7smhgn313fq0gfejf0bv4’ for key ‘sessions_pkey’\n, referer: http://ayushdhara.in/

I have two sites behaving this way right now including this and i do not have a solutions, What is causing this issue, why does it say Duplicate entry? Do we need to make sessions_id to be altered to not Primary Key? or is there anything in the code that we need to do? When the same session id is found for a request/refresh it should update the existing one but why it is throwing the duplicate entry as a new insert of the same session id. why it is happening? Please Please help me on this.

@asmecher,

I enabled the debug on and show stats on and here is the stack trace, It seems it is trying to insert, not sure whether it is the expected behaviour:

(mysql): SET NAMES ‘utf8’
(mysql): INSERT INTO sessions (session_id, ip_address, user_agent, created, last_used, remember, data, domain) VALUES (‘cuff3emf3rirk9qtkubgnlp6o5’, ‘122.172.129.23’, ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36’, 1497097561, 1497097561, 0, ‘’, ‘ayushdhara.in’)
1062: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’
ADOConnection._Execute(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
('cuff3…) % line 845, file: adodb.inc.php
ADOConnection.Execute(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
(?, ?, …, Array[8]) % line 226, file: DAO.inc.php
DAO.update(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
(?, ?, …, Array[8]) % line 88, file: SessionDAO.inc.php
SessionDAO.insertSession(Object:Session) % line 91, file: SessionManager.inc.php
SessionManager.SessionManager(Object:SessionDAO, Object:Request) % line 130, file: SessionManager.inc.php
DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’

Stack Trace:

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionDAO.inc.php line 88
Function: DAO->update(“INSERT INTO sessions (session_id, ip_address, user_agent, cr…”, Array(8))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionManager.inc.php line 91
Function: SessionDAO->insertSession(Object(Session))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionManager.inc.php line 130
Function: SessionManager->SessionManager(Object(SessionDAO), Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/classes/security/Validation.inc.php line 379
Function: SessionManager->getManager()

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/PKPPageRouter.inc.php line 66
Function: Validation->isLoggedIn()

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/Dispatcher.inc.php line 117
Function: PKPPageRouter->isCacheable(Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/PKPApplication.inc.php line 178
Function: Dispatcher->dispatch(Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/index.php line 64
Function: PKPApplication->execute()

Please let me know if something can be observed here to fix the issue.

Note:
Made it as Under Maintenance for now not to show errors to customers.

Hi @Umadhar,

Hmm, this is strange behavior – I’d suggest changing session_cookie_name in config.inc.php to something else to eliminate old cookies / cookie path changes as a cause. Make sure your session_cookie_path is set appropriately – it looks like you’re behind a reverse proxy, so this may be necessary. Anytime you change something in your configuration and want to test it, make sure you’re erasing the relevant cookie from your browser.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

Yes Really taking my time and killing me this issue. What if we make the session_id from sessions table makes non unique, does it harm anything.

I am trying your suggestions. What is the problem with the Reverse proxy, how do we resolve if that is the issue?

Hi @Umadhar,

The session ID needs to be unique – removing the constraint won’t resolve the problem.

If possible, I would suggest trying to access OJS without the reverse proxy being in the way. Unfortunately I can’t give you specifics on how to do this because there are many possible proxy configurations, but within our hosting environment here at SFU, it would normally mean accessing the hosting server directly (possibly at a different IP address and port than your front-facing proxy uses).

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher ,

I changed the session.save_path but it is not working but saying the folder needs to have permissions to write which i gave as 757 too. Please find the errors and stack trace on the portal directly:

http://ayushdhara.in/

With regards to Reverse proxy, if i take the dedicated IP Address, this will become direct access. If this is wrong understanding please let me know what is meant by direct OJS access?

One more question: in the sessionManager.inc.php do i need to make any chagnes to the following one at line 42:

ini_set(‘session.cookie_path’, $request->getBasePath() . ‘/’);

Attached a screenshot for your reference that the sessions are being written in the sessions/ folder as well but still the error being thrown.

Hi @Umadhar,

OJS configures PHP to use database-backed sessions (in the sessions table). It looks like your PHP configuration is for some reason still attempting to create file-based sessions. I suspect the cause of this is somewhere in your PHP configuration, but unfortunately I can’t spot it in the phpinfo() output you posted above. You might try something like StackOverflow to get hints on where to look.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

Based on the session.save_path the sessions are being stored in that folder which i set as per your instruction. Just wanted to understand, when the sessions are being managed through the database-blackened sessions, why do we need to worry about the session.save_path?

What i observed is, This is storing in the database as well as in the file based, not sure why and what is happening.

There is some setting which is causing problem for the sessions to set $this->userSession in SessionManager.inc.php if we come to know about it the issue will be fixed. You might have received lot of questions on this if you know already that would be great help and save my days…

Will the dedicated IP Address works for the reverse proxy issue?

Thank you for your responses and appreciate it.

Thanks and Regards,
Umadhar

Hi @Umadhar,

The session save path isn’t the setting I referenced. I was talking about a differently-named setting in config.inc.php, not php.ini.

If you see sessions being saved in the filesystem as you attempt to access OJS, then some aspect of your PHP configuration is preventing OJS from managing its own sessions, leading to the problem you describe. It appears to be something non-standard or unusual, and I’m afraid I’m not going to be able to debug it remotely. I would suggest talking with your server admin or inquiring on Stackoverflow.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

@asmecher,

Let me explain you:

session_cookie_name : I changed it.

session_cookie_path:
I searched the entire config.inc.php for the session.cookie_path i did not find any, i tried with path, cookie and session words search. So i set it in the .htaccess. If you think particular config parameter/variable please let me know that will help.

I do not see any change after it.

Please guide me on this…