0

我的 Rails 应用程序无法连接到 Postgresql。我怀疑这是因为 Postgres 期望登录它的用户与登录 Ubuntu(12.10)的用户相同。

deployer@xxx:~$ whoami
deployer
deployer@xxx:~$ psql
psql: FATAL:  role "deployer" does not exist

我的设置遵循以下顺序:

a) 作为 root@server 我创建了一个新组admin和一个新用户deployer

groupadd admin
adduser deployer --ingroup admin
ssh-copy-id root@xxx.xxx.xx.xx

b) 我以部署者身份登录并安装了 Postgres

sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql libpq-dev

c) 在我的远程服务器上,我登录到 psql 并创建了一个新用户来匹配我的 Rails 应用程序:

sudo -u postgres psql
create user 'my_app' with password 'secret';
create database my_app_production owner my_app;

对于部署,我使用的是deployer用户。部署期间不断出现此错误:

FATAL: password authentication failed for user "my_app"

这是我的 database.yml

production:
  adapter: postgresql
  encoding: utf8
  database: my_app_production
  pool: 5
  host: localhost
  username: my_app
  password: secret

\du在 psql 中运行会产生以下结果:

 Role name  |                   Attributes                   | Member of 
------------+------------------------------------------------+-----------
 postgres   | Superuser, Create role, Create DB, Replication | {}
 my_app     |                                                | {}
4

1 回答 1

4
deployer@xxx:~$ psql
psql: FATAL:  role "deployer" does not exist

您需要在 postgres 中创建用户:

create user deployer;

或者,在您的个人资料中添加导出,例如:

export PGUSER=postgres

或根据需要更改对 psql 的调用:psql -Uusername database

于 2013-05-17T13:06:12.390 回答