Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database connection failed #93

Open
Raman236 opened this issue Dec 19, 2024 · 10 comments
Open

Database connection failed #93

Raman236 opened this issue Dec 19, 2024 · 10 comments

Comments

@Raman236
Copy link

I have followed the directions for the docker version, however did not work:
image

I placed this at the end of the docker compose file
power-tools:
container_name: immich_power_tools
image: ghcr.io/varun-raj/immich-power-tools:latest
ports:
- "2284:3000"
env_file:
- .env
depends_on:
- redis
- database

got the API key and placed this in the .env file at the end

REQUIRED For IMMICH TOOL

IMMICH_API_KEY=CI*****************************EBIo # your_immich_api_key (Key hidden obviously)
IMMICH_URL = "http://192.168.1.60:2283" # Your immich instace ip address and port
EXTERNAL_IMMICH_URL = "https://photos*************" # External address of immich

@Beard666
Copy link

I'm having the same issue. I have successfully connected to the immich DB using PGAdmin with the same credentials as in the immich-power-tools container. Based on my limited understanding of the scenario, the issue seems to be on the power-tools side.

@jackbrown1993
Copy link
Contributor

Have you tried setting DB_HOST="" to the name of your database container? Looking at your 'depends' section if your immich database container is called 'database try adding DB_HOST='database' to .env

@TheBToby
Copy link

I'm facing the same issue. DB_HOST in .env did not solve the issue.

@jackbrown1993
Copy link
Contributor

Can you run a docker inspect followed by the name of your Immich database container? You will need to ensure the database container has a network in common with the power tools container to ensure reachability.

@TheBToby
Copy link

I'm running all the containers in Portainer. All Immich containers are on the same network. If you need any further details on the individual container, I can pull the inspect.
image

@Beard666
Copy link

I'm running all the containers in Portainer. All Immich containers are on the same network. If you need any further details on the individual container, I can pull the inspect. image

FYI I have the exact same scenario on my setup.

@jackbrown1993
Copy link
Contributor

jackbrown1993 commented Dec 20, 2024

Please ensure you have set the below environmental variables on the immich_power_tools container and that they match the immich_postgres database settings

DB_USERNAME=
DB_PASSWORD=
DB_DATABASE_NAME=
DB_HOST= (this will default to immich_postgres)
DB_PORT= (this will default to 5432)

If you view your immich_postgres container on portainer you can copy and paste the values from there for username, password and database name.

@TheBToby
Copy link

Sure. These are all my env variables:

UPLOAD_LOCATION=medianas_immich
DB_DATA_LOCATION=./postgres
DB_PASSWORD=******************
IMMICH_VERSION=release
DB_USERNAME=postgres
DB_DATABASE_NAME=immich
MACHINE_LEARNING_WORKER_TIMEOUT=600
TZ=Europe/Zurich
CPU_CORES=4
IMMICH_API_KEY=*************************
IMMICH_URL=http://192.168.0.12:2283
EXTERNAL_IMMICH_URL=https://xxx.yyy.zzz
DB_HOST=immich_postgres
DB_PORT=5432

and my full composer:

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    devices:
      - /dev/dri:/dev/dri
    # extends:
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    volumes:
      # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
      - medianas_photos:/home/user/photos_nas:ro
    env_file:
      - stack.env
    ports:
      - '2283:2283'
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false
    labels:
      "com.centurylinklabs.watchtower.enable": true

  power-tools:
    container_name: immich_power_tools
    image: ghcr.io/varun-raj/immich-power-tools:latest
    ports:
      - '8001:3000'
    env_file:
      - stack.env
    restart: always
    labels:
      "com.centurylinklabs.watchtower.enable": true
  
  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}-openvino
    device_cgroup_rules:
      - 'c 189:* rmw'
    devices:
      - /dev/dri:/dev/dri
    # 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:
      - stack.env
    restart: always
    healthcheck:
      disable: false
    labels:
      "com.centurylinklabs.watchtower.enable": true

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:eaba718fecd1196d88533de7ba49bf903ad33664a92debb24660a922ecd9cac8
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    ports:
      - '5432:5432'
    volumes:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) 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

volumes:
  model-cache:
  medianas_photos:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=medianas,nolock,soft,ro,nfsvers=4"
      device: ":/volume1/Media/Photos"
  medianas_immich:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=medianas,nolock,soft,rw,nfsvers=4"
      device: ":/volume1/Immich"   

networks:
  hexabase-network:
    external: true

@Raman236
Copy link
Author

Raman236 commented Dec 20, 2024

This is my .env File:

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables

# The location where your uploaded files are stored
UPLOAD_LOCATION=./library
# The location where your database files are stored
DB_DATA_LOCATION=./postgres

# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
# TZ=Pacific/Auckland

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

# Connection secret for postgres. You should change it to a random password
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
DB_PASSWORD=*******************************

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich
DB_HOST=192.168.176.4 # Postgres Host (IP address or hostname of the database)
DB_PORT=5432 # Postgres Port number (Default 5432)

# REQUIRED For IMMICH TOOL
IMMICH_API_KEY=C****************************************o # your_immich_api_key
IMMICH_URL = "http://192.168.1.60:2283" # Your immich instace ip address and port
EXTERNAL_IMMICH_URL = "https://photos##########" # External address of immich

The Full compose file is:

#
# WARNING: Make sure to use the docker-compose.yml of the current release:
#
# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
# The compose file on main may not be compatible with the latest release.
#

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    volumes:
      # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - '2283:2283'
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false

  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
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:2ba50e1ac3a0ea17b736ce9db2b0a9f6f8b85d4c27d5f5accc6a416d8f42c6d5
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    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

  power-tools:
    container_name: immich_power_tools
    image: ghcr.io/varun-raj/immich-power-tools:latest
    ports:
      - "2284:3000"
    env_file:
      - .env      
    depends_on:
      - redis
      - database


@TheBToby
Copy link

The latest update solved the issue in my case! Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants