Can't create Sqlite database in mounted volume

Recently I’ve been trying to scale my app to two regions, but am having trouble with writing data to the volume of the new region.

  1. I added a volume with matching name to the lax region
  2. Ran fly scale count 2
  3. Saw in flyctl logs that my app is unable to create/read a Sqlite database on the volume upon launching.

The weird bit is it works absolutely fine in the original region I deployed to (ams), and has done so for the last four months. My app uses the heroku/buildpacks:20 builder, could anything have changed under my feet?

Unfortunately better-sqlite3 doesn’t give me much more information than SqliteError: unable to open database file.

Would you mind sharing the script that does the DB file init?

Only possible solution that I can think of right now is that the second volume isn’t automatically replicated, so you might have to create the DB file again there (if you haven’t done so already).

@sudhir.j There’s a few layers of abstraction, but it boils down to making an instance of better-sqlite3’s Database class:

let db = new Database(path);

This will create a new file if none is found at the given path (which is /data/mydb.sql).

For whatever reason, this operation fails on a newly deployed instance in another region, although it works every time in ams.

Looks like you’re doing everything right, let me get this in front of the team. Which app ID is this?

fragrant-leaf-492. Thanks!

1 Like

This is probably a permissions error. If you ssh to your instance and run ls -la /data you can see who owns it. If that path, or any file within that path, is owned by root, that’s a problem. You can likely fix it by running chown -R heroku:heroku /data.

We try and set ownership when we first mount a volume but this is a relatively complex problem and we haven’t figured out the perfect UX yet.

@kurt That was it! Thanks.