mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4876] [Bug]: Error initializing database #3408
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#3408
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 @madcat-314 on GitHub (Jun 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4876
Describe the bug
Immediately after a fresh installation of 3x-ui with PostgreSQL on AlmaLinux 10.2 — I encountered an error: the panel failed to launch.
The logs showed the following entry:
Jun 03 21:13:20 SRV-NAME x-ui[3047]: 2026/06/03 21:13:20 Error initializing database: failed to connect touser=PG-USER database=xui: 127.0.0.1:5432 (127.0.0.1): server error: FATAL: Ident authentication failed for user "PG-USER" (SQLSTATE 28000)This indicates that PostgreSQL was attempting to authenticate the user via "ident" authentication — that is, by verifying the correspondence between the Linux system user and the PostgreSQL role. For an application, however, password-based authentication (specifically
md5orscram-sha-256) is almost always required instead ofident.After I edited the
/var/lib/pgsql/data/pg_hba.conffile by adding the following lines (above more general rules):everything started working immediately.
How to reproduce the problem
Expected behavior
Normal running.
Actual behavior
Just after install:
Panel state: Not running
Start automatically: Yes
xray state: Not running
Relevant logs
Screenshots
No response
3x-ui version
3.2.6
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
AlmaLinux 10.2
Which parts of the panel are affected?
No response
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 3, 2026):
Root cause confirmed
This is a genuine bug in
install_postgres_local()ininstall.sh. The function installs PostgreSQL, creates the role/database, and builds a TCP DSN (postgres://USER:PASS@127.0.0.1:5432/xui?sslmode=disable), but it never modifiespg_hba.confto permit password-based authentication over that TCP connection.On RHEL-family distros (AlmaLinux, Rocky Linux, CentOS, Fedora, RHEL),
postgresql-setup --initdbproduces a defaultpg_hba.confwhose TCP rules useidentauthentication. That means PostgreSQL checks whether the connecting Linux username matches the PostgreSQL role name. Since x-ui runs as root (or another system user) and the PostgreSQL role has a random 8-character name, the check always fails:On Debian/Ubuntu the defaults are different (local connections use
peer, TCP usesmd5), so the same installer works there without modification.Your fix is correct
Adding host-specific
scram-sha-256(ormd5) rules for the application user above the genericidentline is the right solution:After editing, reload PostgreSQL so the new rules take effect:
What should be fixed in the installer
install_postgres_local()should, after creating the role and database, locatepg_hba.confvia PostgreSQL's ownSHOW hba_fileand inject the password-auth entries before the genericidentrules, then reload PostgreSQL. Without this step the installer is broken for all RHEL-family distros.This is a real bug affecting anyone who chooses the "install PostgreSQL locally" option on AlmaLinux, Rocky Linux, CentOS, Fedora, or RHEL.
@madcat-314 commented on GitHub (Jun 4, 2026):
I am not a professional programmer, so I consulted a neural network; I tested the following fix locally, and it worked. Perhaps this could serve as a basis for a more canonical solution.
install_postgres_local—specifically, after this line:
sudo -u postgres psql -c "CREATE DATABASE \"${pg_db}\" OWNER \"${pg_user}\";" >&2 || return 1add
configure_postgres_hba_for_local_xui "${pg_db}" "${pg_user}" || return 1@madcat-314 commented on GitHub (Jun 4, 2026):
Version 3.2.7 is affected by this same bug. The solution is the same as in the previous version.
@MHSanaei commented on GitHub (Jun 4, 2026):
fixed