TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.55k stars 589 forks source link

Database files are incompatible with server #2750

Closed comfreak89 closed 11 months ago

comfreak89 commented 11 months ago

Issue

Hi,

I wanted to update Tandoor to the current version. I changed my docker-compose.yml, so that postgreSQL 15 will be used. Then I get the following error:

db_recipes_1 | db_recipes_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization db_recipes_1 | db_recipes_1 | 2023-11-28 07:18:38.205 UTC [1] FATAL: database files are incompatible with server db_recipes_1 | 2023-11-28 07:18:38.205 UTC [1] DETAIL: The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5. tandoor_db_recipes_1 exited with code 1

Do I need to update the schema beforehand somehow?

I switched back to 1.5.6 for now.

Tandoor Version

1.5.8

OS Version

Ubuntu 22.04

Setup

Docker / Docker-Compose

Reverse Proxy

Nginx Proxy Manager (NPM)

Other

No response

Environment file

# only set this to true when testing/debugging
# when unset: 1 (true) - dont unset this, just for development
DEBUG=0
SQL_DEBUG=0

# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
ALLOWED_HOSTS=*

# random secret key, use for example `base64 /dev/urandom | head -c50` to generate one
SECRET_KEY=key

# your default timezone See https://timezonedb.com/time-zones for a list of timezones
TIMEZONE=Europe/Berlin

# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
DB_ENGINE=django.db.backends.postgresql
# DB_OPTIONS= {} # e.g. {"sslmode":"require"} to enable ssl
POSTGRES_HOST=db_recipes
POSTGRES_PORT=5432
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=djangodb

# database connection string, when used overrides other database settings.
# format might vary depending on backend
# DATABASE_URL = engine://username:password@host:port/dbname

# the default value for the user preference 'fractions' (enable/disable fraction support)
# default: disabled=0
FRACTION_PREF_DEFAULT=0

# the default value for the user preference 'comments' (enable/disable commenting system)
# default comments enabled=1
COMMENT_PREF_DEFAULT=1

# Users can set a amount of time after which the shopping list is refreshed when they are in viewing mode
# This is the minimum interval users can set. Setting this to low will allow users to refresh very frequently which
# might cause high load on the server. (Technically they can obviously refresh as often as they want with their own scripts)
SHOPPING_MIN_AUTOSYNC_INTERVAL=5

# Default for user setting sticky navbar
# STICKY_NAV_PREF_DEFAULT=1

# If base URL is something other than just /  (you are serving a subfolder in your proxy for instance http://recipe_app/recipes/)
# SCRIPT_NAME=/

# If staticfiles are stored at a different location uncomment and change accordingly, MUST END IN /
# this is not required if you are just using a subfolder
# This can either be a relative path from the applications base path or the url of an external host
# STATIC_URL=/static/

# If mediafiles are stored at a different location uncomment and change accordingly, MUST END IN /
# this is not required if you are just using a subfolder
# This can either be a relative path from the applications base path or the url of an external host
# MEDIA_URL=/media/

# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
# provided that include an additional nxginx container to handle media file serving.
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
GUNICORN_MEDIA=0

# S3 Media settings: store mediafiles in s3 or any compatible storage backend (e.g. minio)
# as long as S3_ACCESS_KEY is not set S3 features are disabled
# S3_ACCESS_KEY=
# S3_SECRET_ACCESS_KEY=
# S3_BUCKET_NAME=
# S3_REGION_NAME= # default none, set your region might be required
# S3_QUERYSTRING_AUTH=1 # default true, set to 0 to serve media from a public bucket without signed urls
# S3_QUERYSTRING_EXPIRE=3600 # number of seconds querystring are valid for
# S3_ENDPOINT_URL= # when using a custom endpoint like minio

# Email Settings, see https://docs.djangoproject.com/en/3.2/ref/settings/#email-host
# Required for email confirmation and password reset (automatically activates if host is set)
 EMAIL_HOST=ip
 EMAIL_PORT=25
# EMAIL_HOST_USER=
# EMAIL_HOST_PASSWORD=
# EMAIL_USE_TLS=0
# EMAIL_USE_SSL=0
 DEFAULT_FROM_EMAIL= email
