ERROR [TypeOrmModule] Unable to connect to the database

Is anyone else having this issue here? https://github.com/immich-app/immich/issues/2476 I've tired the fix here https://github.com/immich-app/immich/issues/2931#issuecomment-1605396092 but it won't work as the postgres container won't start for long enough to be able to exec into the bash to apply the fix.
GitHub
[BUG] Docker stack can not connect to DB · Issue #2476 · immich-app...
The bug For unknow reason my docker crashed. After that i am unable to get Immich to work. I have tried backup of the whole VM running docker and also tried to create new networks and assign them i...
GitHub
[BUG] Postgres database failed to start after 1.63.0 update · Issue...
The bug I updated my docker containers this morning to the latest versions and Immich fails to full start (get a 500 error). There are errors in the logs that it cannot connect to the database. So ...
25 Replies
bo0tzz
bo0tzz•2y ago
If your postgres container isn't starting up at all then this is probably not an immich problem. Can you post the postgres logs?
CyberSocialist
CyberSocialistOP•2y ago
20/08/2023 22:10:19 Error: Database is uninitialized and superuser password is not specified. 20/08/2023 22:10:19 You must specify POSTGRES_PASSWORD to a non-empty value for the 20/08/2023 22:10:19 superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run". 20/08/2023 22:10:19 20/08/2023 22:10:19 You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all 20/08/2023 22:10:19 connections without a password. This is not recommended. 20/08/2023 22:10:19 20/08/2023 22:10:19 See PostgreSQL documentation about "trust": 20/08/2023 22:10:19 https://www.postgresql.org/docs/current/auth-trust.html 20/08/2023 22:10:21 Error: Database is uninitialized and superuser password is not specified. 20/08/2023 22:10:21 You must specify POSTGRES_PASSWORD to a non-empty value for the 20/08/2023 22:10:21 superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
PostgreSQL Documentation
21.4. Trust Authentication
21.4. Trust Authentication When trust authentication is specified, PostgreSQL assumes that anyone who can connect to the server is authorized to …
CyberSocialist
CyberSocialistOP•2y ago
(might be useful to note that the pgdata folder also seems to have its owner remapped to '70' and not the user that the container is started as....that an issue?)
bo0tzz
bo0tzz•2y ago
Is this a new setup or a preexisting one? If the latter, have you made any changes etc recently?
CyberSocialist
CyberSocialistOP•2y ago
brand new
bo0tzz
bo0tzz•2y ago
Then the error about missing POSTGRES_PASSWORD is the one to go off. Are you using the standard compose setup?
CyberSocialist
CyberSocialistOP•2y ago
yes - except for one thing: I've changed the name for the container 'database' to 'immich_postgres' - but I've made sure (i think) that that name change is reflected everywhere else that 'database' was referenced. Unless this is a hard coded variable?
bo0tzz
bo0tzz•2y ago
Can you post your compose and .env?
CyberSocialist
CyberSocialistOP•2y ago
(I can - but the character limits will wreck it)

version: "3.8"

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
env_file:
- /home/admin/Docker/immich/env/.env
depends_on:
- immich_redis
- immich_postgres
- typesense
restart: always

immich-microservices:
container_name: immich_microservices
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
# extends:
# file: hwaccel.yml
# service: hwaccel
command: [ "start.sh", "microservices" ]
volumes:
- ${UPLOAD_LOCATION}/:/usr/src/app/upload
env_file:
- "/home/admin/Docker/immich/env/.env" #in the immich bind mount folder "/immich/env"
depends_on:
- immich_redis
- immich_postgres
- typesense
restart: always

version: "3.8"

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
env_file:
- /home/admin/Docker/immich/env/.env
depends_on:
- immich_redis
- immich_postgres
- typesense
restart: always

immich-microservices:
container_name: immich_microservices
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
# extends:
# file: hwaccel.yml
# service: hwaccel
command: [ "start.sh", "microservices" ]
volumes:
- ${UPLOAD_LOCATION}/:/usr/src/app/upload
env_file:
- "/home/admin/Docker/immich/env/.env" #in the immich bind mount folder "/immich/env"
depends_on:
- immich_redis
- immich_postgres
- typesense
restart: always

