Fix for Journey Creation Error – PostgreSQL sequence re-alignment

Modified on Thu, 19 Feb at 2:19 PM

Overview

After upgrades or migrations (e.g., Docker or Newired version updates), you may encounter the following error when creating a new Journey:

ERROR: duplicate key value violates unique constraint "config_property_pkey" Detail: Key (id)=(237) already exists.

Why This Happens

PostgreSQL uses a sequence to automatically generate unique IDs for primary key columns. In this case, the sequence responsible for generating values for:

journeys.config_property.id

has become out of sync.

This means:

  • The sequence is attempting to reuse an ID that already exists in the table.

  • PostgreSQL correctly rejects the insert to prevent duplicate primary keys.

  • No data is corrupted.

  • This is a standard sequence alignment issue that can occur after:

    • System upgrades

    • Database restores

    • Container recreation

    • Migrations

The fix simply requires realigning the sequence with the current maximum ID in the table.


Environment

  • Deployment: On-prem
  • Containerization: Docker
  • Database: PostgreSQL 14.x
  • Schema: journeys
  • Table: config_property
  • Sequence: journeys.seq_config_property

Resolution Steps

Step 1 – Identify the Database Container

Run:

docker ps

Look for the container named similar to:

newired-database

Copy the container ID.


Step 2 – Access the Database Container

Enter the container:

docker exec -it <container_id> bash

Switch to the postgres user:

su postgres

Start PostgreSQL:

psql

Step 3 – Re-align the Sequence

Execute the following query:

SELECT setval( 'journeys.seq_config_property', (SELECT COALESCE(MAX(id), 0) FROM journeys.config_property), false );

What This Does

  • Reads the current highest id value in journeys.config_property

  • Resets the sequence to match that value

  • Ensures the next generated ID will not reuse an existing one


Step 4 – If the Issue Persists

If the error still occurs, increase the sequence by one:

SELECT setval( 'journeys.seq_config_property', (SELECT COALESCE(MAX(id), 0) FROM journeys.config_property) + 1, false );

This ensures the next generated ID is strictly greater than the current maximum.


Step 5 – Exit and Test

Exit PostgreSQL:

\q

Exit the container if needed:

exit

Retry creating a new Journey in Newired.


Important Notes

  • This procedure does not delete or modify existing records.

  • It only adjusts PostgreSQL’s internal auto-numbering counter.

  • As a best practice, take a database backup before making changes in production environments.


Summary

This issue is caused by a PostgreSQL sequence falling out of sync after an upgrade or migration.
Realigning the sequence resolves the duplicate key error and restores normal Journey creation functionality.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article