[GH-ISSUE #6047] [Question]: Data storage #4188

Closed
opened 2026-10-31 20:37:49 +07:00 by bsakaguchi · 3 comments
Owner

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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 ```shell ``` ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
Author
Owner

@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.settings stores client JSON

Inbound.Settings (internal/database/model/model.go) is a JSON-text column, and for most protocols its clients array is close to Xray-core's own wire format: GenXrayInboundConfig and XrayService.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 into peers, VLESS encryption is stripped, Shadowsocks per-client method is healed, MTProto secrets are normalized — all handled in model.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 clients table (model.ClientRecord in model.go, TableName() → "clients") with real columns — email (unique), subId, uuid, password, flow, security, keys, totalGB, expiryTime, enable, tgId, group, comment — plus a client_inbounds join 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's settings JSON first, then in the same DB transaction calls ClientService.SyncInbound (internal/web/service/client_link.go) to reconcile the clients/client_inbounds rows 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.db backup into a PostgreSQL-backed panel

This 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) detects database.IsPostgres(), sniffs the upload's header, and for a SQLite file calls migrateSQLiteIntoPostgres → 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 to pg_restore/pg_dump at 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, and internal/database/dump_sqlite.go are 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:

  1. The exact toast text shown after the failed restore — the panel appends the specific backend error in parentheses, e.g. "An error occurred while importing the database. (...)".
  2. Or the matching warning line from the panel log around that time (journalctl -u x-ui -n 200, or the file under XUI_LOG_FOLDER if set).
  3. Confirmation that XUI_DB_TYPE=postgres (and XUI_DB_DSN) were actually set in /etc/default/x-ui at the time of the restore attempt.
  4. Which file you uploaded — specifically, a .db downloaded 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.

<!-- gh-comment-id:5017980218 --> @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.settings` stores client JSON `Inbound.Settings` (`internal/database/model/model.go`) is a JSON-text column, and for most protocols its `clients` array is close to Xray-core's own wire format: `GenXrayInboundConfig` and `XrayService.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 into `peers`, VLESS `encryption` is stripped, Shadowsocks per-client `method` is healed, MTProto secrets are normalized — all handled in `model.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 `clients` table (`model.ClientRecord` in `model.go`, `TableName()` → `"clients"`) with real columns — email (unique), subId, uuid, password, flow, security, keys, totalGB, expiryTime, enable, tgId, group, comment — plus a `client_inbounds` join 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's `settings` JSON first, then in the same DB transaction calls `ClientService.SyncInbound` (`internal/web/service/client_link.go`) to reconcile the `clients`/`client_inbounds` rows 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.db` backup into a PostgreSQL-backed panel This 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`) detects `database.IsPostgres()`, sniffs the upload's header, and for a SQLite file calls `migrateSQLiteIntoPostgres` → `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 to `pg_restore`/`pg_dump` at 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`, and `internal/database/dump_sqlite.go` are 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: 1. The exact toast text shown after the failed restore — the panel appends the specific backend error in parentheses, e.g. "An error occurred while importing the database. (...)". 2. Or the matching warning line from the panel log around that time (`journalctl -u x-ui -n 200`, or the file under `XUI_LOG_FOLDER` if set). 3. Confirmation that `XUI_DB_TYPE=postgres` (and `XUI_DB_DSN`) were actually set in `/etc/default/x-ui` at the time of the restore attempt. 4. Which file you uploaded — specifically, a `.db` downloaded 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.*
Author
Owner

@MHSanaei commented on GitHub (Jul 23, 2026):

Two parts:

Why inbounds.settings stores client JSON: Inbound.Settings is a JSON-text column whose clients array 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 normalized clients table plus a client_inbounds join 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 .db even when running on PostgreSQL; the code detects Postgres, sniffs the header, and copies every table in one transaction (no pg_restore needed). 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 matching journalctl -u x-ui line; (2) confirmation XUI_DB_TYPE=postgres/XUI_DB_DSN were set at restore time; (3) which file you uploaded. Closing the question part as answered.

<!-- gh-comment-id:5059221752 --> @MHSanaei commented on GitHub (Jul 23, 2026): Two parts: **Why `inbounds.settings` stores client JSON:** `Inbound.Settings` is a JSON-text column whose `clients` array 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 normalized `clients` table plus a `client_inbounds` join 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 `.db` even when running on PostgreSQL; the code detects Postgres, sniffs the header, and copies every table in one transaction (no `pg_restore` needed). 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 matching `journalctl -u x-ui` line; (2) confirmation `XUI_DB_TYPE=postgres`/`XUI_DB_DSN` were set at restore time; (3) which file you uploaded. Closing the question part as answered.
Author
Owner

@vahellame commented on GitHub (Jul 23, 2026):

double neuroslop, good

<!-- gh-comment-id:5059849146 --> @vahellame commented on GitHub (Jul 23, 2026): double neuroslop, good
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#4188
No description provided.