# ACCOUNT_EMAIL_SUBJECT_PREFIX= # prefix used for account related emails (default "[Tandoor Recipes] ")

# allow authentication via reverse proxy (e.g. authelia), leave off if you dont know what you are doing
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
# when unset: 0 (false)
REVERSE_PROXY_AUTH=0

# Default settings for spaces, apply per space and can be changed in the admin view
# SPACE_DEFAULT_MAX_RECIPES=0 # 0=unlimited recipes
# SPACE_DEFAULT_MAX_USERS=0 # 0=unlimited users per space
# SPACE_DEFAULT_MAX_FILES=0 # Maximum file storage for space in MB. 0 for unlimited, -1 to disable file upload.
# SPACE_DEFAULT_ALLOW_SHARING=1 # Allow users to share recipes with public links

# allow people to create accounts on your application instance (without an invite link)
# when unset: 0 (false)
# ENABLE_SIGNUP=0

# If signup is enabled you might want to add a captcha to it to prevent spam
# HCAPTCHA_SITEKEY=
# HCAPTCHA_SECRET=

# if signup is enabled you might want to provide urls to data protection policies or terms and conditions
# TERMS_URL=
# PRIVACY_URL=
# IMPRINT_URL=

# enable serving of prometheus metrics under the /metrics path
# ATTENTION: view is not secured (as per the prometheus default way) so make sure to secure it
# trough your web server (or leave it open of you dont care if the stats are exposed)
# ENABLE_METRICS=0

# allows you to setup OAuth providers
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
# SOCIAL_PROVIDERS = allauth.socialaccount.providers.github, allauth.socialaccount.providers.nextcloud,

# Should a newly created user from a social provider get assigned to the default space and given permission by default ?
# ATTENTION: This feature might be deprecated in favor of a space join and public viewing system in the future
# default 0 (false), when 1 (true) users will be assigned space and group
# SOCIAL_DEFAULT_ACCESS = 1

# if SOCIAL_DEFAULT_ACCESS is used, which group should be added
# SOCIAL_DEFAULT_GROUP=guest

# Django session cookie settings. Can be changed to allow a single django application to authenticate several applications
# when running under the same database
# SESSION_COOKIE_DOMAIN=.example.com
# SESSION_COOKIE_NAME=sessionid # use this only to not interfere with non unified django applications under the same top level domain

# by default SORT_TREE_BY_NAME is disabled this will store all Keywords and Food in the order they are created
# enabling this setting makes saving new keywords and foods very slow, which doesn't matter in most usecases.
# however, when doing large imports of recipes that will create new objects, can increase total run time by 10-15x
# Keywords and Food can be manually sorted by name in Admin
# This value can also be temporarily changed in Admin, it will revert the next time the application is started
# This will be fixed/changed in the future by changing the implementation or finding a better workaround for sorting
# SORT_TREE_BY_NAME=0
# LDAP authentication
# default 0 (false), when 1 (true) list of allowed users will be fetched from LDAP server
#LDAP_AUTH=
#AUTH_LDAP_SERVER_URI=
#AUTH_LDAP_BIND_DN=
#AUTH_LDAP_BIND_PASSWORD=
#AUTH_LDAP_USER_SEARCH_BASE_DN=

Docker-Compose file

version: "3"
services:
  db_recipes:
    restart: always
    image: postgres:15-alpine
    volumes:
      - ./postgresql:/var/lib/postgresql/data
    env_file:
      - ./.env
    labels:
      - "com.centurylinklabs.watchtower.enable=false"

  web_recipes:
    image: vabene1111/recipes
    restart: always
    env_file:
      - ./.env
    volumes:
      - ./staticfiles:/opt/recipes/staticfiles
      - ./nginx_config:/opt/recipes/nginx/conf.d
      - ./mediafiles:/opt/recipes/mediafiles
    depends_on:
      - db_recipes
    labels:
      - "com.centurylinklabs.watchtower.enable=false"

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 8081:80
    env_file:
      - ./.env
    depends_on:
      - web_recipes
    volumes:
      - ./nginx_config:/etc/nginx/conf.d:ro
      - ./staticfiles:/static
      - ./mediafiles:/media
    labels:
      - "com.centurylinklabs.watchtower.enable=false"

