I developed an application using Postgresql + TimescaleDB + PostGIS where repeatedly some primary keys are out of sync. Fixing this manually as described in How to reset postgres' primary key sequence when it falls out of sync? works, but I want to understand why this happens and how I can avoid this.
- The affected tables are not managed with TimescaleDB and have no PostGIS related columns.
- My code contains only one
insert
statement per affected table and my code never sets primary-keys directly. - I'm using SqlAlchemy for the inserts, but only the SQLAlchemy Expression Language layer and not the ORM.
Does anybody have an idea how to fix this issue?