Law*_*den 44 authentication postgresql ruby-on-rails
当我尝试在本地postgres数据库上运行"rake test"时,它会抛出上述异常.
这是我的pg_hba.conf文件:#Unix域名套接字本地所有postgres peer的数据库管理登录
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all username peer
local myapp_dev myapp md5
local myapp_test myapp md5
local myapp_prod myapp md5
#local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Run Code Online (Sandbox Code Playgroud)
这是我的database.yml的相关部分
test:
adapter: postgresql
database: myapp_test
pool: 5
timeout: 5000
host: localhost
username: username
password:
Run Code Online (Sandbox Code Playgroud)
在真正的database.yml中,'username'替换为我登录的实际用户名.由于身份验证方法定义为"peer",因此不需要密码.
我也注意重启Postgres
sudo -u postgres pg_ctlcluster 9.3 main restart
Run Code Online (Sandbox Code Playgroud)
我还缺少什么?
Dan*_*ité 27
localhost作为主机引用TCP连接,这意味着auth方法是md5(需要密码)每个你的pg_hba.conf:
# IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5
对于peer将要采取的方法,你需要通过Unix域套接字连接,因为你似乎可以用一个debian样的操作系统,这意味着把/var/run/postgresql在host外地,或者什么都没有(这是默认的,除非环境变量说除此以外).
编辑:如果使用数据库URI(自Rails-4.1以来支持,如 http://weblog.rubyonrails.org/2014/4/8/Rails-4-1/中所述),语法可能是:
对于localhost:
test: "postgresql://localhost/myapp_test"
对于默认的Unix套接字域(主机字段留空):
test: "postgresql:///myapp_test"
Rav*_*stm 19
更改下面的代码,它将工作
pg_hba.conf:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Run Code Online (Sandbox Code Playgroud)
低于其解释:
信任
允许无条件连接.此方法允许任何可以连接到PostgreSQL数据库服务器的人以他们希望的任何PostgreSQL用户身份登录,而无需密码或任何其他身份验证.
MD5
要求客户端提供双MD5哈希密码以进行身份验证.
在这里提及更多
如果您的hb_conf已被修改为强制密码,那么请确保您的rails app的数据库配置在开发和测试环境中都包含密码.
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
username: your_user
password: your_password
development:
<<: *default
database: your_db_development
test:
<<: *default
database: your_db_test
production:
url: <%= ENV['DATABASE_URL'] %>
Run Code Online (Sandbox Code Playgroud)
当我无法为测试数据库提供密码时,我收到此错误.
| 归档时间: |
|
| 查看次数: |
55446 次 |
| 最近记录: |