mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5320] [Question]: x-ui.db is no longer updated instantly in recent versions (WAL mode?) #3727
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3727
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
What have you already tried?
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
@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:PRAGMAstatements executed on the live connection (lines 765–773):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-waland merged back intox-ui.dbonly at checkpoint events (seeCheckpoint()at line 855, which runsPRAGMA 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 trafficGET /panel/api/inbounds/getClientTraffics/:email— traffic stats for a specific clientGET /panel/api/inbounds/onlines— currently online clientsThe full OpenAPI 3 spec is served at
/panel/api/openapi.jsonand 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-sqlite3for Node, etc.) automatically reads from bothx-ui.dbandx-ui.db-walas a single consistent view. You do not need to do anything special — just openx-ui.dbnormally. The WAL files are read transparently. The common mistake is trying to parsex-ui.dbwith 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):
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
PRAGMAon every startup. Reverting it would require patchinginternal/database/db.goand 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.