Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sqlite's WAL mode to avoid database is locked errors #6519

Merged
merged 4 commits into from Mar 15, 2017

Conversation

n8henrie
Copy link
Contributor

Sending PR to help prompt discussion hopefully, likely still a WIP (due to my lack of in-depth knowledge in the area).

Code:

Description:

Try using sqlite WAL mode to fix "database is locked" errors. Please see: #4780 (comment)

(sqlite3.OperationalError) database is locked is [a common error](https://github.com/home-assistant/home-assistant/issues?utf8=✓&q=is%3Aissue%20database%20is%20locked encountered by HomeAssistant newbies using devices like Raspberry Pi.

WAL mode helps facilitate simultaneous read and write for simple sqlite databases which seems to help alleviate this error. The major drawback to this mode seems to be its requirement for a relatively recent version of sqlite, which seems to be satisfied on a standard Raspbian Jessie / Python 3.4 setup:

$ python3.4 -c 'import sqlite3; print(sqlite3.sqlite_version)'
3.8.7.1

Related issue (if applicable): fixes #4780

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Contributor

Hi @n8henrie,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@mention-bot
Copy link

@n8henrie, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @rhooper and @kellerza to be potential reviewers.

@balloob
Copy link
Member

balloob commented Mar 11, 2017

Not sure what the impact of this setting is, but we should only set it when we're using SQLite as the engine

@n8henrie
Copy link
Contributor Author

@balloob definitely.

The pragma command is specific to SQLite and is not compatible with any other SQL database engine.

source -- I don't know if that means this would produce errors with e.g. mysql or if it would just have no effect. Will try to find out.

@n8henrie
Copy link
Contributor Author

Seems to work okay with postgres (at least with the latest commit that checks for sqlite).

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge when conflicts resolved.

@balloob balloob merged commit 33450c7 into home-assistant:dev Mar 15, 2017
@n8henrie n8henrie deleted the sqlite_wal branch March 15, 2017 11:49
@balloob balloob mentioned this pull request Mar 24, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Jun 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(sqlite3.OperationalError) database is locked
4 participants