0

I have several sequences for tables (dynamic information and crosswalks) that get out of sync from the table primary keys during testing. While I can fix them, what can I do to prevent the sequences from getting out of sync with the keys in the first place?

5
  • Only ever use sequences to generate key values, may be?
    – mustaccio
    Commented Mar 30, 2022 at 23:50
  • Sequences can be allocated to sessions in batches, and that plus aborted transactions where the sequence is "lost" mean that sequences can't be kept in sync with anything. They are basically just meant to be surrogate keys!
    – Vérace
    Commented Mar 31, 2022 at 0:39
  • I assume you complain about gaps in sequences, but I am not certain. Can you clarify that? Commented Mar 31, 2022 at 3:29
  • How to reset postgres' primary key sequence when it falls out of sync? - to prevent that happening in the first place use generated always as identity instead of generated always by default or serial
    – user1822
    Commented Mar 31, 2022 at 5:25
  • @a_horse_with_no_name that sounds like something reasonable there. I'm assuming I can change that through pg_admin without any downtime in the DB? Commented Mar 31, 2022 at 14:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.