immich-machine-learning:
container_name: immich_machine_learning
image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
volumes:
- "/home/admin/Docker/immich/model-cache/:/cache"
env_file:
- "/home/admin/Docker/immich/env/.env"
restart: always

immich-web:
container_name: immich_web
image: ghcr.io/immich-app/immich-web:${IMMICH_VERSION:-release}
env_file:
- "/home/admin/Docker/immich/env/.env"
restart: always

typesense:
container_name: immich_typesense
image: typesense/typesense:0.24.1@sha256:9bcff2b829f12074426ca044b56160ca9d777a0c488303469143dd9f8259d4dd
environment:
- TYPESENSE_API_KEY=${TYPESENSE_API_KEY}
- TYPESENSE_DATA_DIR=/data
# remove this to get debug messages
- GLOG_minloglevel=1
volumes:
- "/home/admin/Docker/immich/tsdata/:/data"
restart: always

immich_redis: #redis
container_name: immich_redis
image: redis:6.2-alpine@sha256:70a7a5b641117670beae0d80658430853896b5ef269ccf00d1827427e3263fa3
restart: always

immich_postgres: #database
container_name: immich_postgres
image: postgres:14-alpine@sha256:28407a9961e76f2d285dc6991e8e48893503cc3836a4755bbc2d40bcc272a441
env_file:
- "/home/admin/Docker/immich/env/.env"
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
volumes:
- "/home/admin/Docker/immich/pgdata/:/var/lib/postgresql/data"
restart: always

immich-proxy:
container_name: immich_proxy
image: ghcr.io/immich-app/immich-proxy:${IMMICH_VERSION:-release}
environment:
# Make sure these values get passed through from the env file
- IMMICH_SERVER_URL
- IMMICH_WEB_URL
ports:
- 2283:8080
depends_on:
- immich-server
- immich-web
restart: always

#volumes:
# pgdata:
# model-cache:
# tsdata:

immich-machine-learning:
container_name: immich_machine_learning
image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
volumes:
- "/home/admin/Docker/immich/model-cache/:/cache"
env_file:
- "/home/admin/Docker/immich/env/.env"
restart: always

immich-web:
container_name: immich_web
image: ghcr.io/immich-app/immich-web:${IMMICH_VERSION:-release}
env_file:
- "/home/admin/Docker/immich/env/.env"
restart: always

typesense:
container_name: immich_typesense
image: typesense/typesense:0.24.1@sha256:9bcff2b829f12074426ca044b56160ca9d777a0c488303469143dd9f8259d4dd
environment:
- TYPESENSE_API_KEY=${TYPESENSE_API_KEY}
- TYPESENSE_DATA_DIR=/data
# remove this to get debug messages
- GLOG_minloglevel=1
volumes:
- "/home/admin/Docker/immich/tsdata/:/data"
restart: always

immich_redis: #redis
container_name: immich_redis
image: redis:6.2-alpine@sha256:70a7a5b641117670beae0d80658430853896b5ef269ccf00d1827427e3263fa3
restart: always

immich_postgres: #database
container_name: immich_postgres
image: postgres:14-alpine@sha256:28407a9961e76f2d285dc6991e8e48893503cc3836a4755bbc2d40bcc272a441
env_file:
- "/home/admin/Docker/immich/env/.env"
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
volumes:
- "/home/admin/Docker/immich/pgdata/:/var/lib/postgresql/data"
restart: always

immich-proxy:
container_name: immich_proxy
image: ghcr.io/immich-app/immich-proxy:${IMMICH_VERSION:-release}
environment:
# Make sure these values get passed through from the env file
- IMMICH_SERVER_URL
- IMMICH_WEB_URL
ports:
- 2283:8080
depends_on:
- immich-server
- immich-web
restart: always

#volumes:
# pgdata:
# model-cache:
# tsdata:
```

# The location where your uploaded files are stored
UPLOAD_LOCATION=/home/admin/Docker/immich/upload


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

# Connection secrets for postgres and typesense. You should change these to random passwords
TYPESENSE_API_KEY=xxxxxxxxxxxxx!xxxxxxxxxxxx
DB_PASSWORD=postgres

# 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

PUBLIC_LOGIN_PAGE_MESSAGE=Welcome to my album
IMMICH_WEB_URL=http://immich-web:3000
IMMICH_SERVER_URL=http://immich-server:3001
IMMICH_MACHINE_LEARNING_URL=http://immich-machine-learning:3003
```

