Migrate from PocketBase¶
burrow migrate-from-pocketbase moves an existing PocketBase app from its SQLite pb_data/data.db to
burrowDB on PostgreSQL. It only reads the SQLite file. Your PocketBase install stays as it is, so you
can go back.
The plan: check the data the day before, stop writes, snapshot data.db, copy it, check it, point the
app at burrowDB. Downtime is the time the copy and checks take.
What it moves¶
- Every collection, with its fields, API rules, options and indexes. View collections are recreated on PostgreSQL.
- Every record, including auth records with their password hashes, so users keep their passwords.
- Settings and the applied-migrations list.
- Files, with the
filesstep, or nothing to do when PocketBase already stores files on S3.
It does not move the request logs (auxiliary.db); burrowDB starts with an empty logs database.
If the PocketBase app encrypted its settings (--encryptionEnv), give burrowDB the same key in
BURROW_ENCRYPTION_KEY. Plain settings work with or without a key.
Steps¶
| Step | What |
|---|---|
preflight |
Scan the SQLite file for values PostgreSQL refuses (NUL bytes, invalid UTF-8) |
schema |
Create the collections on PostgreSQL, indexes deferred |
copy |
Copy every table in batches, converting types; re-run it to continue after an interruption |
indexes |
Create the deferred indexes in parallel, then ANALYZE |
verify |
Row counts and checksums of the converted SQLite rows against PostgreSQL, and the indexes |
all |
schema, copy, indexes and verify in order (-verify-tier full for every row) |
files |
Copy pb_data/storage to the burrowDB data directory |
apidiff |
Ask the old and the new server for the same records and compare the answers |
export |
The way back: PostgreSQL to a new SQLite file (same as burrow export-to-sqlite) |
verify-sqlite |
Compare two SQLite files with each other and with PostgreSQL |
Flags use a single dash: -sqlite, -pg-url. -pg-url defaults to BURROW_POSTGRES_DIRECT_URL, then
BURROW_POSTGRES_URL. Use the direct PostgreSQL URL, not pgbouncer, in URL form
(postgres://USER@HOST:5432/postgres?sslmode=require); keyword DSNs (host=... dbname=...) are refused.
Keep the password out of the command line (where ps shows it): put it in PGPASSWORD, or set the URL in
BURROW_POSTGRES_DIRECT_URL instead of passing -pg-url. Reports written with -report are mode 0600.
The steps that read the SQLite file refuse it while its data.db-wal is not empty, because something may
still be writing to it and the copy would not be one consistent snapshot. Stop PocketBase first (a clean
stop empties the log). -allow-live skips the check for a dry run on a live file. -data-db defaults to
BURROW_DATA_DB or burrow_data, -aux-db to BURROW_AUX_DB or burrow_aux.
The target data database must be empty or not exist yet. copy refuses to write into a table that
already holds rows, unless it is continuing its own interrupted run. Do not start burrowDB against the
target database before the migration finishes.
The day before¶
Copy the live data.db somewhere (a plain copy is fine for a dry run) and check it:
Then run the whole migration once into a scratch database, to learn how long it takes and to see any conversion problems before the real window:
export BURROW_POSTGRES_DIRECT_URL='postgres://burrow@db.example.internal:5432/postgres?sslmode=require'
export PGPASSWORD='...'
burrow migrate-from-pocketbase all -sqlite /tmp/dryrun/data.db -data-db burrow_dryrun -aux-db burrow_dryrun_aux -report dryrun.json
Drop burrow_dryrun and burrow_dryrun_aux afterwards.
Values that do not convert¶
By default (-strict=true) the copy stops on any value it cannot convert, and tells you the table and
column. Fix the data in PocketBase, or decide per case:
| Flag | Use |
|---|---|
-empty-autodate fail\|updated\|epoch |
An empty created or updated. updated uses the row's updated; then also set -fallback-time (RFC 3339) for rows where that is empty too |
-json-nul replace\|fail |
A NUL inside a JSON value, which jsonb cannot store. replace writes U+FFFD and logs the record ids |
-allow-conversion table.column[:reason] |
Accept a conversion to a default or NULL that you have looked at (repeatable) |
The window¶
- Stop writes. Stop PocketBase, or put the app in maintenance mode.
- Snapshot. With PocketBase stopped, copy
data.dband anydata.db-walanddata.db-shmnext to it. If the copieddata.db-walis not empty, fold it into the file:
mkdir -p /migrate/snap && cp pb_data/data.db* /migrate/snap/
sqlite3 /migrate/snap/data.db "PRAGMA wal_checkpoint(TRUNCATE)" # only needed when data.db-wal is not empty
- Migrate.
For large databases, tune -parallel (8), -batch (10000), -split-rows (200000),
-index-workers (4) and -maintenance-mem (1GB). If the copy stops, fix the cause and rerun
copy (it continues from its saved state), then indexes and verify.
verify runs the fast "window" tier by default: counts on everything, full checksums on tables up
to -full-max-rows (200000), and a -sample-pct (10) key sample on larger ones, without the orphan
check. all uses the same tier unless you pass -verify-tier full. Run verify -tier full after
go-live for a complete check, which also compares relation orphans.
What verify proves: it converts each SQLite row the same way copy does and compares checksums
with PostgreSQL, so it proves the load is complete and intact. A mistake in the conversion itself
(a date read wrongly, say) would be applied to both sides and not show up there. That is what
apidiff (step 6) is for: it compares what the old and the new server actually return. It also
checks that every index exists with the same uniqueness and the same partial-index predicate
literals as in the source.
- Files. If PocketBase keeps files on local disk:
With more than one burrowDB replica, files must be on S3. Upload pb_data/storage to your bucket
with your usual tool and turn on S3 in the settings. If PocketBase already used S3, point burrowDB at
the same bucket; there is nothing to copy.
-
Start burrowDB against the migrated database and wait for
/readyz. -
Compare the APIs. Start the old PocketBase again on the snapshot (read-only use) and compare:
BURROW_PASSWORD='...' burrow migrate-from-pocketbase apidiff -sqlite /migrate/snap/data.db \
-a http://127.0.0.1:8091 -b https://api.example.com -user admin@example.com
It fetches -sample (20) records by id and -pages (3) random list pages per collection from both
and reports any difference. If the copy ran with -empty-autodate updated, pass the same flag here so
the created values filled from updated are counted as expected.
- Cut over. Point the app and DNS at burrowDB. The PocketBase SDKs need no change other than the base URL.
The way back¶
If you need to return to PocketBase, stop writes to burrowDB first (scale the API to zero), then export
it to a new SQLite file with the original schema. PostgreSQL is read in one snapshot, so the file is
consistent, but rows written after the export started are not in it. The file is written as
data.db.part and renamed only when the export succeeded, so a failed run leaves nothing to clean up.
burrow export-to-sqlite -template /migrate/snap/data.db -out /migrate/back/data.db
burrow migrate-from-pocketbase verify-sqlite -sqlite /migrate/snap/data.db -other /migrate/back/data.db
-template is the original data.db, or one made by starting the target PocketBase version on an
empty pb_data. The export refuses if PostgreSQL holds data the template has no table or column for
(for example a collection created after the migration). Put the exported file in pb_data/ and start
stock PocketBase.
What we tested¶
The test test/e2e/migrate-from-pocketbase.sh builds a PocketBase app with auth users, a relation,
a view, JSON and select fields, files and Unicode text, migrates it, and goes back. Its last run:
verify-sqliteon the round trip: 0 mismatches over 78 rows.apidiff: 127 responses compared, 0 unexpected differences.- Users log in with their old passwords. The view, file downloads and JSON-path filters work on burrowDB.
- Stock PocketBase serves the file exported back to SQLite.
That is a small dataset. Do a dry run with your own data before the real window.