Missing db?

Hi folks!

I’ve been playing around with Photostructure for a bit. After running on my Desktop for a little bit, I set it up using the docker-compose.yml file on a server. I started it up, looked at the pretty interface in a browser, then shut it down.

I was doing some syncs via the CLI, and after I was finished, I started it back up using the compose file, and I got this message:

photostructure    | {"fatal":true,"exit":true,"status":12,"pid":27,"ppid":20,"error":"Library setup failed: ¹: Error: ModelDbJanitor(/ps/library/.photostructure) {\"from\":\"ModelDbJanitor.setup\"}: SqliteError: code SQLITE_READONLY: attempt to write a readonly database¹⁶"}
photostructure    | Error: ModelDbJanitor(/ps/library/.photostructure) {"from":"ModelDbJanitor.setup"}: SqliteError: code SQLITE_READONLY: attempt to write a readonly database¹⁶
photostructure    | SqliteError: attempt to write a readonly database
photostructure    |     at Database.exec (/ps/app/node_modules/better-sqlite3/lib/methods/wrappers.js:9:14)
photostructure    |     at new t.Migration (/ps/app/bin/main.js:9:688803)
photostructure    |     at /ps/app/bin/main.js:9:677958
photostructure    |     at async E._finishSetup (/ps/app/bin/main.js:9:739308)
photostructure    |     at async /ps/app/bin/main.js:9:737233
photostructure    | {"fatal":true,"exit":true,"status":14,"pid":27,"ppid":20,"error":"main setup failed: Error: ModelDbJanitor(/ps/library/.photostructure) {\"from\":\"ModelDbJanitor.setup\"}: SqliteError: code SQLITE_READONLY: attempt to write a readonly database¹⁶"}
photostructure    | This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
photostructure    | SqliteError: attempt to write a readonly database
photostructure    |     at Database.exec (/ps/app/node_modules/better-sqlite3/lib/methods/wrappers.js:9:14)
photostructure    |     at new t.Migration (/ps/app/bin/main.js:9:688803)
photostructure    |     at /ps/app/bin/main.js:9:677958
photostructure    |     at async E._finishSetup (/ps/app/bin/main.js:9:739308)
photostructure    |     at async /ps/app/bin/main.js:9:737233
photostructure    |     at async Function.for (/ps/app/bin/main.js:9:738236)
photostructure    |     at async /ps/app/bin/main.js:9:628506
photostructure    |     at async /ps/app/bin/main.js:9:627268
photostructure    | This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
photostructure    | SqliteError: attempt to write a readonly database
photostructure    |     at Database.exec (/ps/app/node_modules/better-sqlite3/lib/methods/wrappers.js:9:14)
photostructure    |     at new t.Migration (/ps/app/bin/main.js:9:688803)
photostructure    |     at /ps/app/bin/main.js:9:677958
photostructure    |     at async E._finishSetup (/ps/app/bin/main.js:9:739308)
photostructure    |     at async /ps/app/bin/main.js:9:737233
photostructure    |     at async Function.for (/ps/app/bin/main.js:9:738236)
photostructure    |     at async /ps/app/bin/main.js:9:628506
photostructure    |     at async /ps/app/bin/main.js:9:627268
photostructure    | This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
photostructure    | SqliteError: attempt to write a readonly database
photostructure    |     at Database.exec (/ps/app/node_modules/better-sqlite3/lib/methods/wrappers.js:9:14)
photostructure    |     at new t.Migration (/ps/app/bin/main.js:9:688803)
photostructure    |     at /ps/app/bin/main.js:9:677958
photostructure    |     at async E._finishSetup (/ps/app/bin/main.js:9:739308)
photostructure    |     at async /ps/app/bin/main.js:9:737233
photostructure    |     at async Function.for (/ps/app/bin/main.js:9:738236)
photostructure    |     at async /ps/app/bin/main.js:9:628506
photostructure    |     at async /ps/app/bin/main.js:9:627268
photostructure    | This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
photostructure    | SqliteError: attempt to write a readonly database
photostructure    |     at Database.exec (/ps/app/node_modules/better-sqlite3/lib/methods/wrappers.js:9:14)
photostructure    |     at new t.Migration (/ps/app/bin/main.js:9:688803)
photostructure    |     at /ps/app/bin/main.js:9:677958
photostructure    |     at async E._finishSetup (/ps/app/bin/main.js:9:739308)
photostructure    |     at async /ps/app/bin/main.js:9:737233
photostructure    |     at async Function.for (/ps/app/bin/main.js:9:738236)
photostructure    |     at async /ps/app/bin/main.js:9:628506
photostructure    |     at async /ps/app/bin/main.js:9:627268
photostructure exited with code 0

I went to look to see if I had permission errors, but actually…

.
./README.txt
./.library-uid.json
./.NoMedia
./models
./models/version-backup
./models/version-backup/20211208-035458-db.sqlite3
./models/backup
./models/backup/20211208-040617-seq0-set20-db.sqlite3
./models/backup/20211210-181214-seq10-set2-db.sqlite3
./models/backup/20211210-191752-seq14-set2-db.sqlite3
./models/backup/20211210-183051-seq12-set3-db.sqlite3
./models/backup/20211210-172807-seq8-set4-db.sqlite3
./models/backup/20211210-190335-seq13-set1-db.sqlite3
./opened-by
./.metadata_never_index
./settings.toml

Maybe the database isn’t just “read-only”, maybe it doesn’t exist?

Please note, this is not an emergency or even a problem–there’s literally nothing in the database that wouldn’t be regenerated with just a reimport :slight_smile:

Could this have been caused by "Control-C"ing a cli sync?

Being that I’m on a server, I guess there’s a bunch of possible version things that are relevant, but I’m running on Debian bullseye, using Photostructure for Docker:

docker-compose run --rm photostructure sh
Creating photostructure_photostructure_run ... done
/ps/app # ./photostructure --version
1.1.0

Howdy @adamwolf , welcome to PhotoStructure!

Running PhotoStructure from within docker currently defaults to running in “replica” mode: more details are here: What’s PS_FORCE_LOCAL_DB_REPLICA?

When you’re not within docker, PhotoStructure can tell if your library database is on a remote filesystem automatically. From within a docker container, not so much (as there isn’t a way, afaik, to get bind mount metadata from within the container).

Why does this matter?

Because!

When you run a command and we’re in PS_FORCE_LOCAL_DB_REPLICA mode, the changes made to the local replica database need to be written back to the remote primary database (via a “cold backup”) which is fine automatically at process end. I like to ctrl-c processes as much as you, so I’ve installed a sigint handler that should do all end-process-cleanup, but if disk I/O is to slow or docker ends the container, things may not be left in a happy state.

You can try restoring from a prior database backup, but that can have issues as well: run a rebuild after restoring to verify everything is copacetic.

You also may want to avoid these shenanigans by setting PS_FORCE_LOCAL_DB_REPLICA=false in your docker container’s environment variables, but only if your library is stored on a local volume.

1 Like

Sounds great! I had actually already turned that off and started the library rebuild, so I’m feeling right proper chuffed!

1 Like