Postgres error duplicate key

I’m getting this error in postgres logs. Are this generated because I used the DUPLICATE workflow option? Any clue how to fix it?

PostgreSQL Database directory appears to contain a database; Skipping initialization

2021-11-07 16:56:23.009 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
2021-11-07 16:56:23.009 UTC [1] LOG: listening on IPv6 address “::”, port 5432
2021-11-07 16:56:23.011 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
2021-11-07 16:56:23.029 UTC [25] LOG: database system was shut down at 2021-11-07 16:56:13 UTC
2021-11-07 16:56:23.037 UTC [1] LOG: database system is ready to accept connections
2021-11-07 16:56:33.772 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.772 UTC [32] DETAIL: Key (“webhookPath”, method)=(6cca0-e21fe-710bb-ecfa4-55d39-754b029, GET) already exists.
2021-11-07 16:56:33.772 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.777 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.777 UTC [32] DETAIL: Key (“webhookPath”, method)=(0670a-cdde4-e1e38-b5669-7bc77-166b4ef, GET) already exists.
2021-11-07 16:56:33.777 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.781 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.781 UTC [32] DETAIL: Key (“webhookPath”, method)=(28a63a90-8a82-4644-9166-3d2b4572f205, GET) already exists.
2021-11-07 16:56:33.781 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.784 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.784 UTC [32] DETAIL: Key (“webhookPath”, method)=(b0aa0-5fd1b-dfe05-34aa6-73189-ae3bcc5, GET) already exists.
2021-11-07 16:56:33.784 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.788 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.788 UTC [32] DETAIL: Key (“webhookPath”, method)=(52fbe-dc5f1-4970f-45497-b5660-0d2a50c, GET) already exists.
2021-11-07 16:56:33.788 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.791 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.791 UTC [32] DETAIL: Key (“webhookPath”, method)=(eeab5-068f0-d5b4e-454d0-672f7-33aafb1, GET) already exists.
2021-11-07 16:56:33.791 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.797 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.797 UTC [32] DETAIL: Key (“webhookPath”, method)=(f3f28fe7-bbe7-4831-8f3e-9a401b327a8d, POST) already exists.
2021-11-07 16:56:33.797 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.801 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.801 UTC [32] DETAIL: Key (“webhookPath”, method)=(c67ed-d0f6c-21d80-3da62-c7f6f-85dfea2, GET) already exists.
2021-11-07 16:56:33.801 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.812 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.812 UTC [32] DETAIL: Key (“webhookPath”, method)=(72f41-36de4-79966-10004-fc5d8-d2f26f5, GET) already exists.
2021-11-07 16:56:33.812 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.815 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.815 UTC [32] DETAIL: Key (“webhookPath”, method)=(bff6f-b1fff-985ab-f4011-80316-b7558ea, GET) already exists.
2021-11-07 16:56:33.815 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.819 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.819 UTC [32] DETAIL: Key (“webhookPath”, method)=(822ea-d9580-f6b35-ce964-3bd26-9a480c3, GET) already exists.
2021-11-07 16:56:33.819 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.822 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.822 UTC [32] DETAIL: Key (“webhookPath”, method)=(27a98-ec886-5b58e-492fd-d7f47-c45f2fe, GET) already exists.
2021-11-07 16:56:33.822 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.826 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.826 UTC [32] DETAIL: Key (“webhookPath”, method)=(cd741-caa3b-c66f9-6c5b2-9eff5-bce2e75, POST) already exists.
2021-11-07 16:56:33.826 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.829 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.829 UTC [32] DETAIL: Key (“webhookPath”, method)=(b188d-ad7e4-53fbd-58139-59662-83dfc92, GET) already exists.
2021-11-07 16:56:33.829 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.840 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.840 UTC [32] DETAIL: Key (“webhookPath”, method)=(e58e7-13291-f0a8b-1200b-c2393-da316b4, GET) already exists.
2021-11-07 16:56:33.840 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.853 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.853 UTC [32] DETAIL: Key (“webhookPath”, method)=(9cbc6-991f2-862d1-fe78c-a9c54-7d41c2c, GET) already exists.
2021-11-07 16:56:33.853 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.863 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.863 UTC [32] DETAIL: Key (“webhookPath”, method)=(f162b-da773-2f6e1-14fb9-05a53-afbbf52, GET) already exists.
2021-11-07 16:56:33.863 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.887 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.887 UTC [32] DETAIL: Key (“webhookPath”, method)=(twilio, POST) already exists.
2021-11-07 16:56:33.887 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.903 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.903 UTC [32] DETAIL: Key (“webhookPath”, method)=(telegram, POST) already exists.
2021-11-07 16:56:33.903 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.907 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.907 UTC [32] DETAIL: Key (“webhookPath”, method)=(e988f-070a7-eb537-50961-eee2a-aafec7b, GET) already exists.
2021-11-07 16:56:33.907 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.934 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.934 UTC [32] DETAIL: Key (“webhookPath”, method)=(d7454-15de7-dbe78-a88c1-cd077-b8a798c, GET) already exists.
2021-11-07 16:56:33.934 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.944 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.944 UTC [32] DETAIL: Key (“webhookPath”, method)=(9acb4-4549b-41563-697bb-49014-4ec6258, GET) already exists.
2021-11-07 16:56:33.944 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)
2021-11-07 16:56:33.947 UTC [32] ERROR: duplicate key value violates unique constraint “PK_b21ace2e13596ccd87dc9bf4ea6”
2021-11-07 16:56:33.947 UTC [32] DETAIL: Key (“webhookPath”, method)=(babf8-dba9c-3df67-4dab8-66b9e-c3975c9, GET) already exists.
2021-11-07 16:56:33.947 UTC [32] STATEMENT: INSERT INTO “public”.“webhook_entity”(“workflowId”, “webhookPath”, “method”, “node”, “webhookId”, “pathLength”) VALUES ($1, $2, $3, $4, DEFAULT, DEFAULT)

