Skip to content

duplicate key value violates unique constraint "oc_preferences_pkey" on every login #23213

Closed

Description

@spitzlei

Steps to reproduce

  1. Login to Owncloud Website
  2. Open postgresql Serverlog

Expected behaviour

No Error in logs

Actual behaviour

Logfile is being spammed with errors:
2016-03-14 09:48:10 GMT STATEMENT: INSERT INTO "oc_preferences" ("userid", "appid", "configkey", "configvalue") VALUES($1, $2, $3, $4)
2016-03-14 09:48:34 GMT ERROR: duplicate key value violates unique constraint "oc_preferences_pkey"
2016-03-14 09:48:34 GMT DETAIL: Key (userid, appid, configkey)=(testuser, files, quota) already exists.

(I already cleaned up the table, entries being set after next login. After logout und relogin Errors appear again).

Server configuration

Operating system:
Debian 8.3

Web server:
Package: apache2
Version: 2.4.10-10+deb8u1

Database:
Package: postgresql
Version: 9.4+165

PHP version:
Package: php5
Version: 5.6.17+dfsg-0+deb8u1

ownCloud version: (see ownCloud admin page)
9.0.0 (stable)

Updated from an older ownCloud or fresh install:
Update: 7 > 8 > 9

Where did you install ownCloud from:
deb http://download.owncloud.org/download/repositories/stable/Debian_8.0/ /

Signing status (ownCloud 9.0 and above):
No errors have been found.

List of activated apps:
Enabled:

  • activity: 2.2.1
  • calendar: 1.0
  • comments: 0.2
  • contacts: 1.0.0.0
  • dav: 0.1.5
  • external: 1.2
  • federatedfilesharing: 0.1.0
  • federation: 0.0.4
  • files: 1.4.4
  • files_external: 0.5.2
  • files_pdfviewer: 0.8
  • files_sharing: 0.9.1
  • files_texteditor: 2.1
  • files_trashbin: 0.8.0
  • files_versions: 1.2.0
  • files_videoplayer: 0.9.8
  • firstrunwizard: 1.1
  • gallery: 14.5.0
  • notifications: 0.2.3
  • provisioning_api: 0.4.1
  • systemtags: 0.2
  • templateeditor: 0.1
  • updatenotification: 0.1.0
    Disabled:
  • encryption
  • user_external
  • user_ldap

The content of config/config.php:
{
"system": {
"instanceid": "_REMOVED",
"passwordsalt": "_REMOVED SENSITIVE VALUE
",
"trusted_domains": [
"_REMOVED"
],
"datadirectory": "/var/www/owncloud/data",
"dbtype": "pgsql",
"version": "9.0.0.19",
"dbname": "owncloud",
"dbhost": "localhost",
"dbtableprefix": "oc
",
"dbuser": "_REMOVED SENSITIVE VALUE",
"dbpassword": "_REMOVED SENSITIVE VALUE
",
"installed": true,
"mail_from_address": "cloud",
"mail_smtpmode": "php",
"mail_domain": "_REMOVED",
"forcessl": true,
"theme": "",
"maintenance": false,
"secret": "_REMOVED SENSITIVE VALUE
",
"loglevel": 2,
"memcache.local": "\OC\Memcache\APC",
"trashbin_retention_obligation": "auto",
"updatechecker": false
}
}

Are you using external storage, if yes which one:
No

Are you using encryption:
no

Are you using an external user-backend, if yes which one:
no

Client configuration

Browser:
Firefox 45

Operating system:
Debian 8

