[GH-ISSUE #5320] [Question]: x-ui.db is no longer updated instantly in recent versions (WAL mode?) #3727

Closed
opened 2026-10-31 20:34:31 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @mohsenrahmani145 on GitHub (Jun 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5320

What are you trying to do?

I have a Telegram bot that reads data directly from the x-ui.db SQLite database. In older versions of 3x-ui, all changes (adding/removing users, traffic usage updates, expiration updates, etc.) were written to x-ui.db immediately, and my bot could monitor users and send notifications when their traffic quota or subscription period expired.

In recent versions, I noticed that changes are no longer written instantly to x-ui.db. Instead, additional files such as x-ui.db-wal and x-ui.db-shm are created, and the latest data seems to be stored there.

I would like to know:

  1. Is this expected behavior?
  2. Has 3x-ui switched SQLite to WAL (Write-Ahead Logging) mode?
  3. What is the recommended way for external applications/bots to read up-to-date data from the database?
  4. Is there a way to force changes to be written directly to x-ui.db as in older versions?

What have you already tried?

  • Checked the database files (x-ui.db, x-ui.db-wal, x-ui.db-shm).
  • Compared behavior between older and newer versions.
  • Verified that some recent updates are not immediately visible in x-ui.db alone.

3x-ui version

3.3.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Screenshots or config snippets

No response

Before submitting

  • I read the Wiki and searched existing issues.
  • This is a usage question, not a bug report.
  • This question is written in English.
Originally created by @mohsenrahmani145 on GitHub (Jun 14, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5320 ### What are you trying to do? I have a Telegram bot that reads data directly from the x-ui.db SQLite database. In older versions of 3x-ui, all changes (adding/removing users, traffic usage updates, expiration updates, etc.) were written to x-ui.db immediately, and my bot could monitor users and send notifications when their traffic quota or subscription period expired. In recent versions, I noticed that changes are no longer written instantly to x-ui.db. Instead, additional files such as x-ui.db-wal and x-ui.db-shm are created, and the latest data seems to be stored there. I would like to know: 1. Is this expected behavior? 2. Has 3x-ui switched SQLite to WAL (Write-Ahead Logging) mode? 3. What is the recommended way for external applications/bots to read up-to-date data from the database? 4. Is there a way to force changes to be written directly to x-ui.db as in older versions? ### What have you already tried? - Checked the database files (x-ui.db, x-ui.db-wal, x-ui.db-shm). - Compared behavior between older and newer versions. - Verified that some recent updates are not immediately visible in x-ui.db alone. ### 3x-ui version 3.3.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Screenshots or config snippets _No response_ ### Before submitting - [x] I read the [Wiki](https://github.com/MHSanaei/3x-ui/wiki) and searched [existing issues](../issues?q=is%3Aissue). - [x] This is a usage question, not a bug report. - [x] This question is written in English.
bsakaguchi 2026-10-31 20:34:31 +07:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 14, 2026):

Yes, WAL mode is intentionally enabled in recent versions. All four questions are answered below, grounded in the source code at internal/database/db.go.

1 & 2 — Is this expected? Has 3x-ui switched to WAL mode?

Yes. The SQLite connection is opened with WAL mode explicitly set in two places in internal/database/db.go:

  • The DSN string (line 756):
    ?_journal_mode=WAL&_busy_timeout=10000&_synchronous=NORMAL&_txlock=immediate
    
  • Followed by two PRAGMA statements executed on the live connection (lines 765–773):
    PRAGMA journal_mode=WAL;
    PRAGMA busy_timeout=10000;
    PRAGMA synchronous=NORMAL;
    

This is a deliberate change, not a bug. WAL mode improves concurrent read/write performance: writers no longer block readers and vice versa. The trade-off is that committed data is staged in x-ui.db-wal and merged back into x-ui.db only at checkpoint events (see Checkpoint() at line 855, which runs PRAGMA wal_checkpoint). In the codebase, checkpoints are triggered only during database export/backup operations (internal/web/service/server.go, lines 1143 and 1188). Routine writes (user changes, traffic updates) stay in the WAL file until SQLite auto-checkpoints (default: every 1000 pages).

3 — Recommended way for external applications to read current data

Two options, in order of preference:

  • Use the REST API. The panel exposes a documented JSON API. Relevant endpoints include:

    • GET /panel/api/inbounds/list — all inbounds with embedded client data and traffic
    • GET /panel/api/inbounds/getClientTraffics/:email — traffic stats for a specific client
    • GET /panel/api/inbounds/onlines — currently online clients

    The full OpenAPI 3 spec is served at /panel/api/openapi.json and can be browsed in-panel. Authenticate with the same credentials used to log into the web UI (session cookie or the API login endpoint). This approach is always consistent because it reads through the same GORM layer that wrote the data.

  • Open the SQLite file directly with a WAL-aware reader. Any standard SQLite library (Python's built-in sqlite3, go-sqlite3, better-sqlite3 for Node, etc.) automatically reads from both x-ui.db and x-ui.db-wal as a single consistent view. You do not need to do anything special — just open x-ui.db normally. The WAL files are read transparently. The common mistake is trying to parse x-ui.db with a raw file reader or a tool that does not understand WAL; such tools will see stale data because the WAL content is simply not in the main file yet.

    Example (Python):

    import sqlite3
    # Open read-only; SQLite handles .db-wal transparently
    con = sqlite3.connect("file:/etc/x-ui/x-ui.db?mode=ro", uri=True)
    

4 — Can WAL mode be disabled to revert to the old behavior?

There is no environment variable or panel setting to disable WAL mode. It is hardcoded in the DSN and enforced via PRAGMA on every startup. Reverting it would require patching internal/database/db.go and rebuilding, which would be unsupported and could be overwritten on the next panel update. The correct path is to use option 2 above (a WAL-aware SQLite client) or option 1 (the REST API).

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4702045730 --> @github-actions[bot] commented on GitHub (Jun 14, 2026): **Yes, WAL mode is intentionally enabled in recent versions.** All four questions are answered below, grounded in the source code at `internal/database/db.go`. **1 & 2 — Is this expected? Has 3x-ui switched to WAL mode?** Yes. The SQLite connection is opened with WAL mode explicitly set in two places in `internal/database/db.go`: - The DSN string (line 756): ``` ?_journal_mode=WAL&_busy_timeout=10000&_synchronous=NORMAL&_txlock=immediate ``` - Followed by two `PRAGMA` statements executed on the live connection (lines 765–773): ```sql PRAGMA journal_mode=WAL; PRAGMA busy_timeout=10000; PRAGMA synchronous=NORMAL; ``` This is a deliberate change, not a bug. WAL mode improves concurrent read/write performance: writers no longer block readers and vice versa. The trade-off is that committed data is staged in `x-ui.db-wal` and merged back into `x-ui.db` only at checkpoint events (see `Checkpoint()` at line 855, which runs `PRAGMA wal_checkpoint`). In the codebase, checkpoints are triggered only during database export/backup operations (`internal/web/service/server.go`, lines 1143 and 1188). Routine writes (user changes, traffic updates) stay in the WAL file until SQLite auto-checkpoints (default: every 1000 pages). **3 — Recommended way for external applications to read current data** Two options, in order of preference: - **Use the REST API.** The panel exposes a documented JSON API. Relevant endpoints include: - `GET /panel/api/inbounds/list` — all inbounds with embedded client data and traffic - `GET /panel/api/inbounds/getClientTraffics/:email` — traffic stats for a specific client - `GET /panel/api/inbounds/onlines` — currently online clients The full OpenAPI 3 spec is served at `/panel/api/openapi.json` and can be browsed in-panel. Authenticate with the same credentials used to log into the web UI (session cookie or the API login endpoint). This approach is always consistent because it reads through the same GORM layer that wrote the data. - **Open the SQLite file directly with a WAL-aware reader.** Any standard SQLite library (Python's built-in `sqlite3`, `go-sqlite3`, `better-sqlite3` for Node, etc.) automatically reads from both `x-ui.db` and `x-ui.db-wal` as a single consistent view. You do not need to do anything special — just open `x-ui.db` normally. The WAL files are read transparently. The common mistake is trying to parse `x-ui.db` with a raw file reader or a tool that does not understand WAL; such tools will see stale data because the WAL content is simply not in the main file yet. Example (Python): ```python import sqlite3 # Open read-only; SQLite handles .db-wal transparently con = sqlite3.connect("file:/etc/x-ui/x-ui.db?mode=ro", uri=True) ``` **4 — Can WAL mode be disabled to revert to the old behavior?** There is no environment variable or panel setting to disable WAL mode. It is hardcoded in the DSN and enforced via `PRAGMA` on every startup. Reverting it would require patching `internal/database/db.go` and rebuilding, which would be unsupported and could be overwritten on the next panel update. The correct path is to use option 2 above (a WAL-aware SQLite client) or option 1 (the REST API). *This reply was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3727
No description provided.