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

Features for enabling and disabling WAL mode #132

Closed
simonw opened this issue Aug 10, 2020 · 5 comments
Closed

Features for enabling and disabling WAL mode #132

simonw opened this issue Aug 10, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 10, 2020

I finally figured out how to enable WAL - turns out it's a property of the database file itself: https://github.com/simonw/til/blob/master/sqlite/enabling-wal-mode.md

@simonw simonw added the enhancement New feature or request label Aug 10, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 10, 2020

For the CLI:

$ sqlite-utils enable-wal github.db
$ sqlite-utils disable-wal github.db

For the Python library:

import sqlite_utils

db = sqlite_utils.Database("github.db")
db.enable_wal()
db.disable_wal()
mode = db.journal_mode # "wal" or "delete" or others

@simonw
Copy link
Owner Author

simonw commented Aug 10, 2020

https://www.sqlite.org/pragma.html#pragma_journal_mode lists six modes: DELETE | TRUNCATE | PERSIST | MEMORY | WAL | OFF

I'm only going to implement utilities for DELETE (wal-off) and WAL (wal-on) - the other modes look like they're for specialist purposes that I don't need to support.

If it turns out I do need them I can add those to sqlite-utils later.

@simonw
Copy link
Owner Author

simonw commented Aug 10, 2020

The CLI options should take multiple database files:

$ sqlite-utils enable-wal *.db

It's possible for this to fail if the DB is locked. How about a --retry option that causes it to retry a bunch of times if that happens?

@simonw
Copy link
Owner Author

simonw commented Aug 10, 2020

I'm having trouble figuring out how to write a test that locks a SQLite database (so I can test that --retry actually works). I tried this recipe but it didn't seem to prevent another process from running pragma journal_mode='wal'; against that database:

import time
import sys
import sqlite3

filename = sys.argv[-1]

db = sqlite3.connect(filename)
with db:
    db.execute("create table if not exists counter(id integer primary key, counter text)")
    time.sleep(100)

@simonw
Copy link
Owner Author

simonw commented Aug 10, 2020

For the moment I'll build it without the --retry mode.

@simonw simonw closed this as completed in 2d2d724 Aug 10, 2020
simonw added a commit that referenced this issue Aug 10, 2020
simonw added a commit that referenced this issue Sep 7, 2020
This should have been included in 2d2d724

Refs #132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant