Ecto Postgres安装报错密码验证失败

Ecto Postgres install error password authentication failed

我使用数字海洋从 hello 示例创建了一个 phoenix 项目。我从 etc/motd.tail 文件中输入了用户名和密码。我不断收到以下错误消息。我是初学者,出于某种原因我无法正确安装 ecto。

** (Mix) 无法创建 Hello.Repo 的数据库,给出原因:psql: FATAL: 用户 "elixir" 的密码验证失败 严重:用户 "elixir"

的密码验证失败

您可以使用以下 Postgress 数据库凭据: * 用户:长生不老药 * 通过:***

安装。任何帮助,将不胜感激。

我假设这个错误发生在 mix ecto.create 任务上?

发生这种情况是因为 Ecto 使用 psql 创建数据库,但是在即将推出的 Ecto 2.0 中不再是这种情况。

以下 GitHub 问题显示了相同的问题 https://github.com/elixir-lang/ecto/issues/1207

修复的相关评论是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

请检查您的 pg_hba.conf(可能在 /etc/postsgresql/9.x/pg_hba.conf)。

我在使用 Ubuntu 14.04 时遇到同样的错误,我更正了重置 'postgres' 密码:

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

并重启 postgres 服务:

sudo service postgresql restart

我需要更新 pg_hba.conf 才能完成这项工作。

我正在使用 Fedora,所以请转到 /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

然后我在 postgres 中创建了一个具有数据库创建功能的 elixir 用户,并在 dev.exs (user/password/database)

中配置了它

我们只需要根据 config 文件夹中的文件使用 this db method

创建一个新的 postgresql usernamepassword
$ 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> ;