1

We want to migrate from mysql database to Yugabyte(PostgreSQL) database. We found 2 alternatives in YugabyteDB for mysql AUTO_INCREMENT ()

  1. serial
  2. sequence

For some reason we are not like to use UUID. In that case does serial or sequence ensure the uniqueness of data? (we have 6 nodes)

Draga
  • 43
  • 6

1 Answers1

2

Actually serial/bigserial create a sequence underneath and use that to generate unique ids. Sequences do generate unique values even in distributed systems.

You also need to use caching for better performance which lowers number of rpcs to generate new values: https://docs.yugabyte.com/latest/api/ysql/commands/ddl_create_sequence/#cache

The uniqueness is enforced on the database side by a primary-key, unique-index, constraint. In this case it's also better for the id column to be the primary key.

So, use BIGINT column with a sequence with a big cache, and make the id a primary key.

dh YB
  • 965
  • 3
  • 10