Fix Luanti sqlite WAL file getting huge
I really enjoy the Luanti mapserver project, which gives you a live map of your Luanti world.
One minor problem that can happen with running the mapserver in parallel with a Luanti instance that uses sqlite (the default backend) is that the write-ahead journal (WAL) can get very big.
The way to fix it is to run a short set of commands. Stop luanti and mapserver, run a sqlite checkpoint, and then restore. For example:
cd /home/luanti/game-onyx docker-compose down sqlite3 worlds/onyx/map.sqlite 'PRAGMA wal_checkpoint(TRUNCATE); PRAGMA vacuum;' docker-compose up -d
For my instances, here is the overcomplicated script.
files/2026/listings/fix-map-sqlite.sh (Source)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
#!/bin/sh # Startdate: 2026-03-07 # Purpose: Run a sqlite checkpoint # Dependencies: # sqlite3 # Documentation: # /mnt/public/Support/Games/luanti/luanti-setup.md section "## Shrink map.sqlite-wal" verbose(){ if test -n "${VERBOSE}" ; then echo "${*}" 1>&2 fi } err(){ echo "${*}" 1>&2 } checkpoint(){ # Assumptions: the sqlite database is already not in use, e.g., the luanti world and mapserver have already been stopped. _file="${1}" sqlite3 "${_file}" "PRAGMA wal_checkpoint(TRUNCATE); PRAGMA vacuum;" } main(){ # 1. Find map.sqlite and docker-compose SERVER_WORLD="${SERVER_WORLD:-${1}}" _server_world="${SERVER_WORLD}" # find the first one that matches _path="$( find "${_server_world}" "/home/luanti/game-${_server_world}" "/home/luanti/${_server_world}" -maxdepth 0 -type d -print -quit 2>/dev/null )" if ! test -f "${_path}/docker-compose.yml" ; then err "Fatal! Cannot find docker-compose for ${_path}. Aborted." exit 1 fi verbose "Will use path ${_path}" _map_sqlite="$( find "${_path}/worlds/"*"/map.sqlite" -maxdepth 0 -type f -print -quit 2>/dev/null )" if ! test -f "${_map_sqlite}" ; then err "Fatal! Cannot find map.sqlite in ${_path}/worlds/*/. Aborted." exit 1 fi verbose "Using sqlite file ${_map_sqlite}" # 2. Stop the world ( cd "${_path}" docker-compose down ) # 3. Run the checkpoint checkpoint "${_map_sqlite}" result=$? verbose "Sqlite exit code ${result}" if test $result -ne 0 ; then err "Sqlite checkpoint failed! Please evaluate manually." exit 1 fi # 4. Start the world ( if test -z "${SKIP_START}" ; then cd "${_path}" docker-compose up -d fi ) } # BEGIN IS-SOURCED sourced=0 if [ -n "$ZSH_VERSION" ]; then case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac elif [ -n "$KSH_VERSION" ]; then [ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1 elif [ -n "$BASH_VERSION" ]; then (return 0 2>/dev/null) && sourced=1 else # All other shells: examine $0 for known shell binary filenames. # Detects `sh` and `dash`; add additional shell filenames as needed. case ${0##*/} in sh|-sh|dash|-dash) sourced=1;; esac fi # END BEGIN IS-SOURCED if echo " ${*} " | grep -qiE 'help' || test -z "${*}" ; then echo "Usage: ${0} <path-to-world>" echo "Where <path-to-world> is the short name of the path in /home/luanti" echo "e.g., onyx, so /home/luanti/game-onyx works. The path must contain" echo "docker-compose.yml, and have a worlds/*/map.sqlite." echo "You can also set additional env vars: VERBOSE, SKIP_START." exit 0 fi if test "${sourced}" = "0" ; then main "${*}" fi |
Why here
I keep searching for this on the Internet, because I forget that I documented it locally. You're welcome, self.
References
Weblinks
Inline.
Comments