# The location where your uploaded files are stored
UPLOAD_LOCATION=/home/admin/Docker/immich/upload


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

# Connection secrets for postgres and typesense. You should change these to random passwords
TYPESENSE_API_KEY=xxxxxxxxxxxxx!xxxxxxxxxxxx
DB_PASSWORD=postgres

# 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

PUBLIC_LOGIN_PAGE_MESSAGE=Welcome to my album
IMMICH_WEB_URL=http://immich-web:3000
IMMICH_SERVER_URL=http://immich-server:3001
IMMICH_MACHINE_LEARNING_URL=http://immich-machine-learning:3003
(please excuse the formatting nightmare - is there a better way of sharing the compose and env?)
martabal
martabal•2y ago
wrap your text in (```) it's easier to read 😄
CyberSocialist
CyberSocialistOP•2y ago
oh - how do I do that? (and yeah, I bet it will be!)
martabal
martabal•2y ago
It's a bit hard to explain on discord without triggering it lol
CyberSocialist
CyberSocialistOP•2y ago
wow that is nicer! thank you
bo0tzz
bo0tzz•2y ago
Is your .env file in the same folder as the compose yml?
CyberSocialist
CyberSocialistOP•2y ago
No. But it’s path is correct . Does it not follow paths?
bo0tzz
bo0tzz•2y ago
The .env is used in two ways: to set variables for the containers, and for interpolating into the compose file (${FOO}). For the latter, I believe it needs to be in the same folder
CyberSocialist
CyberSocialistOP•2y ago
Ah. Ok. So I need to move it back then, I’ll try that. Quick question: where is that documented? It seems that containers do this differently, and it’s never really clear…did I miss this ?
J
J•2y ago
Docker Documentation
Ways to set environment variables in Compose
How to set, use and manage environment variables in Compose
CyberSocialist
CyberSocialistOP•2y ago
ok - we're getting there... now I'm seeing this from the 'immich_microservices' container. Anyone any thoughts?

immich_microservices | Error: connect ETIMEDOUT
immich_microservices | at Socket.<anonymous> (/usr/src/app/node_modules/ioredis/built/Redis.js:170:41)
immich_microservices | at Object.onceWrapper (node:events:628:28)
immich_microservices | at Socket.emit (node:events:514:28)
immich_microservices | at Socket._onTimeout (node:net:571:8)
immich_microservices | at listOnTimeout (node:internal/timers:569:17)
immich_microservices | at process.processTimers (node:internal/timers:512:7) {
immich_microservices | errorno: 'ETIMEDOUT',
immich_microservices | code: 'ETIMEDOUT',
immich_microservices | syscall: 'connect'

immich_microservices | Error: connect ETIMEDOUT
immich_microservices | at Socket.<anonymous> (/usr/src/app/node_modules/ioredis/built/Redis.js:170:41)
immich_microservices | at Object.onceWrapper (node:events:628:28)
immich_microservices | at Socket.emit (node:events:514:28)
immich_microservices | at Socket._onTimeout (node:net:571:8)
immich_microservices | at listOnTimeout (node:internal/timers:569:17)
immich_microservices | at process.processTimers (node:internal/timers:512:7) {
immich_microservices | errorno: 'ETIMEDOUT',
immich_microservices | code: 'ETIMEDOUT',
immich_microservices | syscall: 'connect'
bo0tzz
bo0tzz•2y ago
That's a redis error, is redis up and running?
CyberSocialist
CyberSocialistOP•2y ago
dozzzle shows it as fine
bo0tzz
bo0tzz•2y ago
dozzle?? Are the redis logs happy, and is the hostname that you configured correct?
CyberSocialist
CyberSocialistOP•2y ago
So question around that: is the host name supposed to match the local IP, or the globally reachable URL that will be on the letsencrypt certificate ? Or some other placeholder url if this is never to be internet-facing? (Say accessed over a vpn, for example)
bo0tzz
bo0tzz•2y ago
redis is running internal to the docker network, and gets a DNS name assigned based on its container name (usually immich_redis iirc, the defaults should work if you don't touch any of it)

Did you find this page helpful?