User is not deleted after X days (foreign key violation) #3225

Closed
opened 2026-02-05 08:05:00 +03:00 by OVERLORD · 0 comments
Owner

Originally created by @Altycoder on GitHub (May 23, 2024).

The bug

After 7 days a user had not been deleted. I reduce the number of days to 3 and the next night some errors were apparent in the microservices log

The OS that Immich Server is running on

Arch LTS Kernel

Version of Immich Server

v1.105.1

Version of Immich Mobile App

v1.105.0 build.139

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    command: ['start.sh', 'immich']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
      file: hwaccel.transcoding.yml
      service: quicksync # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    command: ['start.sh', 'microservices']
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
    #   file: hwaccel.ml.yml
    #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - model-cache:/cache
    env_file:
      - .env
    restart: always

  redis:
    container_name: immich_redis
    image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:84882e87b54734154586e5f8abd4dce69fe7311315e2fc6d67c29614c8de2672
    restart: always

  database:
    container_name: immich_postgres
    image: registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    volumes:
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    restart: always
    command: ["postgres", "-c" ,"shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"]

#https://immich.app/docs/administration/backup-and-restore/
  backup:
    container_name: immich_db_dumper
    image: prodrigestivill/postgres-backup-local:14
    restart: always
    env_file:
      - .env
    environment:
      POSTGRES_HOST: database
      POSTGRES_CLUSTER: 'TRUE'
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      SCHEDULE: "@daily" #once a day at midnight
      POSTGRES_EXTRA_OPTS: '--clean --if-exists'
      BACKUP_DIR: /db_dumps
    volumes:
      - /mnt/btrfs_raid/Backup/Backups/immich_db:/db_dumps
    depends_on:
      - database

volumes:
  model-cache:

Your .env content

# The location where your uploaded files are stored
UPLOAD_LOCATION=/mnt/docker/immich/upload #/mnt/btrfs_raid/Backup/Photos/immich

#postgres db location
DB_DATA_LOCATION=/mnt/docker/immich/db

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=v1.105.1 #release

# Connection secrets for postgres and typesense. You should change these to random passwords
#TYPESENSE_API_KEY='moToNfvEsAoE#GfhBeWH6t8o!ayB77'
DB_PASSWORD=<redacted>

# The values below this line do not need to be changed
#DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_DATABASE_NAME=immich
#REDIS_HOSTNAME=immich_redis

Reproduction steps

Delete a user
User is not deleted after X days (7 or 3 when reduced)

Relevant log output

[Nest] 7  - 05/23/2024, 12:00:00 AM     LOG [ImmichMicroservices] [UserService] Deleting user: 91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:00 AM    WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/library/91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:00 AM    WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/upload/91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:00 AM    WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/profile/91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:00 AM    WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/thumbs/91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:07 AM    WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/encoded-video/91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:07 AM    WARN [ImmichMicroservices] [UserService] Removing user from database: 91fb45dd-f8c6-474e-94a8-25960f31b3b3
[Nest] 7  - 05/23/2024, 12:00:22 AM   ERROR [ImmichMicroservices] [JobService] Unable to run job handler (backgroundTask/user-deletion): QueryFailedError: update or delete on table "assets" violates foreign key constraint "FK_91704e101438fd0653f582426dc" on table "asset_stack"
    at async UserService.handleUserDelete (/usr/src/app/dist/services/user.service.js:179:9)

Additional information

No response

Originally created by @Altycoder on GitHub (May 23, 2024). ### The bug After 7 days a user had not been deleted. I reduce the number of days to 3 and the next night some errors were apparent in the microservices log ### The OS that Immich Server is running on Arch LTS Kernel ### Version of Immich Server v1.105.1 ### Version of Immich Mobile App v1.105.0 build.139 ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML services: immich-server: container_name: immich_server image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release} command: ['start.sh', 'immich'] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - /etc/localtime:/etc/localtime:ro env_file: - .env ports: - 2283:3001 depends_on: - redis - database restart: always immich-microservices: container_name: immich_microservices image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release} extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding file: hwaccel.transcoding.yml service: quicksync # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding command: ['start.sh', 'microservices'] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - /etc/localtime:/etc/localtime:ro env_file: - .env depends_on: - redis - database restart: always immich-machine-learning: container_name: immich_machine_learning # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag. # Example tag: ${IMMICH_VERSION:-release}-cuda image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release} # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration # file: hwaccel.ml.yml # service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable volumes: - model-cache:/cache env_file: - .env restart: always redis: container_name: immich_redis image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:84882e87b54734154586e5f8abd4dce69fe7311315e2fc6d67c29614c8de2672 restart: always database: container_name: immich_postgres image: registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0 environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} volumes: - ${DB_DATA_LOCATION}:/var/lib/postgresql/data restart: always command: ["postgres", "-c" ,"shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"] #https://immich.app/docs/administration/backup-and-restore/ backup: container_name: immich_db_dumper image: prodrigestivill/postgres-backup-local:14 restart: always env_file: - .env environment: POSTGRES_HOST: database POSTGRES_CLUSTER: 'TRUE' POSTGRES_USER: ${DB_USERNAME} POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_DATABASE_NAME} SCHEDULE: "@daily" #once a day at midnight POSTGRES_EXTRA_OPTS: '--clean --if-exists' BACKUP_DIR: /db_dumps volumes: - /mnt/btrfs_raid/Backup/Backups/immich_db:/db_dumps depends_on: - database volumes: model-cache: ``` ### Your .env content ```Shell # The location where your uploaded files are stored UPLOAD_LOCATION=/mnt/docker/immich/upload #/mnt/btrfs_raid/Backup/Photos/immich #postgres db location DB_DATA_LOCATION=/mnt/docker/immich/db # The Immich version to use. You can pin this to a specific version like "v1.71.0" IMMICH_VERSION=v1.105.1 #release # Connection secrets for postgres and typesense. You should change these to random passwords #TYPESENSE_API_KEY='moToNfvEsAoE#GfhBeWH6t8o!ayB77' DB_PASSWORD=<redacted> # The values below this line do not need to be changed #DB_HOSTNAME=immich_postgres DB_USERNAME=postgres DB_DATABASE_NAME=immich #REDIS_HOSTNAME=immich_redis ``` ### Reproduction steps ```bash Delete a user User is not deleted after X days (7 or 3 when reduced) ``` ### Relevant log output ```shell [Nest] 7 - 05/23/2024, 12:00:00 AM LOG [ImmichMicroservices] [UserService] Deleting user: 91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:00 AM WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/library/91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:00 AM WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/upload/91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:00 AM WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/profile/91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:00 AM WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/thumbs/91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:07 AM WARN [ImmichMicroservices] [UserService] Removing user from filesystem: upload/encoded-video/91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:07 AM WARN [ImmichMicroservices] [UserService] Removing user from database: 91fb45dd-f8c6-474e-94a8-25960f31b3b3 [Nest] 7 - 05/23/2024, 12:00:22 AM ERROR [ImmichMicroservices] [JobService] Unable to run job handler (backgroundTask/user-deletion): QueryFailedError: update or delete on table "assets" violates foreign key constraint "FK_91704e101438fd0653f582426dc" on table "asset_stack" at async UserService.handleUserDelete (/usr/src/app/dist/services/user.service.js:179:9) ``` ### Additional information _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#3225