NOWWORKINGON
I create temporary SQLite database files on almost a daily basis
Some relevant links:
- https://sqlite-utils.datasette.io is the Python CLI tool and library I wrote to speed up this kind of work.
Here’s a recent tutorial I wrote about it: https://datasette.io/tutorials/clean-data
-
https://til.simonwillison.net/sqlite/one-line-csv-operations shows how to use SQLite on the command line to analyze CSV data without even creating a SQLite database file
-
https://simonwillison.net/2021/Jun/19/sqlite-utils-memory/ shows some more advanced in-memory tricks using sqlite-utils
-
https://datasette.io is my larger open source project around building tools for analyzing and publishing data with SQLite
Python SQLite: database is locked
check:
1. you don’t have a hung process sitting on the file :
see if fuser {dbname} returns a line , it should be nothing , if a PID is returned , check that PID with ps {PID}
2. There isn’t a {dbname}-journal file in the directory with cache.db; this would indicate a crashed session that hasn’t been cleaned up properly.
3. Ask the database shell to check itself: $ sqlite3 cache.db "pragma integrity_check;"
4. Backup the database $ sqlite3 cache.db ".backup cache.db.bak"
5. Remove cache.db as you probably have nothing in it (if you are just learning) and try your code again
6. See if the backup works $ sqlite3 cache.db.bak ".schema"
Failing that, read Things That Can Go Wrong and How to Corrupt Your Database Files