Skip to content

PostgreSQL: initialize existing empty databases automatically #412

Open

Description

@EHRETic

Hi there,

I've some difficulties installing Wallbag on my docker host. After "deployment", I get an error 500 by trying to connect to the URL.

image

Docker compose:

version: '3'
services:
  wallabag:
    container_name: wallabag
    image: wallabag/wallabag:latest
    
    restart: unless-stopped
    depends_on:
      - wallabag-postgres
      
    environment:
      SYMFONY__ENV__DATABASE_DRIVER: '${SYMFONY__ENV__DATABASE_DRIVER}'
      SYMFONY__ENV__DATABASE_HOST: '${SYMFONY__ENV__DATABASE_HOST}'
      SYMFONY__ENV__DATABASE_PORT: '${SYMFONY__ENV__DATABASE_PORT}'
      SYMFONY__ENV__DATABASE_NAME: '${SYMFONY__ENV__DATABASE_NAME}'
      SYMFONY__ENV__DATABASE_USER: '${SYMFONY__ENV__DATABASE_USER}'
      SYMFONY__ENV__DATABASE_PASSWORD: '${SYMFONY__ENV__DATABASE_PASSWORD}'
      SYMFONY__ENV__DATABASE_TABLE_PREFIX: '${SYMFONY__ENV__DATABASE_TABLE_PREFIX}'
      SYMFONY__ENV__MAILER_DSN: '${SYMFONY__ENV__MAILER_DSN}'
      SYMFONY__ENV__FROM_EMAIL: '${SYMFONY__ENV__FROM_EMAIL}'
      SYMFONY__ENV__DOMAIN_NAME: '${SYMFONY__ENV__DOMAIN_NAME}'
      SYMFONY__ENV__SERVER_NAME: '${SYMFONY__ENV__SERVER_NAME}'
      POPULATE_DATABASE: '${POPULATE_DATABASE}'
      POSTGRES_USER: '${POSTGRES_USER}'
      POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
      
    volumes:
      - wallabag_images:/var/www/wallabag/web/assets/images
    
    networks:
      default:
        ipv4_address: 192.168.X.Z

    healthcheck:
      test: ["CMD", "wget" ,"--no-verbose", "--tries=1", "--spider", "http://localhost/api/info"]
      interval: 1m
      timeout: 3s

  wallabag-postgres:
    container_name: wallabag-postgres
    image: postgres:16.1-alpine
    
    restart: unless-stopped

    volumes: 
      - postgres:/var/lib/postgresql/data

    networks:
      default:
        ipv4_address: 192.168.X.Y

    environment:
      POSTGRES_USER: '${POSTGRES_USER}'
      POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'

volumes:
  wallabag_images:
  postgres:

networks:
  default:
    external: true
    name: docker_test

ENV file:

SYMFONY__ENV__DATABASE_DRIVER=pdo_pgsql
SYMFONY__ENV__DATABASE_HOST=192.168.X.Y
SYMFONY__ENV__DATABASE_PORT=5432
SYMFONY__ENV__DATABASE_NAME=wallabag
SYMFONY__ENV__DATABASE_USER=wallabag
SYMFONY__ENV__DATABASE_PASSWORD=xxx
SYMFONY__ENV__DATABASE_TABLE_PREFIX=wallabag_
SYMFONY__ENV__MAILER_DSN=smtp://mymailserver
SYMFONY__ENV__FROM_EMAIL=wallabag@mydomain.local
SYMFONY__ENV__DOMAIN_NAME=https://app-test.mydomain.local
SYMFONY__ENV__SERVER_NAME=Wallabag test instance
POSTGRES_USER=postgres
POSTGRES_PASSWORD=xxx
POPULATE_DATABASE=True

Logs when database already exists:

Starting wallabag ...
Waiting for database ...
WARN: Postgres database is already configured. Remove the environment variable with root password.
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/compiler is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/consistency is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/event is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/exception is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/file is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/iterator is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/math is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/protocol is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/regex is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/ruler is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/stream is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/ustring is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/visitor is abandoned, you should avoid using it. No replacement was suggested.
Package hoa/zformat is abandoned, you should avoid using it. No replacement was suggested.
Package lexik/form-filter-bundle is abandoned, you should avoid using it. Use spiriitlabs/form-filter-bundle instead.
Package php-http/guzzle5-adapter is abandoned, you should avoid using it. Use php-http/guzzle7-adapter instead.
Package php-http/message-factory is abandoned, you should avoid using it. Use psr/http-factory instead.
Package scheb/2fa-qr-code is abandoned, you should avoid using it. No replacement was suggested.
Package sensio/framework-extra-bundle is abandoned, you should avoid using it. Use Symfony instead.
Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead.
Package true/punycode is abandoned, you should avoid using it. No replacement was suggested.
Package wallabag/php-mobi is abandoned, you should avoid using it. No replacement was suggested.
Package php-cs-fixer/diff is abandoned, you should avoid using it. No replacement was suggested.
Package symfony/web-server-bundle is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Class SimpleHtmlDom\simple_html_dom_node located in ./vendor/mgargano/simplehtmldom/src/simple_html_dom.php does not comply with psr-0 autoloading standard. Skipping.
Class SimpleHtmlDom\simple_html_dom located in ./vendor/mgargano/simplehtmldom/src/simple_html_dom.php does not comply with psr-0 autoloading standard. Skipping.
100 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> bin/console cache:clear --no-warmup
 // Clearing the cache for the prod environment with debug                      
 // false                                                                       
 [OK] Cache for the "prod" environment (debug=false) was successfully cleared.  
