[GH-ISSUE #4633] [Bug]: Node traffic sync fails with PostgreSQL — max(bigint, unknown) does not exist (SQLSTATE 42883) #3186

Closed
opened 2026-10-31 20:30:39 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @mrnickson-hue on GitHub (May 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4633

Description

When using 3X-UI with PostgreSQL as the database backend and remote nodes configured, the node traffic sync job fails repeatedly with the following error:

WARNING - X-UI: node traffic sync: merge for <NodeName> failed:
ERROR: function max(bigint, unknown) does not exist (SQLSTATE 42883)

Root Cause

In web/service/inbound.go around line 1505, the SetRemoteTraffic function executes:

UPDATE client_traffics
SET up = ?, down = ?, enable = ?, total = ?, expiry_time = ?, reset = ?,
    last_online = MAX(last_online, ?)
WHERE email = ?

MAX(a, b) with two scalar arguments is SQLite-specific syntax that returns the greater of two values. In PostgreSQL, MAX() is an aggregate function (single argument). The PostgreSQL equivalent is GREATEST(a, b).

Steps to Reproduce

  1. Install 3X-UI v3.2.0 with PostgreSQL backend
  2. Add one or more remote nodes in the Nodes panel
  3. Wait for node traffic sync job to run (~5 seconds interval)
  4. Check logs — errors appear immediately for every node

Expected Behavior

Node traffic sync completes successfully and last_online is updated correctly.

Actual Behavior

Sync fails for every node on every cycle, flooding logs with warnings.

Workaround

Create a custom PostgreSQL function that wraps GREATEST:

CREATE OR REPLACE FUNCTION max(bigint, bigint)
RETURNS bigint
LANGUAGE SQL IMMUTABLE PARALLEL SAFE AS
$$ SELECT GREATEST($1, $2); $$;

This makes PostgreSQL resolve MAX(last_online, $N) correctly until the query is fixed in source.

Suggested Fix

In web/service/inbound.go, replace:

last_online = MAX(last_online, ?)

with a dialect-aware expression. If GORM dialect detection is available:

  • PostgreSQL: GREATEST(last_online, ?)
  • SQLite: MAX(last_online, ?)

Or unconditionally use GREATEST if SQLite support is dropped for multi-node setups (since PostgreSQL is required for nodes anyway).

Environment

  • 3X-UI version: v3.2.0
  • Database: PostgreSQL 17
  • OS: Ubuntu 24.04
  • Feature: Remote Nodes (multi-server)
Originally created by @mrnickson-hue on GitHub (May 28, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4633 ## Description When using 3X-UI with PostgreSQL as the database backend and remote nodes configured, the node traffic sync job fails repeatedly with the following error: ``` WARNING - X-UI: node traffic sync: merge for <NodeName> failed: ERROR: function max(bigint, unknown) does not exist (SQLSTATE 42883) ``` ## Root Cause In `web/service/inbound.go` around line 1505, the `SetRemoteTraffic` function executes: ```sql UPDATE client_traffics SET up = ?, down = ?, enable = ?, total = ?, expiry_time = ?, reset = ?, last_online = MAX(last_online, ?) WHERE email = ? ``` `MAX(a, b)` with two scalar arguments is **SQLite-specific syntax** that returns the greater of two values. In PostgreSQL, `MAX()` is an aggregate function (single argument). The PostgreSQL equivalent is `GREATEST(a, b)`. ## Steps to Reproduce 1. Install 3X-UI v3.2.0 with PostgreSQL backend 2. Add one or more remote nodes in the Nodes panel 3. Wait for node traffic sync job to run (~5 seconds interval) 4. Check logs — errors appear immediately for every node ## Expected Behavior Node traffic sync completes successfully and `last_online` is updated correctly. ## Actual Behavior Sync fails for every node on every cycle, flooding logs with warnings. ## Workaround Create a custom PostgreSQL function that wraps `GREATEST`: ```sql CREATE OR REPLACE FUNCTION max(bigint, bigint) RETURNS bigint LANGUAGE SQL IMMUTABLE PARALLEL SAFE AS $$ SELECT GREATEST($1, $2); $$; ``` This makes PostgreSQL resolve `MAX(last_online, $N)` correctly until the query is fixed in source. ## Suggested Fix In `web/service/inbound.go`, replace: ```sql last_online = MAX(last_online, ?) ``` with a dialect-aware expression. If GORM dialect detection is available: - PostgreSQL: `GREATEST(last_online, ?)` - SQLite: `MAX(last_online, ?)` Or unconditionally use `GREATEST` if SQLite support is dropped for multi-node setups (since PostgreSQL is required for nodes anyway). ## Environment - 3X-UI version: v3.2.0 - Database: PostgreSQL 17 - OS: Ubuntu 24.04 - Feature: Remote Nodes (multi-server)
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#3186
No description provided.