volumes:
  nginx_config:
  staticfiles:

Relevant logs

root@docker:~/dockerCompose/tandoor# docker-compose up
Pulling db_recipes (postgres:15-alpine)...
15-alpine: Pulling from library/postgres
96526aa774ef: Already exists
f3836ccc9a67: Pull complete
3625732fb368: Pull complete
db2cf8153bfe: Pull complete
57d1e4d158ff: Pull complete
d4b037398667: Pull complete
fffdf7fd1f65: Pull complete
6fbe9502899e: Pull complete
Digest: sha256:793bbc22cf8dfc7962c006e8e326d19e60ad756d1185ed875e25d4494b16dd66
Status: Downloaded newer image for postgres:15-alpine
Recreating tandoor_db_recipes_1 ... done
Recreating tandoor_web_recipes_1 ... done
Recreating tandoor_nginx_recipes_1 ... done
Attaching to tandoor_db_recipes_1, tandoor_web_recipes_1, tandoor_nginx_recipes_1
nginx_recipes_1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_recipes_1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
db_recipes_1     | 
db_recipes_1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_recipes_1     | 
web_recipes_1    | Checking configuration...
web_recipes_1    | Waiting for database to be ready...
nginx_recipes_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_recipes_1  | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
db_recipes_1     | 2023-11-28 07:18:29.182 UTC [1] FATAL:  database files are incompatible with server
db_recipes_1     | 2023-11-28 07:18:29.182 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5.
nginx_recipes_1  | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
nginx_recipes_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_recipes_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx_recipes_1  | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: using the "epoll" event method
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: nginx/1.25.3
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: OS: Linux 5.15.0-89-generic
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: start worker processes
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: start worker process 20
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: start worker process 21
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: start worker process 22
nginx_recipes_1  | 2023/11/28 07:18:30 [notice] 1#1: start worker process 23
tandoor_db_recipes_1 exited with code 1
db_recipes_1     | 
db_recipes_1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_recipes_1     | 
db_recipes_1     | 2023-11-28 07:18:31.354 UTC [1] FATAL:  database files are incompatible with server
db_recipes_1     | 2023-11-28 07:18:31.354 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5.
db_recipes_1     | 
db_recipes_1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_recipes_1     | 
db_recipes_1     | 2023-11-28 07:18:32.550 UTC [1] FATAL:  database files are incompatible with server
db_recipes_1     | 2023-11-28 07:18:32.550 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5.
tandoor_db_recipes_1 exited with code 1
db_recipes_1     | 
db_recipes_1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_recipes_1     | 
db_recipes_1     | 2023-11-28 07:18:34.587 UTC [1] FATAL:  database files are incompatible with server
db_recipes_1     | 2023-11-28 07:18:34.587 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5.
tandoor_db_recipes_1 exited with code 1
db_recipes_1     | 
db_recipes_1     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_recipes_1     | 
db_recipes_1     | 2023-11-28 07:18:38.205 UTC [1] FATAL:  database files are incompatible with server
db_recipes_1     | 2023-11-28 07:18:38.205 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 15.5.
tandoor_db_recipes_1 exited with code 1
tomsinclair94 commented 11 months ago

I am also having the same problem after upgrading to 1.5.8. I have also reverted back to 1.5.6 for now. I found my docker compose is still using PostgreSQL v11 and it appears 1.5.8 needs PostgreSQL 12 or later. I updated my docker compose to try both PostgreSQL v12 and v15 and experienced a similar issue as @comfreak89 found. I found a few resources on this GitHub about migrating the DB from v11 to a higher version but I couldn't quite figure out how to do it for a docker container setup.

Any advice on how to migrate the PostgreSQL DB from v11 to something higher (say v15) would be appreciated as it seems this is required to upgrade beyond v1.5.6!

smilerz commented 11 months ago

Duplicate #2550 Postgres does not automatically upgrade versions, you can see avaible methods here