Code Monkey home page Code Monkey logo

Comments (6)

veryphatic avatar veryphatic commented on June 18, 2024 1

Different databases (Azure PG/Ubuntu PG)

(I also added detail above)

from directus.

hanneskuettner avatar hanneskuettner commented on June 18, 2024 1

After looking at how the auto increment is set up in Postgres I have to tell you that this is indeed expected behavior and won't be changed. The primary key is drawn from a SEQUENCE object and sequences are only guaranteed to be incrementing in nature but not gap-less.

To avoid blocking concurrent transactions that obtain numbers from the same sequence, the value obtained by nextval is not reclaimed for re-use if the calling transaction later aborts. This means that transaction aborts or database crashes can result in gaps in the sequence of assigned values. That can happen without a transaction abort, too. For example an INSERT with an ON CONFLICT clause will compute the to-be-inserted tuple, including doing any required nextval calls, before detecting any conflict that would cause it to follow the ON CONFLICT rule instead. Thus, PostgreSQL sequence objects cannot be used to obtain “gapless” sequences.1

As such I'll be closing this issue. If you need a strictly gapless ID for some reason (which to me seems like a weird requirement) you could resort to populating a different field after the fact in a flow (you would have to account for concurrent insert yourself then). And this is just something I can come up with on the top off my head, not a recommendation :D

Footnotes

  1. https://www.postgresql.org/docs/current/functions-sequence.html

from directus.

hanneskuettner avatar hanneskuettner commented on June 18, 2024

Since I'm not seeing this problem on my local instance with the SQLite driver, I've got a few clarifying questions:

  • What DB vendor and version are you using?
  • You're talking about two instances, are you running Directus as a cluster or are you seeing the same problems on two individual instances?
  • Can you share your configuration (without sharing any secrets are API keys) to help us reproduce this issue.

from directus.

veryphatic avatar veryphatic commented on June 18, 2024

You're talking about two instances, are you running Directus as a cluster or are you seeing the same problems on two individual instances?

  • There are two individual instances

What DB vendor and version are you using?
Can you share your configuration (without sharing any secrets are API keys) to help us reproduce this issue.

Instance 1

  • Azure App service
  • Docker image: directus:10.10.5
  • Azure Database for PostgreSQL 16.2 - Flexible Server
  • DB_SSL: true
  • Collection: primary key (bigint), various inputs (text, multiple images, M20 relation, radio), boolean

Instance 2: air gapped network

  • Ubuntu 22.04
  • Postgres 16.2
  • Docker image: directus:10.10.5
  • DB_SSL: false
  • Collection: primary key (bigint), various inputs (text, multiple images, M20 relation, radio), boolean

from directus.

hanneskuettner avatar hanneskuettner commented on June 18, 2024

And just to confirm, are you pointing both instances to the same DB instance or different ones as well?

from directus.

veryphatic avatar veryphatic commented on June 18, 2024

Additionally, the M2O related collection also has bigint primary key

from directus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.