Ruby on rails rake db:使用PostgreSQL创建----fe_sendauth:未提供密码

Ruby on rails rake db:使用PostgreSQL创建----fe_sendauth:未提供密码,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,这一切都是新鲜事,所以请耐心等待。基本上,我是想在我的LinuxLite机器上安装Rails。安装PostgreSQL后,我按照教程的说明创建了一个数据库角色,如下所示 sudo -u postgres createuser tjjjwxzq -s 但是我没有继续使用这个角色创建密码,因为教程让它看起来像是一个可选的东西。我在我的数据库.yml文件中指定了开发环境用户名: development: <<: *default database: myapp_developme

这一切都是新鲜事,所以请耐心等待。基本上,我是想在我的LinuxLite机器上安装Rails。安装PostgreSQL后,我按照教程的说明创建了一个数据库角色,如下所示

sudo -u postgres createuser tjjjwxzq -s
但是我没有继续使用这个角色创建密码,因为教程让它看起来像是一个可选的东西。我在我的
数据库.yml
文件中指定了开发环境用户名:

development:
  <<: *default
  database: myapp_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user that initialized the database.
  username: tjjjwxzq

  # The password associated with the postgres role (username).
  #password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost
如您所见,我将
tjjwxzq
用户的身份验证方法设置为
trust
,因为我没有创建密码,也不想提供密码。但是当我运行时,在我的Rails项目目录中

rake db:create
我得到:

fe_sendauth: no password supplied
...
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"myapp_test"}
我对PostgreSQL和Rails完全陌生,我已经在谷歌上搜索了几个小时的解决方案。更改
pg_hba.conf
文件似乎很有希望,但对我来说并不奏效。我怀疑我可以通过为我创建的
tjjwxzq
角色指定密码来通过此测试,但我想了解为什么我的设置现在不起作用。非常感谢您的帮助

编辑: 好吧,我意识到我犯了一个愚蠢的错误
rake db:create
用于创建
myapp_development
(指定的开发数据库)我已经检查了日志文件,最新的日志是:

2015-04-01 07:04:28 SGT [2342-1] tjjjwxzq@postgres ERROR:  database "myapp_development" already exists
2015-04-01 07:04:28 SGT [2342-2] tjjjwxzq@postgres STATEMENT:  CREATE DATABASE "myapp_development" ENCODING = 'unicode'
现在我意识到,
rakedb:create
的输出中显示了最后一行

Couldn't create database for {"adapter"=>"postgresql", encoding"=>"unicode", "pool"=>5, "database"=>"myapp_test"}
所以问题实际上是我的测试数据库,看看我的
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

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: myapp_test
default:&default
适配器:postgresql
编码:unicode
#有关连接池的详细信息,请参阅rails配置指南
# http://guides.rubyonrails.org/configuring.html#database-汇集
游泳池:5
#警告:定义为“测试”的数据库将被删除并删除
#运行“rake”时从开发数据库重新生成。
#请勿将此数据库设置为与开发或生产相同的数据库。
测试:
我不喜欢这个

sudo -u postgres createuser tjjjwxzq -s
没有理由让该用户成为整个集群的超级用户(
-s
)。只允许该用户创建数据库

sudo -u postgres createuser tjjjwxzq --createdb
将config/database.yml更改为使用套接字。注释掉
host:localhost
行。(我假设您没有在Windows下运行。)


啊好的。但是,在我已经以超级用户身份创建了
tjjwxzq
之后,如何更改角色权限?运行
sudo-u postgres createuser tjjwxzq--createdb
会简单地覆盖以前的权限吗?另外,如果我在更改用户权限之前运行
rake db:create
,我应该能够在以后更改权限而不影响任何事情,对吗?由于用户“postgres”(可能是您拥有的唯一其他超级用户),您可以执行SQL语句
alter role tjjwxzq nosuperuser createdb。您应该能够在不影响任何其他内容的情况下更改这些特权,尽管在大多数情况下并非如此。(config/database.yml中的Rails用户需要具有createdb权限,但不需要超级用户权限。)好的,我更改了
tjjwxzq
的权限并更改了
database.yml
文件。但是当我运行rakedb:create时,仍然没有任何乐趣。错误与此相同
fe\u sendauth:未提供密码
。有什么想法吗?连接适配器与pg_hba.conf中的错误规则(错误行)匹配。查看PostgreSQL日志文件,查看它与哪一行匹配;可能需要指定套接字目录。哪个操作系统?
sudo -u postgres createuser tjjjwxzq --createdb
# Connect on a TCP socket. Omitted by default since the client uses a # domain socket that doesn't need configuration. Windows does not have # domain sockets, so uncomment these lines. # host: localhost
$ bin/rake db:create