mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6047] [Question]: Data storage #4188
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#4188
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 @vahellame on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6047
Describe the bug
You still store full client information in JSON format in inbound table in settings column. Why?
Also, recovery from x-ui.db just not working with PostgreSQL
How to reproduce the problem
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
26.6.7
How did you install 3x-ui?
install.sh script
Operating system
Debian 13
Which parts of the panel are affected?
Other
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jul 20, 2026):
Both parts are addressed below, grounded in the current source (checked against 3.5.0, which you're running).
Why
inbounds.settingsstores client JSONInbound.Settings(internal/database/model/model.go) is a JSON-text column, and for most protocols itsclientsarray is close to Xray-core's own wire format:GenXrayInboundConfigandXrayService.GetXrayConfig(internal/web/service/xray.go) pass that string almost directly into the live Xray config. The per-protocol shape varies a lot (WireGuard clients are rewritten intopeers, VLESSencryptionis stripped, Shadowsocks per-clientmethodis healed, MTProto secrets are normalized — all handled inmodel.go), which is why the row keeps Xray's own format instead of a panel-invented one.That JSON is not the only place client data lives, though. There is a normalized
clientstable (model.ClientRecordinmodel.go,TableName()→"clients") with real columns — email (unique), subId, uuid, password, flow, security, keys, totalGB, expiryTime, enable, tgId, group, comment — plus aclient_inboundsjoin table (model.ClientInbound) so one client identity can be attached to multiple inbounds. Every client create/update path (internal/web/service/client_crud.go,client_inbound_apply.go) writes to the inbound'ssettingsJSON first, then in the same DB transaction callsClientService.SyncInbound(internal/web/service/client_link.go) to reconcile theclients/client_inboundsrows from it. That relational table backs the client list, groups, uniqueness checks, and the traffic/expiry jobs; the JSON blob remains because it is literally what has to reach Xray-core and gets pushed to nodes.So this is a deliberate two-layer design rather than an oversight: dropping the JSON column entirely would mean reconstructing Xray's exact per-protocol settings shape from the relational rows on every config generation. Whether that's worth pursuing further is a maintainer call — tagging @MHSanaei.
Restoring an
x-ui.dbbackup into a PostgreSQL-backed panelThis path exists and is documented in the panel itself: Home page → "Backup & Restore" → "Restore" — its own description states it accepts "a PostgreSQL backup (.dump), a SQLite database (.db), or a SQLite migration dump" when the panel runs on PostgreSQL. On the backend,
ServerService.ImportDB(internal/web/service/server.go) detectsdatabase.IsPostgres(), sniffs the upload's header, and for a SQLite file callsmigrateSQLiteIntoPostgres→database.MigrateData(internal/database/migrate_data.go), which copies every table into PostgreSQL inside a single transaction (rolled back whole on any failure). That path does not shell out topg_restore/pg_dumpat all — those binaries are only needed to restore a native PostgreSQL.dump.I compared this code between v3.5.0 (your version) and the current default branch:
internal/web/service/server.go's restore logic,internal/database/migrate_data.go, andinternal/database/dump_sqlite.goare unchanged, so this isn't something already fixed since your version.Without more detail I can't pin down why it fails for you. Could you provide:
journalctl -u x-ui -n 200, or the file underXUI_LOG_FOLDERif set).XUI_DB_TYPE=postgres(andXUI_DB_DSN) were actually set in/etc/default/x-uiat the time of the restore attempt..dbdownloaded via "Back Up" from a SQLite-backed panel, or something else.I've relabeled this as a question (matching your title) with clarification needed for the restore report, since that half is currently an unconfirmed bug claim with no reproduction steps or logs.
This reply was generated automatically; a maintainer may follow up.
@MHSanaei commented on GitHub (Jul 23, 2026):
Two parts:
Why
inbounds.settingsstores client JSON:Inbound.Settingsis a JSON-text column whoseclientsarray is close to Xray-core's own wire format, so config generation can feed it almost directly into the live Xray config without reconstructing the per-protocol shape each time. It's not the only copy — there's a normalizedclientstable plus aclient_inboundsjoin table, and every create/update writes the JSON first, then in the same transaction reconciles the relational rows (which back the client list, groups, uniqueness checks, and traffic/expiry jobs). So it's a deliberate two-layer design.Restoring an
x-ui.db(SQLite) into a PostgreSQL panel: this path exists — Home → Backup & Restore → Restore accepts a SQLite.dbeven when running on PostgreSQL; the code detects Postgres, sniffs the header, and copies every table in one transaction (nopg_restoreneeded). It's unchanged between v3.5.0 and current, so if a restore failed for you it's worth a separate report. Please reopen with: (1) the exact restore error text (the toast appends the backend error in parentheses) or the matchingjournalctl -u x-uiline; (2) confirmationXUI_DB_TYPE=postgres/XUI_DB_DSNwere set at restore time; (3) which file you uploaded. Closing the question part as answered.@vahellame commented on GitHub (Jul 23, 2026):
double neuroslop, good