mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-12-10 17:23:04 +03:00
[vaultwarden::db::sqlite_migrations][ERROR] Error creating database directory when using Postgres
#1313
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cschmatzler on GitHub.
Subject of the issue
Using a
DATABASE_URLenv variable starting withpostgres://, Vaultwarden still tries to run SQLite migrations and fails at https://github.com/dani-garcia/vaultwarden/blob/main/src/db/mod.rs#L291. Data directory is writeable since the keys are created successfully.Deployment environment
Debian Bullseye with Docker
version 20.10.8, build 3967b7dvaultwarden version: Docker image
vaultwarden/server:1.22.2Install method:
MySQL/MariaDB or PostgreSQL version:
postgres:13.3Other relevant details:
env-vaultwarden:
Running it under root uid works.
Steps to reproduce
Create the env file, a postgres database, data dir with correct owner and run the above command to launch the docker image.
Expected behaviour
SQLite migrations should be skipped and container should launch.
Actual behaviour
Container stops at SQLite migrations failing
Troubleshooting data
@cschmatzler commented on GitHub:
Found the issue.
DATABASE_URLmay not be quoted, neither in single nor in double quotes. This is in contrast to the wiki entry here, which givesThe server should probably allow quoted environment variables? When passing a quoted variable as
-e DATABASE_URL='...', Docker automatically unquotes it, but as--env-file, it stays quoted.@jjlin commented on GitHub:
It's generally not the application's job to do more unquoting on environment variables, as the user might want an env var to have a quoted value. Unfortunately, there is not really any standard for env file syntax, so different tools can handle it differently.
I've updated https://github.com/dani-garcia/vaultwarden/wiki/Configuration-overview#loading-environment-variables-from-a-file to mention this pitfall with
--env-file. That wiki page covers other ways to load env files as well.@cschmatzler commented on GitHub:
Let's minimize a little:
results in the same.
Omitting the
userflag and running it as root does start the container and logsRunning migrationa bunch, and brings up the web vault... but does not write anything to the Postgres database and loses all data after a container restart, so it's writing somewhere in the ephemeral file system.Which is very interesting, because it also logs
and if it was defaulting to sqlite...
https://github.com/dani-garcia/vaultwarden/blob/main/src/config.rs#L302
https://github.com/dani-garcia/vaultwarden/blob/main/src/config.rs#L314
are both using
c.data_folder, which has write permissions even for my1500:1500user, because thersa_keypath can be created and does persist between container restarts.@BlackDex commented on GitHub:
I'm having no issues using postgresql.
Are you sure the correct env is loaded? Since sqlite is default, i think those env's you try to load arn't working.
Try to add LOG_LEVEL=debug or trace and see if the output changes.
@cschmatzler commented on GitHub:
Running
Passing the
DATABASE_URLenvironment variable topsqlconnects to the database successfully.