2010-07-03 14 views
24

मैं (परीक्षण) अपने आवेदन में कुछ दोहराव आपरेशन बना दिया है, और अचानक मैं एक अजीब त्रुटि मिल रही है:OperationalError: डेटाबेस लॉक किया गया है

OperationalError: database is locked 

मैं सर्वर को पुनः आरंभ किया है, लेकिन समस्या बनी रहती है । यह सब क्या हो सकता है?

उत्तर

41
Django डॉक से

:

SQLite is meant to be a lightweight database, and thus can't support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.

Python's SQLite wrapper has a default timeout value that determines how long the second thread is allowed to wait on the lock before it times out and raises the OperationalError: database is locked error.

If you're getting this error, you can solve it by:

Switching to another database backend. At a certain point SQLite becomes too "lite" for real-world applications, and these sorts of concurrency errors indicate you've reached that point.

Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.

Increase the default timeout value by setting the timeout database option optionoption

http://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption

+1

निर्दिष्ट एक लंबे समय तक से भी डिफ़ॉल्ट टाइमआउट समस्या राहत देने में मदद कर सकते हैं: 'create_engine ('SQLite: /// {}' .format (xxx), connect_args = { 'टाइमआउट': 15}) ' –

+0

मेरे मामले में मैं' SQLiteDatabaseBrowser.exe' ... – citynorman

13

इस के लिए व्यावहारिक कारण यह है कि अजगर या Django गोले डीबी के लिए एक अनुरोध खोला है और यह ठीक से बंद नहीं किया गया था अक्सर है; आपके टर्मिनल एक्सेस को मारना अक्सर इसे मुक्त करता है। मुझे आज कमांड लाइन परीक्षण चलाने पर यह त्रुटि हुई थी।

संपादित करें: मैं इस पर समय-समय पर upvotes मिलता है। आप, टर्मिनल रिबूट करने के बिना पहुँच को मारने के लिए चाहते हैं, तो उसके बाद कमांडलाइन से आप कर सकते हैं:

from django import db 
db.connections.close_all() 
+1

कैसे यह टर्मिनल की हत्या के बिना ठीक करने के लिए के साथ फ़ाइल खोला था? कोई उपाय? – neuronet

+0

@neuronet खोल में अपना कनेक्शन बंद करें? –

5

मेरे मामले में, यह क्योंकि मैं SQLite ब्राउज़र से डेटाबेस को खोलने था। जब मैं इसे ब्राउज़र से बंद करता हूं, तो समस्या खत्म हो जाती है।

+0

धन्यवाद यह मेरे लिए काम किया। – an0nh4x0r

-1

इस आदेश का प्रयास करें:

sudo fuser -k 8000/tcp 
+0

-1, डाउनवॉटेड क्योंकि यह कोई समाधान नहीं देता है कि यह समाधान क्या करता है और कैसे, – helplessKirk

+0

का उपयोग किया जा रहा बंदरगाह के बारे में धारणाएं बनाते हुए यह किसी भी तरह से मदद करता है? –

संबंधित मुद्दे