immich_postgres healthcheck not working #3441

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

Originally created by @PotatoPTT on GitHub (Jun 11, 2024).

The bug

In the latest dockercompose was added a healthcheck but in immich_postgres
SELECT SUM(checksum_failures) FROM pg_stat_database returns NULL not 0, so the healthcheck fails every time
For a temporary solution i just changed to SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database

The OS that Immich Server is running on

Docker/Non Relatable

Version of Immich Server

v1.106.1

Version of Immich Mobile App

v1.106.1

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

database:
    container_name: immich_postgres
    image: ${IMMICH_POSTGRES}
    env_file:
      - .env
    networks:
      - non_exposed
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready --dbname='${DB_DATABASE_NAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT SUM(checksum_failures) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
      interval: 5m
      start_interval: 30s
      start_period: 5m
    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"]
    restart: always
    labels:
      - 'wud.watch=false'

Your .env content

NON RELATABLE

Reproduction steps

1. Run the container
2. Wait 5 minutes
3. Healthcheck fails

Relevant log output

No response

Additional information

No response

Originally created by @PotatoPTT on GitHub (Jun 11, 2024). ### The bug In the latest dockercompose was added a healthcheck but in immich_postgres `SELECT SUM(checksum_failures) FROM pg_stat_database` returns NULL not 0, so the healthcheck fails every time For a temporary solution i just changed to `SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database` ### The OS that Immich Server is running on Docker/Non Relatable ### Version of Immich Server v1.106.1 ### Version of Immich Mobile App v1.106.1 ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML database: container_name: immich_postgres image: ${IMMICH_POSTGRES} env_file: - .env networks: - non_exposed environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} POSTGRES_INITDB_ARGS: '--data-checksums' volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: pg_isready --dbname='${DB_DATABASE_NAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT SUM(checksum_failures) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1 interval: 5m start_interval: 30s start_period: 5m 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"] restart: always labels: - 'wud.watch=false' ``` ### Your .env content ```Shell NON RELATABLE ``` ### Reproduction steps ```bash 1. Run the container 2. Wait 5 minutes 3. Healthcheck fails ``` ### Relevant log output _No response_ ### Additional information _No response_
Author
Owner

@AngelaDMerkel commented on GitHub (Jun 11, 2024):

I am also experiencing this issue

@AngelaDMerkel commented on GitHub (Jun 11, 2024): I am also experiencing this issue
Author
Owner

@dsquare86 commented on GitHub (Jun 11, 2024):

Same issue on micro services and postgres

@dsquare86 commented on GitHub (Jun 11, 2024): Same issue on micro services and postgres
Author
Owner

@PotatoPTT commented on GitHub (Jun 11, 2024):

Same issue on micro services and postgres

microservices it's no longer required release notes

@PotatoPTT commented on GitHub (Jun 11, 2024): > Same issue on micro services and postgres microservices it's no longer required [release notes](https://github.com/immich-app/immich/releases/tag/v1.106.1)
Author
Owner

@zaggash commented on GitHub (Jun 11, 2024):

This is not a bug.
You are using running the DB without checksum.
So do not use the new test.

You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'.
Then restore the DB.

You database will be recreated with checksum enabled and the new healthcheck will work.

@zaggash commented on GitHub (Jun 11, 2024): This is not a bug. You are using running the DB without checksum. So do not use the new test. You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'. Then restore the DB. You database will be recreated with checksum enabled and the new healthcheck will work.
Author
Owner

@lo97 commented on GitHub (Jun 11, 2024):

This is not a bug. You are using running the DB without checksum. So do not use the new test.

You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'. Then restore the DB.

You database will be recreated with checksum enabled and the new healthcheck will work.

How should we backup the DB, create a new one and restore it? Does anyone have a step by step guide?

@lo97 commented on GitHub (Jun 11, 2024): > This is not a bug. You are using running the DB without checksum. So do not use the new test. > > You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'. Then restore the DB. > > You database will be recreated with checksum enabled and the new healthcheck will work. How should we backup the DB, create a new one and restore it? Does anyone have a step by step guide?
Author
Owner

@Tractor777 commented on GitHub (Jun 11, 2024):

This seems to work (backed up and restore) and the health check doesn't fail https://immich.app/docs/administration/backup-and-restore/#:~:text=The%20recommended%20way%20to%20backup,to%20use%20the%20pg_dumpall%20command.

@Tractor777 commented on GitHub (Jun 11, 2024): This seems to work (backed up and restore) and the health check doesn't fail https://immich.app/docs/administration/backup-and-restore/#:~:text=The%20recommended%20way%20to%20backup,to%20use%20the%20pg_dumpall%20command.
Author
Owner

@PotatoPTT commented on GitHub (Jun 11, 2024):

This is not a bug. You are using running the DB without checksum. So do not use the new test.

You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'. Then restore the DB.

You database will be recreated with checksum enabled and the new healthcheck will work.

@PotatoPTT commented on GitHub (Jun 11, 2024): > This is not a bug. You are using running the DB without checksum. So do not use the new test. > > You can however, backup the DB, then create a new one with the new env POSTGRES_INITDB_ARGS: '--data-checksums'. Then restore the DB. > > You database will be recreated with checksum enabled and the new healthcheck will work.
Author
Owner

@mertalev commented on GitHub (Jun 12, 2024):

I think this should be fixed. The health check shouldn’t report Postgres as unhealthy unless it has a reason to think it is. Adding a COALESCE would make it more elegant for existing databases (and generally for users who disable checksums).

@mertalev commented on GitHub (Jun 12, 2024): I think this should be fixed. The health check shouldn’t report Postgres as unhealthy unless it has a reason to think it is. Adding a COALESCE would make it more elegant for existing databases (and generally for users who disable checksums).
Author
Owner

@zaggash commented on GitHub (Jun 12, 2024):

It is written in the documentation FAQ
I agree it deserves more visibility

https://immich.app/docs/FAQ#how-can-i-verify-the-integrity-of-my-database

@zaggash commented on GitHub (Jun 12, 2024): It is written in the documentation FAQ I agree it deserves more visibility https://immich.app/docs/FAQ#how-can-i-verify-the-integrity-of-my-database
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#3441