mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5665] [Bug]: PostgreSQL sequence reset fails on client_inbounds junction table #3948
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#3948
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 @SergioSHA1 on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5665
Describe the bug
After migrating from SQLite to PostgreSQL using the panel's built-in
migration tool, PostgreSQL logs are flooded with repeated errors on
every panel restart. The errors come from a sequence-reset routine
that assumes every table has an id column and unconditionally
calls pg_get_serial_sequence(table, 'id') on it — including
client_inbounds, which is a junction table with a composite primary
key (client_id, inbound_id) and has no id column by design.
A related issue: several ALTER TABLE ... ADD COLUMN statements run
on every startup without an existence check, so they also fail with
"already exists" errors once a column has been added.
Functionality itself is not broken — clients connect and route
traffic normally — but the logs become unusable for spotting real
issues, and the pattern suggests the migration isn't idempotent.
How to reproduce the problem
→ option 2 (Migrate SQLite → PostgreSQL)
sudo systemctl restart x-ui
sudo tail -100 /var/log/postgresql/postgresql-14-main.log
Expected behavior
The sequence-reset routine should skip tables that don't have an
id column (e.g. composite-key junction tables like
client_inbounds), and ADD COLUMN statements should check for
existence first. No errors should appear in the PostgreSQL log for
a normal, successful migration or restart.
Actual behavior
The following errors appear repeatedly, on every restart after the
PostgreSQL migration:
ERROR: column "id" does not exist at character 70
STATEMENT: SELECT setval(pg_get_serial_sequence($1, 'id'),
COALESCE((SELECT MAX(id) FROM "client_inbounds"), 1), true)
WHERE pg_get_serial_sequence($2, 'id') IS NOT NULL
ERROR: column "wg_private_key" of relation "clients" already exists
STATEMENT: ALTER TABLE "clients" ADD "wg_private_key" text
ERROR: column "reset_up" of relation "client_groups" already exists
STATEMENT: ALTER TABLE "client_groups" ADD "reset_up" bigint DEFAULT 0
client_inbounds schema for reference (composite PK, no id column
by design):
---------------+--------+-----------+----------+---------
client_id | bigint | | not null |
inbound_id | bigint | | not null |
flow_override | text | | |
created_at | bigint | | |
Indexes:
"client_inbounds_pkey" PRIMARY KEY, btree (client_id, inbound_id)
"idx_client_inbounds_client_id" btree (client_id)
"idx_client_inbounds_inbound_id" btree (inbound_id)
Relevant logs
Screenshots
No response
3x-ui version
3.4.2
Xray-core version
26.6.27
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 22.04.5 LTS
Which parts of the panel are affected?
Database / migrations
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 (Jun 29, 2026):
Both bugs are confirmed in the v3.4.2 source.
Bug 1 — sequence reset errors on
client_inboundsresyncPostgresSequencesininternal/database/migrate_data.go:279–295iterates every model ininitModels()and runs:The intent is that the
WHERE pg_get_serial_sequence(…) IS NOT NULLclause makes the statement a no-op for tables that have noidsequence. However,model.ClientInbound(declared ininternal/database/model/model.go:691–698) maps toclient_inbounds, which uses a composite primary key (client_id,inbound_id) and has noidcolumn. PostgreSQL validates column references in theSELECTlist at parse/plan time — before evaluating theWHEREcondition — soSELECT MAX(id) FROM "client_inbounds"raises an error unconditionally. The application discards the error (_ = db.Exec(…).Error) so the panel is unaffected, but every PostgreSQL startup logs the failure.The fix is to skip models whose GORM schema has no
idfield before issuing the SQL — e.g., by checkingstmt.Schema.FieldsByDBName["id"]after parsing the model, the same way the existing code already resolves the table name.Bug 2 — repeated
ADD COLUMN … already existserrorsinitModels()ininternal/database/db.go:86–90calls GORM'sAutoMigratefor each model. For PostgreSQL, GORM does not useADD COLUMN IF NOT EXISTS, so if a column was added in a prior run it issues:The columns are real —
ClientRecord.PrivateKey(wg_private_key) inmodel.go:630andClientGroup.ResetUp(reset_up) inmodel.go:652. The application catches these withisIgnorableDuplicateColumnErr(db.go:474–498) and suppresses the Go error, so nothing breaks. But because PostgreSQL has already logged the error server-side before the driver returns control to Go, it cannot be suppressed at the log level from application code. UsingALTER TABLE … ADD COLUMN IF NOT EXISTS(supported from PostgreSQL 9.6) in the migration path would prevent the server-side log entry entirely.Summary
internal/database/and neither requires a schema change.This reply was generated automatically; a maintainer may follow up.
@ArrayKamko commented on GitHub (Jun 30, 2026):
Please this Bug need Quick hotfix
after that PostgreSQL error am getting a lot of error in panel
i cant do anything rightnow
@MHSanaei commented on GitHub (Jul 2, 2026):
Fixed in
273f8872: the sequence resync now skips composite-PK tables like client_inbounds, and AutoMigrate is skipped when the table, columns, and indexes already exist — so neither the setval parse error nor the duplicate ADD COLUMN statements reach the PostgreSQL server log anymore. Will ship in the next release.@ArrayKamko your "Failed to fetch dynamically imported module" errors are a different, client-side issue: the browser cached an old page while the panel binary was updated underneath it. A hard refresh (Ctrl+F5) after a panel update resolves it.