新手问题 部署 rails 项目使用 postgres 数据库 ,创建了数据库用户 这个普通用户却登录不了

babyhai · 2018年01月09日 · 最后由 mlzhuyi 回复于 2018年01月10日 · 2908 次阅读

我是按照 这个操作部署的 [使用 Puma 和 Nginx 部署 Rails 应用程序]https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04)

使用了 rbenv-vars 设置环境变量; 操作 这一步出错了:

RAILS_ENV=production rake db:create

报错信息是:

FATAL:  password authentication failed for user "APPNAME_DATABASE_USER=haley"
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "username"=>"APPNAME_DATABASE_USER=haley", "password"=>"APPNAME_DATABASE_PASSWORD=foobar", "database"=>"appname_production"}
rake aborted!
PG::ConnectionBad: FATAL:  password authentication failed for user "APPNAME_DATABASE_USER=haley"

Tasks: TOP => db:create
(See full trace by running task with --trace)

这是 postgres 数据库的配置文件: [/var/lib/pgsql/9.5/data/pg_hba.conf]

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             65.49.212.216/32        trust

# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident


新建的 haley 用户 登录也提示错误

这么登录会报错 su - haley

[baby@host appname]$ su - haley
Password:
su: Authentication failure

这么登录不需要输入 [数据库用户:haley] 的密码,需要输入 baby 用户的密码 [baby 是我的 centos 系统中的普通用户,不是数据库用户]

[baby@host appname]$ sudo su - haley
[sudo] password for baby:
Last login: Tue Jan  9 04:18:05 EST 2018 on pts/3
Last failed login: Tue Jan  9 04:50:30 EST 2018 on pts/0
There was 1 failed login attempt since the last successful login.
[haley@host ~]$

求解 是哪里出了问题?

我现在可以用 haley 用户登录进入数据库,但是执行 RAILS_ENV=production rake db:create 还是报错

[baby@host appname]$ RAILS_ENV=production rake db:create
FATAL:  role "APPNAME_DATABASE_USER=haley" does not exist
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "username"=>"APPNAME_DATABASE_USER=haley", "password"=>"APPNAME_DATABASE_PASSWORD=foobar", "database"=>"appname_production"}
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "APPNAME_DATABASE_USER=haley" does not exist


Caused by:
PG::ConnectionBad: FATAL:  role "APPNAME_DATABASE_USER=haley" does not exist

Tasks: TOP => db:create
(See full trace by running task with --trace)

username: <%= ENV["APPNAME_DATABASE_USER"] %> 其他的同

这是我的数据库配置文件

用 DATABASE_URL

现在得报错:

fe_sendauth: no password supplied
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "username"=>nil, "password"=>nil, "database"=>"appname_production"}
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied

Tasks: TOP => db:create
(See full trace by running task with --trace)

DATABASE_URL 是怎么写

username: <%= ENV["APPNAME_DATABASE_USER"] %>
只要理解里面 ENV 方法的定义,你应该就能明白是那个环节你的理解出了偏差

babyhai 关闭了讨论。 01月12日 13:50
需要 登录 后方可回复, 如果你还没有账号请 注册新账号