Capistrano postgresql:致命:用户的对等身份验证失败

use*_*027 5 deployment postgresql capistrano ruby-on-rails unicorn

我是第一次将应用程序部署到数字海洋并遇到两个(可能更多)问题.

1)bundle install添加gem 'unicorn'到Gemfile 后我不能.我发现kgio与windows不兼容.通过capistrano部署时,是否必须存在Gemfile.lock?我将如何解决这个问题?

group :production do
  gem 'pg', '0.14.1'
  gem "nginx"
  gem 'unicorn'
end
Run Code Online (Sandbox Code Playgroud)

2)我在服务器上的postgresql上进行身份验证时遇到问题.

production:
  adapter: postgresql
  encoding: unicode
  database: postgresql
  pool: 5
  username: postgresql
  password: secret
Run Code Online (Sandbox Code Playgroud)

我运行了这些命令(以及其他一些变体):

create user postgresql with password 'secret';
create database postgresql with owner postgresql;
Run Code Online (Sandbox Code Playgroud)

我每次上限部署时都会收到此错误:

FATAL: Peer authentication failed for user "postgresql"
Run Code Online (Sandbox Code Playgroud)

我尝试使用我知道不存在的无效用户名,数据库无效但错误消息始终相同.根据postgresql网站,我应该得到不同的错误...

如果我能得到一些帮助,那就太棒了.谢谢!

小智 8

您需要指定密码验证的主机.

production:
  adapter: postgresql
  encoding: unicode
  database: postgresql
  pool: 5
  host: localhost
  username: postgresql
  password: secret
Run Code Online (Sandbox Code Playgroud)

更多细节在这里


Erw*_*ter 2

您必须首先在文件中设置 Postgres 的密码md5(更安全:从 Postgres 11 开始为scram-sha-256身份验证pg_hba.conf

只要仅允许身份对等身份验证,就不会提示输入密码。您只能以与您的系统用户对应的 db 角色身份登录。

顺便说一句,数据库角色和操作系统用户通常称为postgres,而不是postgresql。我想这不是打字错误吧?

在 shell 中尝试:

sudo -u postgres -i
Run Code Online (Sandbox Code Playgroud)

然后以 db 角色身份通过对等身份验证登录postgres

看: