Skip to content

Use BIGSERIAL for auto incremental default IDs.#300

Merged
olt merged 1 commit into
omniscale:masterfrom
johngian:use-bigserial
Mar 21, 2025
Merged

Use BIGSERIAL for auto incremental default IDs.#300
olt merged 1 commit into
omniscale:masterfrom
johngian:use-bigserial

Conversation

@johngian

Copy link
Copy Markdown
Contributor

No description provided.

@johngian

johngian commented Mar 21, 2025

Copy link
Copy Markdown
Contributor Author

This patch is something we use in our production imposm3-based OSM import pipeline. The tables storing relation members reached the limit of max integer used for SERIAL. In case this is an overhead we don't want (int vs bigint) we can make it configurable.

For more information: https://phabricator.wikimedia.org/T389462

@elukey

elukey commented Mar 21, 2025

Copy link
Copy Markdown

Error that we got in Postgres:

nextval: reached maximum value of sequence "wikidata_relation_members_id_seq" (2147483647)

Table specs:

gis=# \d public.wikidata_relation_members
                                     Table "public.wikidata_relation_members"
  Column  |          Type           | Collation | Nullable |                        Default                        
----------+-------------------------+-----------+----------+-------------------------------------------------------
 id       | integer                 |           | not null | nextval('wikidata_relation_members_id_seq'::regclass)
 osm_id   | bigint                  |           | not null | 
 wikidata | character varying       |           |          | 
 geometry | geometry(Geometry,3857) |           |          | 
Indexes:
    "wikidata_relation_members_pkey" PRIMARY KEY, btree (osm_id, id)
    "wikidata_relation_members_geom" gist (geometry)
    "wikidata_relation_members_idx" btree (wikidata)

@olt

olt commented Mar 21, 2025

Copy link
Copy Markdown
Member

Relation members are a special case, as all members are re-inserted when the relation or any relation member is changed.
I can see how you could hit that limit with a generic mapping like wikidata over a longer period.

The following should give you an idea if other tables are reaching this limit as well:

select schemaname as schema, 
       sequencename as sequence, 
       last_value
from pg_sequences;

I estimate a storage overhead of 1-2% when changing all IDs from SERIAL to BIGSERIAL for a "standard" OSM database used for rendering. I'm fine with this, as it makes it ready for even not-so-edge-case imports in the longer future.

@olt olt merged commit 16ebd6f into omniscale:master Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants