Deploying Entity Framework
Entity Framework is a largely untested way to provide database services for Bitwarden. If you decide to use it, please expect inconsistencies and bugs. If you encounter any, please create an issue at https://github.com/bitwarden/server/issues with as much reproduction information as possible.
We don’t yet have a way to automatically run database migrations. You need to do it yourself every time you update your Bitwarden instance. It’s best not to run a given migration multiple times. Again, this is not automated, so you’ll need to keep track yourself.
No attempt is made to migrate data from an existing MSSql database to a new database provider. You
can swap back to MSSql at any time by changing globalSettings__databaseProvider="postgres" to
globalSettings__databaseProvider="sqlServer"
DO NOT in a production instance with data you care about!
These instructions have only been tested on Linux.
Instructions
Install a Bitwarden self-hosted instance as nomal: https://bitwarden.com/help/install-on-premise-linux/
Update
bwdata/docker/docker-compose.override.yml- Note: You should choose a better PgAdmin4 password
#
# Useful references:
# https://docs.docker.com/compose/compose-file/
# https://docs.docker.com/compose/reference/overview/#use--f-to-specify-name-and-path-of-one-or-more-compose-files
# https://docs.docker.com/compose/reference/envvars/
#
#########################################################################
# WARNING: This file is generated. Do not make changes to this file. #
# They will be overwritten on update. If you want to make additions to #
# this file, you can create a `docker-compose.override.yml` file in the #
# same directory and it will be merged into this file at runtime. You #
# can also manage various settings used in this file from the #
# ./bwdata/config.yml file for your installation. #
#########################################################################
version: '3'
services:
mssql:
web:
attachments:
api:
identity:
sso:
admin:
icons:
notifications:
events:
nginx:
postgresql:
image: postgres:13.2
container_name: bitwarden-postgres
restart: always
stop_grace_period: 60s
networks:
- default
- public
ports:
- '5432:5432'
volumes:
- ../postgres/data:/var/lib/postgresql/data
- ../postgres/config:/etc/postgresql
- ../postgres/log:/var/log/postgresql
env_file:
- postgresql.env
- ../env/uid.env
- ../env/postgresql.override.env
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: postgres@bitwarden.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "8889:80"
networks:
- default
- publicCreate
bwdata/docker/postgresql.envPOSTGRES_DB=bw_vault
POSTGRES_USER=postgresCreate
bwdata/env/postgresql.override.env- Note: you should choose a better password
POSTGRES_PASSWORD=exampleUpdate
bwdata/env/global.override.envby adding the following (be sure to update the password to match what you set inpostgresql.override.env):globalSettings__databaseProvider="postgres"
globalSettings__postgreSql__connectionString="Host=bitwarden-postgres;Port=5432;Username=postgres;Password=example;Database=bw_vault"Restart your Bitwarden environment to apply these config changes:
bitwarden.sh restartRun database migrations. Since we’re just setting up, we need to run all migrations.
Clone the server repository
git clone https://github.com/bitwarden/servercdinto the appropriate Scripts directory. For Postgres, this isserver/util/PostgresMigrations/ScriptsCopy each migration to the postgres docker container and run it. The following script will do this for every migration in the current directory. Note: this script needs to be run from the current directory, otherwise the
$fin thedocker execcommand will not point to the script file on the container.for f in `ls -v ./*.psql`; do docker cp $f bitwarden-postgres:/var/lib/postgresql/; docker exec -u 1001 bitwarden-postgres psql bw_vault postgres -f /var/lib/postgresql/$f; done;
Run
bitwarden.sh restartjust to make sure everything is up to date
Your self-hosted instance should now be using postgres!