# PostgreSQL errors?

**URL:** <https://community.n8n.io/t/postgresql-errors/25148>\
**Category:** Questions\
**Tags:** database-migration\
**Created:** [April 13, 2023, 5:00pm UTC](https://community.n8n.io/t/postgresql-errors/25148 "2023-04-13T17:00:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nle](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nle/32/13357_2.png) [@nle](https://community.n8n.io/u/nle)\
**Post date:** [April 13, 2023, 5:00pm UTC](https://community.n8n.io/t/postgresql-errors/25148/1 "2023-04-13T17:00:38Z")

</div>

I recently experienced `SQLITE_BUSY: database is locked` error from one of my nodes, and figured I should change to PostgreSQL.

I first exported all workflows and credentials, added the environment variables (using docker), started a clean instance and imported the credentials and workflows.

Everything seem to work, but I get the following in the postgressql logs:

```auto
PostgreSQL Database directory appears to contain a database; Skipping initialization

2023-04-13 16:43:19.026 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-04-13 16:43:19.026 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-04-13 16:43:19.028 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-04-13 16:43:19.040 UTC [26] LOG: database system was shut down at 2023-04-13 16:39:06 UTC
2023-04-13 16:43:19.045 UTC [1] LOG: database system is ready to accept connections
2023-04-13 16:43:27.398 UTC [42] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:43:27.398 UTC [42] HINT: Must be superuser to create this extension.
2023-04-13 16:43:27.398 UTC [42] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:43:32.023 UTC [52] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:43:32.023 UTC [52] HINT: Must be superuser to create this extension.
2023-04-13 16:43:32.023 UTC [52] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:43:51.944 UTC [91] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:43:51.944 UTC [91] HINT: Must be superuser to create this extension.
2023-04-13 16:43:51.944 UTC [91] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:44:09.611 UTC [116] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:44:09.611 UTC [116] HINT: Must be superuser to create this extension.
2023-04-13 16:44:09.611 UTC [116] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:44:12.002 UTC [126] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:44:12.002 UTC [126] HINT: Must be superuser to create this extension.
2023-04-13 16:44:12.002 UTC [126] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:44:12.333 UTC [124] ERROR: duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-13 16:44:12.333 UTC [124] DETAIL: Key ("workflowId", name)=(4, data_loaded) already exists.
2023-04-13 16:44:12.333 UTC [124] STATEMENT: INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)
2023-04-13 16:44:12.396 UTC [124] ERROR: duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-13 16:44:12.396 UTC [124] DETAIL: Key ("workflowId", name)=(4, production_success) already exists.
2023-04-13 16:44:12.396 UTC [124] STATEMENT: INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)
2023-04-13 16:44:32.037 UTC [161] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:44:32.037 UTC [161] HINT: Must be superuser to create this extension.
2023-04-13 16:44:32.037 UTC [161] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
2023-04-13 16:44:32.354 UTC [80] ERROR: duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-13 16:44:32.354 UTC [80] DETAIL: Key ("workflowId", name)=(4, data_loaded) already exists.
2023-04-13 16:44:32.354 UTC [80] STATEMENT: INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)
2023-04-13 16:44:32.419 UTC [80] ERROR: duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-13 16:44:32.419 UTC [80] DETAIL: Key ("workflowId", name)=(4, production_success) already exists.
2023-04-13 16:44:32.419 UTC [80] STATEMENT: INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)
2023-04-13 16:44:33.205 UTC [162] ERROR: permission denied to create extension "uuid-ossp"
2023-04-13 16:44:33.205 UTC [162] HINT: Must be superuser to create this extension.
2023-04-13 16:44:33.205 UTC [162] STATEMENT: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

```

And it keeps on …

Any input on how I can solve this?

EDIT:  
Ended up upgrading via dumping and restoring postgresdb from 11 to 15 – also upgraded from 0.222.2 to 0.223.0 (as per [this post](http://community.n8n.io/t/duplicate-key-value-violates-unique-constraint-workflow-statistics-pkey/22427/18)). That seems to have helped for the `uuid-ossp` problem, but I still see:

```auto
2023-04-13 17:55:42.255 UTC [521] ERROR: duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-13 17:55:42.255 UTC [521] DETAIL: Key ("workflowId", name)=(4, data_loaded) already exists.
2023-04-13 17:55:42.255 UTC [521] STATEMENT: INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)

```

## Information on your n8n setup

- **n8n version:** 0.223.0
- **Database you’re using (default: SQLite):** PostgreSQL 15.2
- **Running n8n with the execution process:** own
- **Running n8n via:** Docker

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [April 19, 2023, 7:40am UTC](https://community.n8n.io/t/postgresql-errors/25148/3 "2023-04-19T07:40:43Z")

</div>

Hi @nle, I am so sorry for this. I was able to confirm this on my side even on the current n8n version 0.224.1, I’ll once again bring this up to the engineering team and will post an update when I hear back.

---

<div class="post-metadata">

**Author:** ![MarioGuimaraes](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marioguimaraes/32/19803_2.png) [@MarioGuimaraes](https://community.n8n.io/u/MarioGuimaraes)\
**Post date:** [April 27, 2023, 5:23pm UTC](https://community.n8n.io/t/postgresql-errors/25148/5 "2023-04-27T17:23:51Z")

</div>

Hi @nle  
this error:  
permission denied to create extension “uuid-ossp”

I solved with this:  
psql -U ${POSTGRES\_USER} -d ${POSTGRES\_DB} -c ‘CREATE EXTENSION “uuid-ossp”;’

my service in docker-compose:  
n8n\_postgres:  
image: postgres:11  
container\_name: postgres-n8n  
restart: always  
environment:  
- POSTGRES\_USER  
- POSTGRES\_PASSWORD  
- POSTGRES\_DB  
- POSTGRES\_NON\_ROOT\_USER  
- POSTGRES\_NON\_ROOT\_PASSWORD  
networks:  
- internal\_network  
volumes:  
- postgres-data:/var/lib/postgresql/data  
- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh  
healthcheck:  
test:  
[  
‘CMD-SHELL’,  
‘pg\_isready -h localhost -U ${POSTGRES\_USER} -d ${POSTGRES\_DB}’  
]  
interval: 5s  
timeout: 5s  
retries: 10

Observe this line:

- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh  
This file is the secret to solve this problem init-data.sh

Content the init-data.sh:  
#!/bin/bash  
set -e;

if [-n “${POSTGRES\_NON\_ROOT\_USER:-}”] && [-n “${POSTGRES\_NON\_ROOT\_PASSWORD:-}”]; then  
psql -v ON\_ERROR\_STOP=1 --username “$POSTGRES\_USER” --dbname “$POSTGRES\_DB” \<\<-EOSQL  
CREATE USER ${POSTGRES\_NON\_ROOT\_USER} WITH PASSWORD ‘${POSTGRES\_NON\_ROOT\_PASSWORD}’;  
GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES\_DB} TO ${POSTGRES\_NON\_ROOT\_USER};  
EOSQL  
psql -U ${POSTGRES\_USER} -d ${POSTGRES\_DB} -c ‘CREATE EXTENSION “uuid-ossp”;’  
else  
echo “SETUP INFO: No Environment variables given!”  
fi

And my .env:  
POSTGRES\_USER=your\_username  
POSTGRES\_PASSWORD=your\_password  
POSTGRES\_DB=your\_db\_name  
POSTGRES\_NON\_ROOT\_USER=your\_user\_non\_root  
POSTGRES\_NON\_ROOT\_PASSWORD=your\_password\_non\_root

There are in the same folder

---

<div class="post-metadata">

**Author:** ![MarioGuimaraes](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marioguimaraes/32/19803_2.png) [@MarioGuimaraes](https://community.n8n.io/u/MarioGuimaraes)\
**Post date:** [April 27, 2023, 5:26pm UTC](https://community.n8n.io/t/postgresql-errors/25148/6 "2023-04-27T17:26:42Z")

</div>

the second problem:  
duplicate key

is being discussed here too:

> [@Duplicate key value violates unique constraint "workflow\_statistics\_pkey"](http://community.n8n.io/t/duplicate-key-value-violates-unique-constraint-workflow-statistics-pkey/22427/15):
>
> Same issue here. n8n v.221.2 & postgres-ha. My n8n has hundreds of thousands of executions per day. I believe what @MutedJam said was the cause, that n8n logs the ‘error’ whenever an execution occurs and write to an existing row, instead of doing something like ‘increment if exists’. I can’t tell if my n8n’s performance is affected, but the log file is getting quite crazy lol. It’d be great if you guys could find a solution to this. Thank you for the hard work!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 26, 2023, 5:27pm UTC](https://community.n8n.io/t/postgresql-errors/25148/7 "2023-07-26T17:27:03Z")

</div>

Closed on July 26, 2023, 5:27pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