On the n8n Worker, I get this warning:

WARNING: Creating a duplicate database object for the same connection.
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Postgres/Postgres.node.js:250:20)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

Are they related? Thank you!

Hey @vinicius,

I think there was an odd bug when cloning a workflow with a webhook in it. Can you delete the webhook node and add it again to see if that gets it working.

1 Like

Please do not change constraints! They are there for a reason. It is like cutting a foot when the little toe hurts. The pain from the toe will be gone but you will have a much bigger problem afterward.

Instead, do exactly what @jon proposed. That should fix the problem you had.

1 Like

I deleted the postgres image/db and updated to v14. Then I imported the workflows one by one using the ‘create new’ and ‘import from file’ options. When I finished I started testing and same issue. Postgres shows this error as well as worker say that duplicate object for the same connection.

Is there anything else I can do to solve this? Thank you!

Did you try deleting the trigger node then adding it back in again?

Yes, I deleted all 25 webhooks. The difference now is that the first time I start n8n, Postgress shows no error. But when I execute a webhook, then this error appears again.

That is strange, when you are deleting them are deleting the entire workflow or just the node?

What version of n8n are you running and how do you have it setup as well?

Hi Jon thanks for your attention and quick replies!

I tried both, first I deleted the entire workflow and imported again. Second I deleted only the Webhook node and added a new one.

I’m using the latest version of n8n, running with Docker Compose with Postgres 14 and Redis. I have 2 worker nodes in other machines for scaling.

Workflows are working, this error in Posgres got my attention, as well as the error in the Workers.

Maybe you can simulate it at your side? I did nothing fancy here, the error happens after a few seconds when I start the Docker compose.

Found the solution for the Postgres error.

After removing:
N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN=true

Postgres stopped showing the error.

It seems that when this is on, n8n tries to insert the same values to the table and, of course, it will not accept.

But the warning in the worker is still to be solved:

WARNING: Creating a duplicate database object for the same connection.
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Postgres/Postgres.node.js:250:20)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

Any clue?