Skip to content

Failed to create memories for : Error: write CONNECTION_DESTROYED database #24400

@ptr727

Description

@ptr727

I have searched the existing issues, both open and closed, to make sure this is not a duplicate report.

  • Yes

The bug

It looks like the DB connection is not opened or no longer open when the 12am rescan operation started.

The OS that Immich Server is running on

Proxmox 9.1 / Debian 13 / Kernel 6.17

Version of Immich Server

v2.3.1

Version of Immich Mobile App

v0

Platform with the issue

  • Server
  • Web
  • Mobile

Device make and model

NA

Your docker-compose.yml content

name: immich

networks:
  stack_network:
  local_network:
    name: ${LOCAL_NETWORK_NAME}
    external: true

volumes:
  model-cache:

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:release
    restart: unless-stopped
    user: root
    group_add:
      - ${DOCKER_GROUP_ID}
    security_opt:
      - seccomp=unconfined
      - apparmor=unconfined
    # https://docs.immich.app/features/hardware-transcoding
    # https://github.com/immich-app/immich/releases/latest/download/hwaccel.transcoding.yml
    devices:
      - /dev/dri:/dev/dri
    # https://docs.immich.app/guides/custom-locations
    volumes:
      - ${MEDIA_DIR}/Immich:/data
      # - ${MEDIA_DIR}/Immich/encoded-video:/data/encoded-video
      - ${APPDATA_DIR}/immich/thumbs:/data/thumbs
      - ${APPDATA_DIR}/immich/profile:/data/profile
      - ${APPDATA_DIR}/immich/backups:/data/backups
      - ${MEDIA_DIR}/Pictures:/mnt/pictures:ro
      - ${MEDIA_DIR}/Videos:/mnt/videos:ro
    # https://docs.immich.app/install/environment-variables
    environment:
      - TZ=${TZ}
      # - IMMICH_LOG_LEVEL=debug
    networks:
      local_network:
      stack_network:
    labels:
      - traefik.enable=true
      - traefik.http.routers.immich.rule=HostRegexp(`^immich${DOMAIN_REGEX}$$`)
      - traefik.http.services.immich.loadbalancer.server.scheme=http
      - traefik.http.services.immich.loadbalancer.server.port=2283
    depends_on:
      - database
      - redis
      - immich-machine-learning
    healthcheck:
      disable: false

  # https://docs.immich.app/features/ml-hardware-acceleration
  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:release-openvino
    restart: unless-stopped
    user: root
    group_add:
      - ${DOCKER_GROUP_ID}
    security_opt:
      - seccomp=unconfined
      - apparmor=unconfined
    # https://github.com/immich-app/immich/releases/latest/download/hwaccel.ml.yml
    devices:
      - /dev/dri:/dev/dri
    environment:
      - TZ=${TZ}
      # - IMMICH_LOG_LEVEL=debug
    networks:
      stack_network:
    volumes:
      - model-cache:/cache
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/valkey/valkey:8
    restart: unless-stopped
    user: root
    group_add:
      - ${DOCKER_GROUP_ID}
    security_opt:
      - seccomp=unconfined
      - apparmor=unconfined
    environment:
      - TZ=${TZ}
    networks:
      stack_network:
    healthcheck:
      test: redis-cli ping || exit 1

  database:
    container_name: immich_postgres
    # Keep tag updated with https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    image: ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0
    restart: unless-stopped
    user: root
    group_add:
      - ${DOCKER_GROUP_ID}
    security_opt:
      - seccomp=unconfined
      - apparmor=unconfined
    environment:
      - TZ=${TZ}
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=immich
      - POSTGRES_INITDB_ARGS=--data-checksums
    networks:
      stack_network:
    volumes:
      - ${APPDATA_DIR}/immich/database:/var/lib/postgresql/data
    shm_size: 128mb

Your .env content

# Not using .env

Reproduction steps

  1. Clean install.
  2. Use immich-go to import pictures.
  3. Note that all job ques drain, but "Extract Metadata" job queue has 1 item pending and it stays there forever.
  4. Use immich-go to import videos.
  5. Note that all job ques drain, but "Extract Metadata" job queue has 1 item pending and it stays there forever.
  6. Review logs, and note a DB constraint violation error, and server DB connection errors, and FFmpeg errors.

DB Log:

 2025-12-04 11:57:23.738 PST [126] ERROR:  duplicate key value violates unique constraint "UQ_assets_owner_checksum"
 2025-12-04 11:57:23.738 PST [126] DETAIL:  Key ("ownerId", checksum)=(4eb384b0-b4fa-4770-8027-b3ad73d3ed88, \x0f3d7a19f26be5d215dd594e17454a46bc657e1e) already exists.
 2025-12-04 11:57:23.738 PST [126] STATEMENT:  insert into "asset" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "duration", "visibility", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) returning *

Server log:

