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.

4 Answers 4

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
1
  • 4
    Worked for me too!
    – helcim
    Dec 14, 2016 at 11:49
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).

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" Mar 5, 2016 at 15:46
  • I just created a new phoenix project in root and then ran mix ecto.create and it worked. Thank you Mar 5, 2016 at 16:23
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> ;
1
  • ✗ sudo -u postgres createuser me sudo: unknown user: postgres sudo: unable to initialize policy plugin
    – tblev
    May 10, 2021 at 14:08
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.