29
votes

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

4 Answers

92
votes

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
10
votes

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).

3
votes

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> ;
0
votes

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)