> bin/console assets:install web --symlink --relative
 Trying to install assets as relative symbolic links.
 --- ------------------------ ------------------ 
      Bundle                   Method / Error    
 --- ------------------------ ------------------ 
  ✔   NelmioApiDocBundle       relative symlink  
  ✔   CraueConfigBundle        relative symlink  
  ✔   BabDevPagerfantaBundle   relative symlink  
  ✔   FOSJsRoutingBundle       relative symlink  
 --- ------------------------ ------------------ 
 [OK] All assets were successfully installed.                                   
wallabag is ready!

Logs when database doesn't exists:

Starting wallabag ...
Waiting for database ...
Configuring the Postgres database ...
ERROR:  syntax error at or near "-"
LINE 1: CREATE DATABASE wallabag;

Thing is, I have no tables in my database, despite wallbag user is owner of the database and I think "of course", this will result in the 500 error. api is available tough with the mentionned URL.

One thing: if I create the database after the initial start without, the logs will be exactly the same as above, so the DB is found. Remove root credentials doesn't help either.

Any clue where to start? Thx in advance! 😉

Activity

  1. tan-yong-sheng commented on Apr 14, 2024

    @tan-yong-sheng

    I faced similar problem as well...
    and the installation docs looks weird to me: https://doc.wallabag.org/en/developer/docker

    For example, the step 2: Edit app/config/parameters.yml to replace database_* properties with commented ones (with values prefixed by env.). I checked and found I can't follow this step as there isn't any app/config/ folder existed.

    I am working to self-host it with Docker and traefik reverse proxy.

  2. martin-juul commented on May 4, 2024

    @martin-juul

    If you ran into the same problem as me, you would see this as the first log entry:

    WARN: Postgres database is already configured. Remove the environment variable with root password.

    The issue is that the entrypoint only runs the database setup if it's the creator of the database. See

    if [ "$DATABASE_EXISTS" != "1" ]; then

    However it doesn't grant the necessary permissions, and the setup code is a bit ... Well it could be better.

    How to get wallabag working with postgres

    There's a flag POPULATE_DATABASE which we can disable, then we can go back to giving wallabag a role which has privileges on a database.

    So my environment looks like this now:

          - POPULATE_DATABASE=false
          - SYMFONY__ENV__DATABASE_DRIVER=pdo_pgsql
          - SYMFONY__ENV__DATABASE_HOST=postgresql
          - SYMFONY__ENV__DATABASE_PORT=5432
          - SYMFONY__ENV__DATABASE_NAME=wallabag
          - SYMFONY__ENV__DATABASE_USER=wallabag
          - SYMFONY__ENV__DATABASE_PASSWORD=wallabag
    

    Then we start the container and wait for it to finish starting up, afterwards jump into a shell:

    docker exec -it wallabag sh

    Now we can run the install script ourselves

    php bin/console wallabag:install --env=prod -n

    Since we ran that as root, we have to fix the permissions (otherwise you will get some nasty session errors)

    chown -R nobody:nobody /var/www/wallabag

    Then you should be able to hit your containers url or whatever you mapped it to and see

    image


    My database wouldn't close the hanging connections, to force drop it the syntax is as follows:

    DROP DATABASE dbName WITH (FORCE)
  3. ipedrazas commented on Sep 5, 2024

    @ipedrazas

    If you're using a version of Postgres after 15, you will get the following error:

    ERROR: permission denied for schema public.

    To fix it, you need to grant permissions to the public schema, connect to your wallabag database with your root user and execute the following command:

    GRANT ALL ON SCHEMA public TO wallabag

  4. hnykda commented on Oct 30, 2024

    @hnykda

    Thanks for the pointers. I don't know why, but for me this doesn't really work. I believe the docker example assumes creation of that user etc. before, implicitly. I kinda expected it will just work.

    I am running inside a VM and connect to the docker-compose local postgres instance, therefore I don't mind the thing running under a super user, so do it like this:

    services:
      wallabag:
        image: wallabag/wallabag
        restart: unless-stopped
        environment:
          - SYMFONY__ENV__DATABASE_DRIVER=pdo_pgsql
          - SYMFONY__ENV__DATABASE_HOST=db
          - SYMFONY__ENV__DATABASE_PORT=5432
          - SYMFONY__ENV__DATABASE_NAME=postgres
          - SYMFONY__ENV__DATABASE_USER=postgres
          - SYMFONY__ENV__DATABASE_PASSWORD=postgres
          - 'SYMFONY__ENV__DATABASE_TABLE_PREFIX="wallabag_"'
          - 'SYMFONY__ENV__MAILER_DSN=smtp://127.0.0.1'
          - SYMFONY__ENV__FROM_EMAIL=wallabag@example.com
          - 'SYMFONY__ENV__DOMAIN_NAME=https://...'
          - 'SYMFONY__ENV__SERVER_NAME="Wallabag"'
          - SYMFONY__ENV__REDIS_HOST=redis
        expose:
          - 80
        volumes:
          - './data/images:/var/www/wallabag/web/assets/images'
        healthcheck:
          test:
            - CMD
            - wget
            - '--no-verbose'
            - '--tries=1'
            - '--spider'
            - 'http://localhost/api/info'
          interval: 1m
          timeout: 3s
        depends_on:
          - db
          - redis
      db:
        image: 'postgres:17-alpine'
        volumes:
          - './data/postgresql/pg_data:/var/lib/postgresql/data'
        environment:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        healthcheck:
          test:
            - CMD-SHELL
            - 'pg_isready -U postgres'
          interval: 5s
          timeout: 5s
          retries: 5
      redis:
        image: 'redis:alpine'
        restart: unless-stopped
        healthcheck:
          test:
            - CMD
            - redis-cli
            - ping
          interval: 20s
          timeout: 3s
    

    however, this doesn't work out of the box either, initial migration doesn't spin up - tables are not being created, and after a fresh start, I see things like this int he DB:

    2024-10-30T09:09:32.302923300Z 2024-10-30 09:09:32.302 UTC [151] ERROR:  relation "wallabag_internal_setting" does not exist at character 77
    2024-10-30T09:09:32.302947185Z 2024-10-30 09:09:32.302 UTC [151] STATEMENT:  SELECT t0.value AS value_1, t0.name AS name_2, t0.section AS section_3 FROM "wallabag_internal_setting" t0 WHERE t0.name = $1 LIMIT 1
    

    I had to exec the initialization inside wallabag container via docker exec -ti {your-wallabag-container-id} php bin/console wallabag:install --env=prod -n and voila, it works.

    I was able to also get it working via creating the wallabag user, database, granting permissions etc., but it was more hassle for me.

  5. erikvanoosten commented on May 29, 2025

    @erikvanoosten

    Using Postgresql 17, I also had to set the database owner:

    docker compose exec -ti db psql --user=postgres
    GRANT ALL ON SCHEMA public TO wallabag;
    ALTER DATABASE wallabag OWNER TO wallabag;

    Then I could run the migration with:

    docker compose exec --no-TTY wallabag /var/www/wallabag/bin/console doctrine:migrations:migrate --env=prod --no-interaction
  6. maxant commented on Jun 9, 2025

    @maxant

    I had a similar problem (although with MySql)
    Steps to resolve:

    • STEP 01: run docker with migrate tagged on the end (as shown in a comment above), in order to make sure the database tables are created.
    • STEP 02: run docker with sh tagged on the end (as shown in a comment above), and then run these scripts:
        php bin/console wallabag:install --env=prod -n
        chown -R nobody:nobody /var/www/wallabag
    
    • STEP 03: start it with registration enabled, so that we can create a user by registering one:
            -e SYMFONY__ENV__FOSUSER_REGISTRATION=True
            -e SYMFONY__ENV__FOSUSER_CONFIRMATION=False
    
    • STEP 04: once registered, restart docker with registration disabled if you want that
  7. robertgosz commented on Dec 14, 2025

    @robertgosz

    I have similar issue with mariadb. Fresh install. The provided docker compose example does not work out of the box. Db is complaining about file permissions. When given full access it starts, but then wallabag cannot connect (db refusing connections). After setting up db to create service account the wallabag container starts and is able to connect to db, but returns exactly the same error 500 as seen above.

  8. j0k3r commented on Oct 28, 2026

    @j0k3r
    Member

    Are we agree that the issue is about: initialize existing empty databases automatically? (like #121 for MySQL)

    When POPULATE_DATABASE=True, the entrypoint skips wallabag:install if the PostgreSQL database already exists even when it contains no application tables.

    The entrypoint should distinguish an existing database from an initialized wallabag installation and initialize an existing empty database automatically.

    Manual initialization is now documented, but remains a workaround.

  9. changed the title [-]Error 500 by fresh installation (Docker/Postgres)[/-] [+]PostgreSQL: initialize existing empty databases automatically[/+] on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions