Cannot read properties of undefined / Found an item that no longer exists

I ran into an issue today, so I will post the solution in case it helps someone else.

Joplin server sync stopped working, with the following error message:

2023-03-14 22:10:51: [error] App: 10.0.1.254 TypeError: Cannot read properties of undefined (reading 'content_size')
    at ItemModel.<anonymous> (/home/joplin/packages/server/src/models/ItemModel.ts:276:57)
    at Generator.next (<anonymous>)
    at fulfilled (/home/joplin/packages/server/dist/models/ItemModel.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Also the following warnings were logged (hundreds per second):

2023-03-14 22:07:43: [warn] ShareModel: Found an item (7D9zXuCk5oEkhHFXAzDebWIQijEpk6hN) associated with a share that no longer exists () - skipping it
2023-03-14 22:07:43: [warn] ShareModel: Found an item (3g4jHUb1OGbnzqPV34sjmnINNlUF0vEP) associated with a share that no longer exists () - skipping it

It turns out the PostgreSQL indices were corrupt. To fix this, first get a postgres shell:

docker exec -it ... psql -U <user>

Then rebuild indices:

REINDEX DATABASE <database name>;

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