Skip to content

postgresql.override.conf should not be located in the postgres database directory #26425

Description

@doraskayo

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

  • Yes

The bug

postgresql.override.conf is currently expected to be added to the database directory:
https://github.com/immich-app/base-images/blob/462f4b1022791ceb91d5d7b8c4bc2139120f7a65/postgres/postgresql.ssd.conf#L15

However, this means that it is not possible to create new databases with a pre-existing postgresql.override.conf file. This is because initdb expects the database directory to be empty when creating a new database, and postgresql.override.conf being present in the directory results in an error.

Specifically, when postgresql.override.conf is bound to /var/lib/postgresql/data/postgresql.override.conf` in the database container, the following error is seen for new databases:

initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
initdb: hint: If you want to create a new database system, either remove or empty the directory "/var/lib/postgresql/data" or run initdb with an argument other than "/var/lib/postgresql/data".

The only workaround is to create a database without postgresql.override.conf and add it after the database is successly created. However, doing so defeats the purpose of this file.

The OS that Immich Server is running on

Flatcar 4547.1.0

Version of Immich Server

v2.5.6

Version of Immich Mobile App

v2.5.6

Platform with the issue

  • Server
  • Web
  • Mobile

Device make and model

No response

Your docker-compose.yml content

...
  database:
    container_name: immich_postgres
    image: ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0@sha256:bcf63357191b76a916ae5eb93464d65c07511da41e3bf7a8416db519b40b1c23
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
      # Uncomment the DB_STORAGE_TYPE: 'HDD' var if your database isn't stored on SSDs
      # DB_STORAGE_TYPE: 'HDD'
    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
      - ./postgresql.override.conf:/var/lib/postgresql/data/postgresql.override.conf
    shm_size: 128mb
    restart: always
    healthcheck:
      disable: false
...

Your .env content

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

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

# The location where your database files are stored. Network shares are not supported for the database
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=Etc/UTC

# The Immich version to use. You can pin this to a specific version like "v2.1.0"
IMMICH_VERSION=v2

# 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=postgres

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

Reproduction steps

1. Make sure the host directory bound to `/var/lib/postgresql/data` in the database container is empty. Essentually a new database scenario.
2. Set `postgresql.override.conf` to be bound to `/var/lib/postgresql/data/postgresql.override.conf` in the database container.
3. Try to run the database container. You will get the error mentioned in this issue.

Relevant log output

initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
initdb: hint: If you want to create a new database system, either remove or empty the directory "/var/lib/postgresql/data" or run initdb with an argument other than "/var/lib/postgresql/data".

Additional information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions