Repository navigation
Using PostgreSQL
SQLite is the default and needs nothing. To keep the application data in PostgreSQL instead, set ConnectionStrings__PostgresConnection to an Npgsql connection string:
environment:
ConnectionStrings__PostgresConnection: Host=db;Port=5432;Database=trackarr;Username=trackarr;Password=change-meWhen it is set (not empty), trackarr uses PostgreSQL; otherwise it uses SQLite. Hangfire and the plugins stay on disk under /data either way, so keep the data volume. docker/docker-compose.postgres.yml is a complete example with a postgres:17-alpine container. At startup the log names the engine in use (Database: PostgreSQL 17.x), and Settings > About shows PostgreSQL. The connection string and its password are never logged.
trackarr never creates the PostgreSQL database. Create an empty database, owned by (or writable for) the user in the connection string, before the first start. trackarr then creates its tables in it, and applies its migrations on later upgrades.
- With the official
postgresimage,POSTGRES_DBcreates the database the first time the container starts on an empty volume, as in the example compose file. - With a server of your own, create it with
psql, for exampleCREATE DATABASE trackarr OWNER trackarr;.
trackarr stops at startup, with the reason in the log, when it cannot use PostgreSQL:
-
The database does not exist. Nothing is created on the server, and startup stops with:
PostgreSQL database 'trackarr' does not exist. trackarr does not create it: create it, or remove ConnectionStrings__PostgresConnection to use SQLite. -
The server cannot be reached (a network or socket error, for example while the PostgreSQL container is still starting). trackarr logs
Failed to connect to PostgreSQL at <host>:<port>, N retries remainingand tries again, 3 times, 5 seconds apart. During those tries any PostgreSQL error is retried, since a server that is still starting refuses connections for a moment. If the last try also fails, startup stops withCould not connect to PostgreSQL at <host>:<port> after 3 retries. -
Any other PostgreSQL error on the first try, such as a wrong password or a missing permission, stops startup at once with the PostgreSQL error.
trackarr does not fall back to SQLite when PostgreSQL fails: fix the connection, or remove the setting on purpose.
trackarr never copies data between the two databases, in either direction. Each database keeps its own data, and the one you are not using is left as it is.
Warning
Migrating an existing SQLite database to PostgreSQL is not supported. When you set ConnectionStrings__PostgresConnection, trackarr starts empty on PostgreSQL. Your trackarr.db is not read, changed or deleted.
The steps below copy a SQLite database into PostgreSQL with pgloader. They are unofficial: they worked for trackarr v0.5.0, they may not work for your database without changes, and we cannot help you with them. Keep your trackarr.db: if anything goes wrong, remove the setting and trackarr is back on it.
The commands assume the example compose files, started from the docker folder (Compose project docker, so the data volume is docker_trackarr_data and the network docker_default), and the default trackarr database, user and password. Change those names to match your setup.
-
Stop trackarr, which is still on SQLite, and copy
trackarr.dbinto an empty working folder. Once trackarr has stopped there is notrackarr.db-walfile, andtrackarr.dbholds everything.docker compose stop trackarr mkdir ~/trackarr-pgloader docker run --rm -v docker_trackarr_data:/data:ro -v ~/trackarr-pgloader:/out alpine cp /data/trackarr.db /out/
-
Switch to PostgreSQL (see Create the database yourself) and start trackarr once, so it creates its tables in the empty database. Check that the log shows
Database: PostgreSQL, add nothing in the UI, then stop trackarr and leave PostgreSQL running.docker compose -f docker-compose.postgres.yml up -d docker compose -f docker-compose.postgres.yml logs trackarr | grep "Database:" docker compose -f docker-compose.postgres.yml stop trackarr
-
Delete the two rows trackarr wrote on that first start, so the rows from SQLite take their place. Do not delete anything else, do not touch
__EFMigrationsHistory, and do not drop any table.docker exec -i trackarr-postgres psql -U trackarr -d trackarr <<'SQL' DELETE FROM "ApplicationSettings"; DELETE FROM "WhatsNewState"; SQL
-
Save this as
~/trackarr-pgloader/trackarr.load:LOAD DATABASE FROM sqlite:///work/trackarr.db INTO postgresql://trackarr@trackarr-postgres/trackarr WITH data only, quote identifiers SET timezone TO 'UTC' EXCLUDING TABLE NAMES LIKE '__EFMigrations%';-
data onlyloads the rows into the tables trackarr created, andquote identifierskeeps the table and column names' case. -
SET timezone TO 'UTC': SQLite stores the dates in UTC with no offset, and PostgreSQL reads such a date in the session time zone. The example compose file runs PostgreSQL inAPP_TIMEZONE, so without this line every date would move by your UTC offset. - The excluded tables are EF Core's migration history and lock. The PostgreSQL migrations have their own IDs, so the history PostgreSQL already has must stay as it is.
No cast is needed: SQLite stores the IDs, dates and decimals as text, and PostgreSQL converts them to
uuid,timestamp with time zoneandnumericon load. -
-
Run pgloader. The password comes from
PGPASSWORD, so it is not in the load file.docker run --rm --network docker_default -e PGPASSWORD=trackarr \ -v ~/trackarr-pgloader:/work ghcr.io/dimitri/pgloader:latest pgloader /work/trackarr.loadThe summary lists
ApplicationSettings,Integrations,IntegrationSnapshotsandWhatsNewStatewith 0 errors, and ends withTotal import time ✓. TheWARNING ... is casted to type ... which is not the same as ...lines are expected. AnyERRORline means the copy is not complete: drop and create the database again, and start over from step 2. -
Start trackarr and check your integrations and their history.
docker compose -f docker-compose.postgres.yml up -d
PostgreSQL keeps dates to the microsecond, while SQLite kept them to a tenth of one, so the copied dates are rounded to the nearest microsecond. Nothing else changes. The trackarr.db in the data volume is left as it is.
Removing ConnectionStrings__PostgresConnection does not bring your PostgreSQL data back to SQLite. trackarr opens the <Data__Directory>/trackarr.db that is on disk, as it is: the data from before you switched to PostgreSQL, or a new empty database if there is no file. Nothing is copied from PostgreSQL, and the PostgreSQL database is not changed: setting the connection string again brings back what it holds.