Ecto Postgres install error password authentication failed
Asked Answered
N

4

29

I created a phoenix project from the hello example using digital ocean. I entered the username and password from the etc/motd.tail file. I keep getting the error message below. I am a beginner and for some reason I just cannot get ecto to install correctly.

** (Mix) The database for Hello.Repo couldn't be created, reason given: psql: FATAL: password authentication failed for user "elixir" FATAL: password authentication failed for user "elixir"

You can use the following Postgress database credentials: * User: elixir * Pass: ***

install. Any help would be appreciated.

Nash answered 4/3, 2016 at 0:35 Comment(0)
N
11

I assume this error is happening on the mix ecto.create task?

This happens because Ecto uses psql to create the database, however this is no longer the case in the upcoming Ecto 2.0.

The following GitHub issue shows the same issue https://github.com/elixir-lang/ecto/issues/1207

The relevant comment with the fix is https://github.com/elixir-lang/ecto/issues/1207#issuecomment-172570064:

My database config (pg_hba.conf) was apparently wrong.

For anyone else encountering this:

host all my_user 127.0.0.1/32 trust will not work host all my_user localhost trust will work

Please check your pg_hba.conf (likely in /etc/postsgresql/9.x/pg_hba.conf).

Nittygritty answered 4/3, 2016 at 8:28 Comment(2)
First thank you for your help. I attempted to edit my pg_hba.conf file (localhost trust). host all all localhost trust md5 ** (Mix) The database for Hello.Repo couldn't be created, reason given: psql: FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres"Nash
I just created a new phoenix project in root and then ran mix ecto.create and it worked. Thank youNash
E
97

I get the same error using Ubuntu 14.04 and I corrected resetting the 'postgres' password:

$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"

and restart postgres service:

sudo service postgresql restart
Ejector answered 22/5, 2016 at 14:50 Comment(1)
Worked for me too!Agitprop
N
11

I assume this error is happening on the mix ecto.create task?

This happens because Ecto uses psql to create the database, however this is no longer the case in the upcoming Ecto 2.0.

The following GitHub issue shows the same issue https://github.com/elixir-lang/ecto/issues/1207

The relevant comment with the fix is https://github.com/elixir-lang/ecto/issues/1207#issuecomment-172570064:

My database config (pg_hba.conf) was apparently wrong.

For anyone else encountering this:

host all my_user 127.0.0.1/32 trust will not work host all my_user localhost trust will work

Please check your pg_hba.conf (likely in /etc/postsgresql/9.x/pg_hba.conf).

Nittygritty answered 4/3, 2016 at 8:28 Comment(2)
First thank you for your help. I attempted to edit my pg_hba.conf file (localhost trust). host all all localhost trust md5 ** (Mix) The database for Hello.Repo couldn't be created, reason given: psql: FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres"Nash
I just created a new phoenix project in root and then ran mix ecto.create and it worked. Thank youNash
C
3

We just need to create a new postgresql username and password according to the files inside config folder using this db method

$ sudo -u postgres createuser <username>
$ sudo -u postgres createdb <dbname>
$ sudo -u postgres psql
psql=# alter user <username> with encrypted password '<password>';
psql=# grant all privileges on database <dbname> to <username> ;
Cece answered 11/3, 2018 at 20:3 Comment(1)
✗ sudo -u postgres createuser me sudo: unknown user: postgres sudo: unable to initialize policy pluginBaldhead
S
0

I needed to update the pg_hba.conf to make this work.

I am using Fedora, so get to /var/lib/pgsql/data

# "local" is for Unix domain socket connections only
local   all             postgres                                peer
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 ident

Then I created an elixir user in postgres with databse creation capabilities and configured it in dev.exs (user/password/database)

Stuckey answered 20/1, 2017 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.