#572·migrate

ERROR: tuple concurrently updated (SQLSTATE XX000) in line 0: TRUNCATE \"schema_migrations\""

Author: faraoncCreated May 25, 2021Updated Sep 23, 2026

Describe the Bug I run my database migration using a Job in Kubernetes with completions: 1, parallelism: 1, and backoffLimit: 4 thus it is single job with some retries based from backoffLimit. The database takes a while to start, so the job has to retry.

This rarely happens, but sometimes I would see the following error on the last retry .

ERROR: tuple concurrently updated (SQLSTATE XX000) in line 0: TRUNCATE \"schema_migrations\""

This happens even if the previous job already terminated, therefore I am unsure if there is anything left to cleanup.

import (
    "database/sql"
    _ "github.com/lib/pq"
    "github.com/golang-migrate/migrate/v4"
    "github.com/golang-migrate/migrate/v4/database/postgres"
    _ "github.com/golang-migrate/migrate/v4/source/file"
)

func main() {
    db, err := sql.Open("postgres", "postgres://postgres-svc:5432/database?sslmode=disabled")
    defer db.Close()
    driver, err := postgres.WithInstance(db, &postgres.Config{})
    // I have not tried closing the Driver
    // driver.Close()
    m, err := migrate.NewWithDatabaseInstance(
        "file:///migrations",
        "postgres", driver)
    m.Up()

Expected Behavior A clear and concise description of what you expected to happen.

Migrate Version v4.8.0

Loaded Source Drivers file

Loaded Database Drivers postgres

Go Version go1.13.11 linux/amd64