←back to thread

353 points HunOL | 2 comments | | HN request time: 0.001s | source
Show context
mickeyp ◴[] No.45781619[source]
SQLite is a cracking database -- I love it -- that is let down by its awful defaults in service of 'backwards compatibility.'

You need a brace of PRAGMAs to get it to behave reasonably sanely if you do anything serious with it.

replies(2): >>45781956 #>>45781998 #
tejinderss ◴[] No.45781956[source]
Do you know any good default PRAGMAs that one should enable?
replies(3): >>45782017 #>>45782031 #>>45782813 #
mickeyp ◴[] No.45782017[source]
These are my PRAGMAs and not your PRAGMAs. Be very careful about blindly copying something that may or may not match your needs.

    PRAGMA foreign_keys=ON
    PRAGMA recursive_triggers=ON
    PRAGMA journal_mode=WAL
    PRAGMA busy_timeout=30000
    PRAGMA synchronous=NORMAL
    PRAGMA cache_size=10000
    PRAGMA temp_store=MEMORY
    PRAGMA wal_autocheckpoint=1000
    PRAGMA optimize <- run on tx start
Note that I do not use auto_vacuum for DELETEs are uncommon in my workflows and I am fine with the trade-off and if I do need it I can always PRAGMA it.

defer_foreign_keys is useful if you understand the pros and cons of enabling it.

replies(3): >>45782120 #>>45782365 #>>45782487 #
adzm ◴[] No.45782120[source]
Really, no mmap?
replies(1): >>45782274 #
1. metrix ◴[] No.45782274[source]
I'm curious what your suggest mmap pragma would be.
replies(1): >>45793234 #
2. adzm ◴[] No.45793234[source]
PRAGMA mmap_size=268435456;

for example? I'm surprised by the downvotes. Using mmap significantly reduced my average read query time; durations about 70% the length!