Pgroll migration fails to create index when under load, but succeeds after nth time.
Author: andriusjurkusCreated Jan 9, 2026Updated Sep 11, 2026
This looks like race condition somewhere. Basically what happened is that this migration failed multiple times but after nth automatic try it succeeded.
DB is on postgres 17 PGROLL 14.3 (not sure if 16 version did something which could have fixed issue)
Related schema before migration
\d+ client
Table "public.client"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
------------+--------------------------+-----------+----------+------------------------------------+----------+-------------+--------------+-------------
id | integer | | not null | nextval('client_id_seq'::regclass) | plain | | |
api_key | character varying | | not null | | extended | | |
name | character varying | | not null | | extended | | |
created_at | timestamp with time zone | | not null | now() | plain | | |
updated_at | timestamp with time zone | | not null | now() | plain | | |
Indexes:
"client_pkey" PRIMARY KEY, btree (id)
"client_name_idx" UNIQUE, btree (name)
Referenced by:
TABLE "email" CONSTRAINT "email_client_fk" FOREIGN KEY (fk_client_id) REFERENCES client(id)
Access method: heap
Trying to apply
operations:
- create_index:
columns:
api_key: {}
method: btree
name: client_api_key_idx
table: clientThis is logs from first run! And it says that index is already created.
INFO Command: pgroll status⏎
INFO Latest local migration: 013_add_client_token_index⏎
INFO Latest DB migration: 012_add_client_name_index⏎
INFO Current DB Status: { "schema": "public", "version": "012_add_client_name_index", "status": "Complete" }⏎
INFO Starting migration: 013_add_client_token_index (1 operation)⏎
INFO Starting operation: create_index⏎
INFO Details: { "name": "client_api_key_idx", "table": "client", "index_type": "btree" }⏎
INFO Rolling back migration: 013_add_client_token_index⏎
INFO Dropped versioned schema: public_013_add_client_token_index⏎
ERROR Failed to start migration: failed to execute action create_index_concurrently_client_client_api_key_idx⏎
ERROR Cause: pq: relation "client_api_key_idx" already exists⏎
INFO Migration rolled back successfully.This never fails when there is no load when doing "local" migrations.
Source: xataio/pgroll