为我修好了什么: 在config / database.yml中 我添加了一行,user:myapp,并注意以root用户身份重启服务器。
原始问题:
我在使用我的Rails 4应用程序(开发环境)在我的Ubuntu 12.04 VPS(托管在DigitalOcean上)上设置PostGreSQL时遇到问题。
root@ip.address$ su - postgres
postgres@ip.address $ psql
我创建了一个角色' myapp' (与我的Rails应用程序同名),使用我在〜/ .bashrc中设置的密码。角色' myapp'
postgres# create role 'myapp' with password '12345';
postgres# alter role 'myapp' with superuser;
postgres# alter role 'myapp' with LOGIN;
postgres# \q
postgres@ip.address $ exit
root@ip.address$ cd myapp/
root@ip.address$ rake db:setup
...created my tables, etc...no trouble there
的myapp /配置/ database.yml的
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
user: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
development:
<<: *default
database: myapp_development
...
的pg_hba.conf:
local all postgres trust #md5 I already tried
# 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 md5
# IPv6 local connections:
host all all ::1/128 md5
我重新启动了postgresql root@ip.address$ service postgresql restart 它好像重新开始......
但是当我在ip.address访问我的网站时,
PG::ConnectionBad
fe_sendauth: no password supplied
我查看我的日志 VAR /数/ PostgreSQL的/ postgresql.main ...
2014-11-21 17:24:40 UTC LOG: database system was shut down at 2014-11-21 17:24:39 UTC
2014-11-21 17:24:40 UTC LOG: database system is ready to accept connections
2014-11-21 17:24:40 UTC LOG: autovacuum launcher started
2014-11-21 17:24:41 UTC LOG: incomplete startup packet
2014-11-21 17:24:46 UTC FATAL: password authentication failed for user "postgres"
2014-11-21 17:24:46 UTC FATAL: password authentication failed for user "postgres"
2014-11-21 17:24:46 UTC LOG: incomplete startup packet
我不知道&#34; postgres&#34;的密码。我从其他帖子中看到它应该是空白的。 我已经改变了我希望以appname命名的角色。在线PostgreSQL文档没有解决这个问题,或者我似乎无法找到它。我已经像所有关于postgresql的Stack Overflow帖子一样检查过,并且找不到修复程序。我该怎么办?
答案 0 :(得分:0)
我认为您在database.yml中使用user
而非username
导致问题。如果您未提供用户名,则默认为您当前的用户。在尝试启动应用时,您还是su - postgres
吗?这可以解释为什么当它找不到用户名时,它会回到'postgres'。处于postgres环境中可能会导致您的$ MYAPP_DATABASE_PASSWORD环境变量也被取消设置,具体取决于您的设置方式。
答案 1 :(得分:0)
使用user
代替username