�[32m[Nest] 7  - �[39m12/04/2025, 11:56:44 AM �[32m    LOG�[39m �[33m[Microservices:SystemConfigService]�[39m �[32mLogLevel=log (set via system config)�[39m
 Query failed : {
   durationMs: 1.6470660000049975,
   error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum"
       at ErrorResponse (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:794:26)
       at handle (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:480:6)
       at Socket.data (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:315:9)
       at Socket.emit (node:events:518:28)
       at addChunk (node:internal/streams/readable:561:12)
       at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
       at Readable.push (node:internal/streams/readable:392:5)
       at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
       at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
     severity_local: 'ERROR',
     severity: 'ERROR',
     code: '23505',
     detail: 'Key ("ownerId", checksum)=(4eb384b0-b4fa-4770-8027-b3ad73d3ed88, \\x0f3d7a19f26be5d215dd594e17454a46bc657e1e) already exists.',
     schema_name: 'public',
     table_name: 'asset',
     constraint_name: 'UQ_assets_owner_checksum',
     file: 'nbtinsert.c',
     line: '663',
     routine: '_bt_check_unique'
   },
   sql: 'insert into "asset" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "duration", "visibility", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) returning *',
   params: [
     '4eb384b0-b4fa-4770-8027-b3ad73d3ed88',
     null,
     <Buffer 0f 3d 7a 19 f2 6b e5 d2 15 dd 59 4e 17 45 4a 46 bc 65 7e 1e>,
     '/data/upload/4eb384b0-b4fa-4770-8027-b3ad73d3ed88/a5/35/a5356474-baf6-457b-ba7c-5be3b5fe680d.MOV',
     'IMG_5475 (1).MOV-19466360',
     'server-2',
     2020-12-25T10:33:44.000Z,
     2025-11-27T15:19:28.846Z,
     2020-12-25T10:33:44.000Z,
     'VIDEO',
     false,
     '00:00:00.000000',
     'timeline',
     'IMG_5475 (1).MOV'
   ]
 }
 Query failed : {
   durationMs: 3.2802799999481067,
   error: PostgresError: duplicate key value violates unique constraint "UQ_assets_owner_checksum"
       at ErrorResponse (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:794:26)
       at handle (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:480:6)
       at Socket.data (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:315:9)
       at Socket.emit (node:events:518:28)
       at addChunk (node:internal/streams/readable:561:12)
       at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
       at Readable.push (node:internal/streams/readable:392:5)
       at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
       at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
     severity_local: 'ERROR',
     severity: 'ERROR',
     code: '23505',
     detail: 'Key ("ownerId", checksum)=(4eb384b0-b4fa-4770-8027-b3ad73d3ed88, \\x84642378e1eab551aec5c5164705f8a302f4156c) already exists.',
     schema_name: 'public',
     table_name: 'asset',
     constraint_name: 'UQ_assets_owner_checksum',
     file: 'nbtinsert.c',
     line: '663',
     routine: '_bt_check_unique'
   },
   sql: 'insert into "asset" ("ownerId", "libraryId", "checksum", "originalPath", "deviceAssetId", "deviceId", "fileCreatedAt", "fileModifiedAt", "localDateTime", "type", "isFavorite", "duration", "visibility", "originalFileName") values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) returning *',
   params: [
     '4eb384b0-b4fa-4770-8027-b3ad73d3ed88',
     null,
     <Buffer 84 64 23 78 e1 ea b5 51 ae c5 c5 16 47 05 f8 a3 02 f4 15 6c>,
     '/data/upload/4eb384b0-b4fa-4770-8027-b3ad73d3ed88/68/8a/688a5d53-7615-4f8e-9344-1d0ac8b8cb93.JPG',
     'IMG_2101.JPG-129835',
     'server-2',
     2025-11-27T04:14:11.529Z,
     2025-11-27T04:14:11.529Z,
     2025-11-27T04:14:11.529Z,
     'IMAGE',
     false,
     '00:00:00.000000',
     'timeline',
     'IMG_2101.JPG'
   ]
 }
 �[32m[Nest] 7  - �[39m12/04/2025, 12:01:01 PM �[32m    LOG�[39m �[33m[Microservices:MediaService]�[39m �[32mTranscoding video fda41470-0934-4150-916b-87135a26a21c with VAAPI-accelerated encoding and software decoding�[39m

Server log:

�[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:LibraryService]�[39m �[32mInitiating scan of all external libraries...�[39m
 �[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:LibraryService]�[39m �[32mChecking for any libraries pending deletion...�[39m
 �[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:SessionService]�[39m �[32mDeleted 0 expired session tokens�[39m
 Query failed : {
   durationMs: 0.15859799832105637,
   error: Error: write CONNECTION_DESTROYED database:5432
       at Object.execute (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:156:35)
       at Query.handler (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/index.js:230:13)
       at Query.handle (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/query.js:140:65)
       at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
     code: 'CONNECTION_DESTROYED',
     errno: 'CONNECTION_DESTROYED',
     address: [ 'database' ],
     port: [ 5432 ]
   },
   sql: 'select "person".* from "person" where "person"."thumbnailPath" = $1',
   params: [ '' ]
 }

Looks like the DB connection failed while the nightly rescan job stated at 12am.

Relevant log output

�[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:LibraryService]�[39m �[32mInitiating scan of all external libraries...�[39m
 �[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:LibraryService]�[39m �[32mChecking for any libraries pending deletion...�[39m
 �[32m[Nest] 7  - �[39m12/05/2025, 12:00:00 AM �[32m    LOG�[39m �[33m[Microservices:SessionService]�[39m �[32mDeleted 0 expired session tokens�[39m
 Query failed : {
   durationMs: 0.15859799832105637,
   error: Error: write CONNECTION_DESTROYED database:5432
       at Object.execute (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/connection.js:156:35)
       at Query.handler (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/index.js:230:13)
       at Query.handle (/usr/src/app/server/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/cjs/src/query.js:140:65)
       at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
     code: 'CONNECTION_DESTROYED',
     errno: 'CONNECTION_DESTROYED',
     address: [ 'database' ],
     port: [ 5432 ]
   },
   sql: 'select "person".* from "person" where "person"."thumbnailPath" = $1',
   params: [ '' ]
 }

Additional information

immich_postgres.log
immich_server.log
immich_redis.log
immich_machine_learning.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions