Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate key value violates unique constraint "internal_metadata_pkey". #506

Open
kaladay opened this issue Jan 13, 2023 · 1 comment · Fixed by #508
Open

Duplicate key value violates unique constraint "internal_metadata_pkey". #506

kaladay opened this issue Jan 13, 2023 · 1 comment · Fixed by #508
Assignees
Labels
bug Something isn't working

Comments

@kaladay
Copy link
Contributor

kaladay commented Jan 13, 2023

Describe the bug

I've been seeing some weird problems with the primary key synchronization.
Errors like:

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "internal_metadata_pkey"
  Detail: Key (id)=(42) already exists.

Relevant parts of the database look like:

sage=# select max(id) + 1 from internal_metadata;
 ?column? 
----------
       45
(1 row)

sage=# select * from internal_metadata_id_seq ;
 last_value | log_cnt | is_called 
------------+---------+-----------
         42 |       0 | f
(1 row)

sage=# select * from internal_metadata where id = 42;
 id | field  |          gloss          | required 
----+--------+-------------------------+----------
 42 | medium | Medium (dcterms.medium) | f
(1 row)

This is wrong, the id sequence should be 45.
Any attempt to create new metadata would result in a duplicate key violation because 42 already exists.

This is temporarily fixed by doing something like:

alter table internal_metadata alter COLUMN id restart with 45;

To Reproduce
Steps to reproduce the behavior:

  1. Unknown.

Expected behavior
Should always be able to create new metadata without the primary keys being behind.

@kaladay kaladay added the bug Something isn't working label Jan 13, 2023
@kaladay
Copy link
Contributor Author

kaladay commented Jan 13, 2023

This appears to be a problem regarding the code here:

The immediate solution is to make sure this and other SQL db import files are not run when hibernate.ddl-auto is set to something other than create-drop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant