Skip to content

Cannot save statistics on PosgreSQL #14124

@mdima

Description

@mdima

NodeBB version

v4.10.0 (docker image)

NodeBB git hash

No response

NodeJS version

No response

Installed NodeBB plugins

  • @nodebb/nodebb-plugin-reactions
  • nodebb-plugin-composer-default
  • nodebb-plugin-custom-pages
  • nodebb-plugin-dbsearch
  • nodebb-plugin-emoji
  • nodebb-plugin-markdown
  • nodebb-plugin-mentions
  • nodebb-plugin-poll
  • nodebb-plugin-web-push
  • nodebb-rewards-essentials
  • nodebb-theme-harmony
  • nodebb-widget-essentials

All updated.

Database type

PostgreSQL

Database version

18.2

Exact steps to cause this issue

Hello, at the start of the container I find:

2026-03-25T13:53:02.059Z [4567/217] - error: [analytics] Encountered error while writing analytics to data store error: duplicate key value violates unique constraint "legacy_zset_pkey" at /usr/src/app/node_modules/pg/lib/client.js:631:17 at process.processTicksAndRejections (node:internal/process/task_queues:104:5) at async /usr/src/app/src/database/postgres/sorted/add.js:54:4 at async module.transaction (/usr/src/app/src/database/postgres/transaction.js:22:10) at async sortedSetAddBulk (/usr/src/app/src/database/postgres/sorted/add.js:52:3) at async module.sortedSetAdd (/usr/src/app/src/database/postgres/sorted/add.js:13:11) at async Promise.all (index 0) at async Analytics.writeData (/usr/src/app/src/analytics.js:209:3) at async onTick (/usr/src/app/src/analytics.js:44:5) at async CronJob.<anonymous> (/usr/src/app/src/cron.js:46:4)

This happened after an update to a new build of the NodeBB container

At the same time in the PostgreSQL container I find as log:

2026-03-25 13:55:22.038 UTC [526] ERROR:  duplicate key value violates unique constraint "legacy_zset_pkey"
2026-03-25 13:55:22.038 UTC [526] DETAIL:  Key (_key, value)=(analyticsKeys, pageviews:month) already exists.
2026-03-25 13:55:22.038 UTC [526] STATEMENT:  
	INSERT INTO "legacy_zset" ("_key", "value", "score")
	SELECT $1::TEXT, v, s
	FROM UNNEST($2::TEXT[], $3::NUMERIC[]) vs(v, s)
	ON CONFLICT ("_key", "value")
	DO UPDATE SET "score" = EXCLUDED."score"

The result is that the dashboard statistics data is empty.

What you expected

The statistics data in the administration dashboard.

What happened instead

The statistics data is empty.

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions