2

Working with Active Record in postgres in a rails application, hosted in heroku I start to notice that sometimes the index of my database are been skipped. For example: product id 1000 1001 1003 <---- Missing the 1002

This is not happen all the time, and I am trying to figure out what is the issue. I check database logs, the server logs and also I call my clients and they said that they have no issue. But I need to know why this skipping scenarios is happening.

rails', '3.2.17' activerecord (3.2.17) pg (0.14.1) pg_search (0.7.0)

I have my guess: this can be heroku issue, with Async Excect, but I have no idea.

dsapandora
  • 104
  • 7
  • Is it possible that the element was deleted? If an id is used for an element, and then that element is deleted, the id will not be re-used. – Joe Essey Apr 20 '16 at 16:05
  • No we actually never delete anything. I overwrite the models delete method just to unpublish things. The issue happens yesterday. So I am still guessing – dsapandora Apr 20 '16 at 16:10

1 Answers1

1

Your transaction rolled back due to some invalid data. Could be google spiders, or less savory robots trying to penetrate the site.

Here's a stack overflow answer: How to reset Autoincremented Id when rollback occurs in sql

Autoincrement IDs should not be contiguous in a production environment.

Community
  • 1
  • 1
Andy Gauge
  • 1,428
  • 2
  • 14
  • 25
  • can it be a data collision from my own users? – dsapandora Apr 20 '16 at 16:11
  • 2
    Thanks, I think that now I can have an Idea from what is happening.To avoid blocking concurrent transactions that obtain numbers from the same sequence, a nextval operation is never rolled back; that is, once a value has been fetched it is considered used, even if the transaction that did the nextval later aborts. This means that aborted transactions might leave unused "holes" in the sequence of assigned values. – dsapandora Apr 20 '16 at 16:16