python - Django sqlite database is locked -
i've been struggling "sqlite3.operationalerror database locked" day....
searching around answers seems known problem i've found explained of time fact sqlite not work nice in multithreading thread potentially timeout waiting more 5 (default timeout) seconds write db because thread has db lock .
so having more threads play db , 1 of them using transactions , writing i've began measuring time takes transactionns complete. i've found no transaction takes more 300 ms , rendering not plausible above explication. unless thread uses transactions makes ~21 (5000 ms / 300 ms) consecutive transactions while other thread desiring write gets ignored time
so other hypothesis potentially explain behavior ?
i have had lot of these problems sqlite before. basically, don't have multiple threads could, potentially, write db. if not acceptable, should switch postgres or else better @ concurrency.
sqlite has simple implementation relies on file system locking. file systems not built low-latency operations this. true network-mounted filesystems , virtual filesystems used vps solutions (that last 1 got me btw).
additionally, have django layer on top of this, adding complexity. don't know when django releases connections (although pretty sure here can give answer in detail :) ). again, if have multiple concurrent writers, need database layer can concurrency. period.
i solved issue switching postgres. django makes simple you, migrating data no-brainer little downtime.
Comments
Post a Comment