diff --git a/src/pages/selfhosted/maintenance/scaling/migrate-sqlite-to-postgresql.mdx b/src/pages/selfhosted/maintenance/scaling/migrate-sqlite-to-postgresql.mdx index 969995bc..39a20feb 100644 --- a/src/pages/selfhosted/maintenance/scaling/migrate-sqlite-to-postgresql.mdx +++ b/src/pages/selfhosted/maintenance/scaling/migrate-sqlite-to-postgresql.mdx @@ -121,4 +121,118 @@ docker compose logs netbird-server | grep store You should see: ``` using Postgres store engine +``` + +## Migrate Auth Store + +The embedded identity provider (Dex) uses a separate SQLite database (`idp.db`) to store authentication data such as users, passwords, connectors, sessions, and tokens. You can optionally migrate this to PostgreSQL as well. + +### Create the Auth Database + +```bash +docker exec postgres-server psql -U postgres -c "CREATE DATABASE netbird_auth;" +``` + +### Create the Auth Migration File + +Create a file called `auth-sqlite.load` with the following content: + +``` +LOAD DATABASE + FROM sqlite:///root/combined/backup/idp.db + INTO postgresql://postgres:password@localhost:5432/netbird_auth + +WITH include drop, create tables, create indexes, reset sequences + +CAST + column client.public to boolean, + column auth_request.force_approval_prompt to boolean, + column auth_request.logged_in to boolean, + column auth_request.claims_email_verified to boolean, + column auth_code.claims_email_verified to boolean, + column refresh_token.claims_email_verified to boolean +; +``` + + +Update the SQLite path and PostgreSQL connection string to match your environment. + + +### Run the Auth Migration + +```bash +pgloader auth-sqlite.load +``` + +### Update config.yaml + +Add the `authStore` section to your `config.yaml`: + +```yaml +server: + # ... existing settings ... + + authStore: + engine: "postgres" + dsn: "host=postgres-server port=5432 user=postgres password=password dbname=netbird_auth sslmode=disable" +``` + +### Restart and Verify + +```bash +docker compose up -d +``` + +## Migrate Activity Store + +The activity events store uses a separate SQLite database (`events.db`) to record user and system activity. You can optionally migrate this to PostgreSQL as well. + +### Create the Activity Database + +```bash +docker exec postgres-server psql -U postgres -c "CREATE DATABASE netbird_events;" +``` + +### Create the Activity Migration File + +Create a file called `activity-sqlite.load` with the following content: + +``` +LOAD DATABASE + FROM sqlite:///root/combined/backup/events.db + INTO postgresql://postgres:password@localhost:5432/netbird_events + +WITH include drop, create tables, create indexes, reset sequences +; +``` + + +No boolean CAST rules are needed for the activity store — all columns use standard integer and text types. + +Update the SQLite path and PostgreSQL connection string to match your environment. + + +### Run the Activity Migration + +```bash +pgloader activity-sqlite.load +``` + +### Update config.yaml + +Add the `activityStore` section to your `config.yaml`: + +```yaml +server: + # ... existing settings ... + + activityStore: + engine: "postgres" + dsn: "host=postgres-server port=5432 user=postgres password=password dbname=netbird_events sslmode=disable" +``` + +### Restart and Verify + +```bash +docker compose up -d ``` \ No newline at end of file