Fedora 26下Phoenix与PostgreSQL连接认证失败问题求助
mix ecto.create on Fedora 26 Let’s get this sorted out—you’re hitting PostgreSQL’s default Ident authentication restriction, which is why Phoenix can’t connect even though you know the postgres user password. Here’s how to fix it step by step:
Why this happens
PostgreSQL uses Ident authentication for local connections by default, which matches your operating system username directly to a PostgreSQL username. Since you’re running Phoenix as your regular user (not the postgres system user), it can’t pass this check. We need to switch to password-based authentication (md5) for the postgres user to let Phoenix connect properly.
Step 1: Edit PostgreSQL’s authentication config file
First, open the pg_hba.conf file—on Fedora 26, it lives at /var/lib/pgsql/data/pg_hba.conf. You’ll need sudo permissions to edit it:
sudo nano /var/lib/pgsql/data/pg_hba.conf
Look for the lines handling local connections for the postgres user. You’ll probably see something like this:
local all postgres ident
Or for TCP loopback connections:
host all all 127.0.0.1/32 ident
Change the ident value to md5 in these lines. For example:
local all postgres md5 host all all 127.0.0.1/32 md5
Save the file (in nano, that’s Ctrl+O then Ctrl+X).
Step 2: Restart PostgreSQL to apply changes
The new authentication rules won’t take effect until you restart the service:
sudo systemctl restart postgresql
Step 3: Double-check your Phoenix Repo configuration
Make sure your config/dev.exs has the correct credentials for Hello.Repo—it should match your postgres user details:
config :hello, Hello.Repo, username: "postgres", password: "postgres", database: "hello_dev", hostname: "localhost", show_sensitive_data_on_connection_error: true, pool_size: 10
Step 4: Run mix ecto.create again
Now go ahead and run the command once more:
mix ecto.create
This should let Phoenix authenticate with the postgres user using your password and create the database without issues.
内容的提问来源于stack exchange,提问作者Matt Stevens

