I’m using self-hosted n8n version with postgres database. I’m trying to enable automatic execution pruning using examples in documentation, but it doesn’t work for me. There are still old executions in execution_data in postgres.
This is my env variables in n8n image in docker compose:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- EXECUTIONS_DATA_PRUNE=true
- EXECUTIONS_DATA_MAX_AGE=1
current size of execution_data table is 21GB, execution_entity 142MB
The execution_data table should contain the data from the workflow and only exist if there is a matching execution_entity record, In this case it would be worth checking the execution_entity table for the oldest record or… Check the execution_data table for any records that don’t exist in the execution_entity table with something like…
SELECT
"executionId"
FROM
execution_data ed
WHERE
NOT EXISTS (
SELECT
FROM
execution_entity
WHERE
id = ed."executionId"
);
It could be that the data is being removed or maybe everything is only being soft deleted and the hard delete isn’t kicking. This should in theory tell us a bit more, I have checked on my own local postgres install and everything appears to be working as expected which is a good sign although I am on a newer version of n8n than you.
Your request returned no data for me. By the way, the request SELECT COUNT(*) FROM execution_data ed; returns 262115 in my case, and SELECT COUNT(*) FROM execution_entity; returns 262255.
In theory if the query returns nothing there is no data there that shouldn’t be and everything has a match although your query output seems somewhat odd as you do have different counts so it looks like you have some execution_entity records without any workflow data.
What is the max age of the records in the database? There is not really any difference between our ocmpose options other than I am using a newer n8n version in which case upgrading would fix it for you, I am on a newer Postgres version as I upgraded from 11 to 14 a while back but I can’t see this being the cause and the other thing is my max age is 30 instead of 1.
For science I have just updated my install to use 1 to see if that is the issue.