Skip to content

Using PostgreSQL

Leandro Battochio edited this page Nov 8, 2026 · 1 revision

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-me

When 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.

Create the database yourself

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 postgres image, POSTGRES_DB creates 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 example CREATE DATABASE trackarr OWNER trackarr;.

Startup failures

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 remaining and 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 with Could 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.

Moving between SQLite and PostgreSQL

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.

From SQLite to PostgreSQL

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.

  1. Stop trackarr, which is still on SQLite, and copy trackarr.db into an empty working folder. Once trackarr has stopped there is no trackarr.db-wal file, and trackarr.db holds 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/
  2. 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
  3. 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
  4. 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 only loads the rows into the tables trackarr created, and quote identifiers keeps 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 in APP_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 zone and numeric on load.

  5. 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.load

    The summary lists ApplicationSettings, Integrations, IntegrationSnapshots and WhatsNewState with 0 errors, and ends with Total import time ✓. The WARNING ... is casted to type ... which is not the same as ... lines are expected. Any ERROR line means the copy is not complete: drop and create the database again, and start over from step 2.

  6. 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.

From PostgreSQL back to SQLite

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.

Clone this wiki locally