Activity

  1. LukasReschke commented on Mar 14, 2016

    @LukasReschke
    Contributor

    Duplicate of #22563

  2. spitzlei commented on Mar 14, 2016

    @spitzlei
    Author

    Why is this a Duplicate?
    I'm using Owncloud 9.0 and not 8.0 and here the oc_preferences tables is affected and not the oc_filecache.

  3. nebulade commented on Mar 14, 2016

    @nebulade

    We are seeing a similar issue, maybe related but in LDAP code:

    ERROR:  duplicate key value violates unique constraint "preferences_pkey"
    Mar 14 19:38:07 smartserver.io docker[750]: 2016-03-14 19:38:07 UTC DETAIL:  Key (userid, appid, configkey)=(username, user_ldap, displayName) already exists.
    Mar 14 19:38:07 smartserver.io docker[750]: 2016-03-14 19:38:07 UTC STATEMENT:  INSERT INTO "preferences" ("userid", "appid", "configkey", "configvalue") VALUES($1, $2, $3, $4)
    

    If I understand #22563 correctly, can this be ignored for now? I am also using oC 9.0 but with mysql

  4. mobstef commented on Mar 21, 2016

    @mobstef

    There is a workaround for this issue, which seems to affect ldap user login in 9.0.
    To stop flooding of the logs with the reported error message add a rule to ignore the insert if the constraint violation would occur. After http://dba.stackexchange.com/questions/30499/optimal-way-to-ignore-duplicate-inserts:
    CREATE OR REPLACE RULE oc_preferences_ignore_duplicate_inserts AS ON INSERT TO oc_preferences WHERE (EXISTS ( SELECT 1 FROM oc_preferences WHERE oc_preferences.userid = NEW.userid and oc_preferences.appid = NEW.appid and oc_preferences.configkey = NEW.configkey)) DO INSTEAD NOTHING;

  5. jknockaert commented on Mar 22, 2016

    @jknockaert
    Contributor

    Seeing a similar issue, but without LDAP:

    [2016-03-22 16:23:33.169 CET] REMOVED ERROR:  duplicate key value violates unique constraint "oc_preferences_pkey"
    [2016-03-22 16:23:33.169 CET] REMOVED DETAIL:  Key (userid, appid, configkey)=(REMOVED, login, lastLogin) already exists.
    [2016-03-22 16:23:33.169 CET] REMOVED STATEMENT:  INSERT INTO "oc_preferences" ("userid", "appid", "configkey", "configvalue") VALUES($1, $2, $3, $4)
    

    The postgres log is full of these lines. Especially with the os x client app this error happens multiple times per user per minute.

    @LukasReschke Pls reopen. This happens on OC 9 (with postgres) and is not a duplicate of #22563

  6. jknockaert commented on Mar 31, 2016

    @jknockaert
    Contributor

    Do we already know which regression caused this behaviour?

  7. voidzero commented on Apr 21, 2016

    @voidzero

    @mobstef Any idea how to reverse this query, for when the bug gets fixed?

  8. mobstef commented on Apr 21, 2016

    @mobstef

    @voidzero Rather straightforward:
    drop rule oc_preferences_ignore_duplicate_inserts on oc_preferences;

  9. voidzero commented on Apr 21, 2016

    @voidzero

    Perfect, @mobstef. Much thanks.

  10. nickvergessen commented on Jun 8, 2016

    @nickvergessen
    Contributor

    Just had a look at the code, it seems to be expected. We run the insert, then catch the php side exception that is thrown by doctrine when the key is violated and update instead.

    Basically we could try and change the preference stuff to use insertIfNotExists(), but we can't do that in the current method Connection::setValues() because we don't know for all of the use-cases of the method, what keys they would need to check.

  11. 21 remaining items

  12. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    Seems fixed by @butonic around November 9fe34ef for versions 9.1>

    Hail @butonic, @PVince81 can we try to backport it to 9.0 and check if this fixes the issue?

  13. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    @DeepDiver1975 Yet another motivation to get rid of <9.1 fantastic legacy code and doing query only with Doctrine and QueryBuilder, yet this is not strictly related to this issue?

  14. jknockaert commented on Apr 5, 2017

    @jknockaert
    Contributor

    No need for me to backport. If it is fixed then it is ok for me to just close this ticket.

  15. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    Yep, but maybe I would need to check it again on Postgre if that really fixed the issue also for < 9.1 versions :>. Lets see what @butonic says, can I just cherry-pick 9fe34ef and test again Posgre, wont it break sth?

  16. butonic commented on Apr 5, 2017

    @butonic
    Contributor

    Skimming this issue I only see a reference to an INSERT statement. The PR mentioned by @mrow4a only touches a SELECT. It does change the statement a little, however, as it adds a NOT NULL check: 9fe34ef#diff-512d39632663dc8e28bba3e11ac5dd52R423

    @mrow4a If you can reproduce this I'd like to verify the PR actually fixes this issue as it was intended to fix an oracle only problem. Could you backport?

  17. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    @jknockaert @butonic @PVince81 I verified and on OC9.1 the issue exists, and on OC10 issue is solved, because setUserValue function is not being called on repetitive login (called only on first user login) and also different values are being inserted to oc_preferences table. I also upgraded from 9.1->10. However, we cannot backport it to lower version, because code responsible for that has been completely refactored for version 10 and it is not related (directly) to the COMMIT I mentioned above, as I was hoping it will be.

    Is it ok for you that it is solved in 10 and I can close the ticket? Please reopen if it happens again in OC10

  18. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    @DeepDiver1975 Now oc_accounts table is responsible for these things right, I think it was your crazy long PR https://github.com/owncloud/core/pull/27276/files#diff-37958be4e01e8baeb127a59409e1a593R125? Sorry @butonic, it was Thomas hard work i think, not yours .. :>
    selection_158

  19. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    Debugging further the issue to find corner cases, one could experience "one-time" violation if he is changing the language e.g. from English to Polish etc, so next login after the change will once experience it, however any consequtive login wont. @DeepDiver1975 any priority on fixing this, since it is only happening once user changes his preference? (It is not violating during initialization of the preference and not with consequtive logins)

  20. mrow4a commented on Apr 5, 2017

    @mrow4a
    Contributor

    I could not stand looking at this "universal querying" and there is ongoing PR #27576, which will fix above issue in OC10 and potentialy all other if backported to <9.1 (needs checking the backport). However ideally we should kill that setValue thing, I am not a fan of "universality" in big scale instances, but this i not in scope of OC10 I guess ( @DeepDiver1975 ?)

  21. PVince81 commented on Apr 6, 2017

    @PVince81
    Contributor

    once user changes his preference

    There is more code that changes stuff in oc_preferences than just changing the language I think.
    Third party apps are also able to store user preferences there, so I suspect the exception might be logged for those cases as well.

  22. israel-lugo commented on Apr 24, 2017

    @israel-lugo

    @mrow4a Please note that the message does appear after consecutive logins, at least in my use case. I am not changing languages every day, yet I had 142 occurrences of the message in the last 12 hours. Just normal contact/calendar sync traffic from my clients (cellphone, MUA).

  23. mrow4a commented on Apr 24, 2017

    @mrow4a
    Contributor

    Yep, will wake up the topic in here #27576, I already fixed it, however needs some adjustment.

  24. lock commented on Aug 2, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  25. locked as resolved and limited conversation to collaborators on Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions