Move from SQLite to Postgres
Naelox keeps its data in one SQLite file in the data folder. That is fine for most homes. Postgres makes sense when the server is busy with many profiles and workers, or when you already run Postgres and want backups in one place.
Before you start
Section titled “Before you start”- An empty Postgres database and a user that owns it.
- The connection URL, for example
postgres://naelox:[email protected]:5432/naelox?sslmode=disable. - A moment when nobody is watching. Database calls pause during the copy; playback that is already running continues.
- Open Settings → Server as an admin.
- Choose Move to Postgres… and paste the URL.
- Confirm.
Naelox checks that the target is empty, runs its migrations there, pauses database calls while it copies every table in one transaction, saves the URL to database.json in the data folder, and switches the running server over. The SQLite file is left in place as a backup.
Afterwards
Section titled “Afterwards”database.jsonis what the server reads on later starts. Keep it with the rest of the data folder.- The move is one way from the web app. To go back to SQLite, delete
database.jsonand restore the SQLite file from your backup. DATABASE_URLin the environment always wins overdatabase.json. If it is set, the Move to Postgres… option is not shown.
Starting on Postgres from day one
Section titled “Starting on Postgres from day one”A new server can start on Postgres with nothing to move. There are two ways, and both need an empty database and a user that owns it.
In setup. Open Advanced → Data, choose A Postgres server, paste the URL and press Test. Setup saves the URL to database.json when you finish.
With DATABASE_URL. Set the variable before the first start:
Setup still runs, so you create the owner and add libraries as usual. Its data step shows the database server and “Fixed by DATABASE_URL” with nothing to choose, and no database.json is written. If the database can’t be reached, Naelox stops with the reason and does not fall back to SQLite. If the database already holds a Naelox server’s data, setup is skipped and the server starts on it.
Where Allspark keeps its data
Section titled “Where Allspark keeps its data”The Allspark built into Naelox follows the server’s database:
- With Naelox on SQLite, it keeps its own SQLite file in
allspark/in the data folder. - With a server that starts on Postgres, it uses the same database, in a schema named
allsparkthat it creates. The database user needs permission to create a schema. - When you move a server to Postgres from Settings, Allspark’s queue and history move with it into that schema, and Naelox restarts once so Allspark starts on Postgres. Playback pauses for a few seconds. Steps that workers on other machines are running carry on; a step the server’s own worker was running is picked up again a few minutes later, as after any restart.
- If Allspark’s part of the move fails, Naelox’s move still stands and Allspark carries on with its local file. Settings → Server → Database says so and shows Move Allspark too… to try again. The same button appears on a server that moved to Postgres before version 0.1.61, or that started on
DATABASE_URLwith an older Allspark file in its data folder. - Allspark’s old file,
allspark/allspark.db, stays in the data folder as a backup. Nothing reads it afterwards.
An Allspark you run yourself is not affected; it has its own database setting.
Where the data folder can live
Section titled “Where the data folder can live”Naelox refuses to set up a new server whose data folder is on a network share (SMB, NFS, AFP, WebDAV, SSHFS) or on a FAT or exFAT drive, because SQLite can lose data there. Setup shows the reason and the folder. Put the data folder on a local disk formatted for your system, and keep the media itself wherever you like. A server that was already set up on such a volume keeps starting and logs a warning each time. This applies with Postgres too, because the built-in Allspark queue and the caches still live in the data folder.