Rails:fe_sendauth:没有提供密码(PG ::错误)

时间:2014-07-21 09:22:02

标签: ruby-on-rails postgresql

所以我已经看到很多这些问题,但没有一个我需要的答案。大多数都有postgres设置问题或密码错字等。

我遇到了与Rails 3.2无关的Postgres数据库连接问题。

  • Postgres 9.1对其他rails项目工作得很好。 pg_hba.conf设置为默认值,从不需要更改。

  • 我正在使用与其他项目完全相同的database.yml文件,只是数据库名称不同。我之前从未遇到过这个问题,而且我还有大约20个使用postgres的其他rails项目都工作正常。

  • 我正在与名为postgres

  • 的数据库所有者建立联系

我的database.yml文件:

connection: &connection
  adapter: postgresql
  username: postgres
  password: mypassword
  encoding: unicode
  pool: 5

development:
  <<: *connection
  database: projectname_development

test:
  <<: *connection
  database: projectname_test

production:
  <<: *connection
  database: projectname_production

我得到的错误是:

/home/username/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec   
./spec/controllers/keyword_lists_controller_spec.rb     
./spec/controllers/map_keywords_controller_spec.rb ./spec/full_stack/document_import_spec.rb   
./spec/html_content/defined_terms_wrapper_spec.rb 
./spec/html_content/reference_relation_builder_spec.rb ./spec/lib/caches_children_spec.rb 
./spec/logic/content_formatting/content_node_formatter_spec.rb 
./spec/logic/content_formatting/table_formatter_spec.rb 
./spec/logic/content_formatting/text_run_formatter_spec.rb  
./spec/logic/document_processor_spec.rb ./spec/logic/hierarchy_tracker_spec.rb 
./spec/logic/map_builder/content_factory_spec.rb 
./spec/logic/map_builder/page_break_content_factory_spec.rb 
./spec/logic/map_builder/table_content_factory_spec.rb 
./spec/logic/map_builder/text_run_content_factory_spec.rb ./spec/logic/style_converter_spec.rb 
./spec/models/document_spec.rb ./spec/models/keyword_list_spec.rb ./spec/models/map_spec.rb 
./spec/models/related_keyword_spec.rb
/home/username/.rvm/gems/ruby-2.1.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize': fe_sendauth: no password supplied (PG::Error)

但是,我在这里向PGConnection注入了一些代码:

# Connects to a PostgreSQL server and sets up the adapter depending on the
# connected server's characteristics.
def connect
puts Rails.env
puts @connection_parameters.inspect
@connection = PGconn.connect(*@connection_parameters)
# etc.

输出是(我发现这有点奇怪,但可能是连接对象的一部分?):

test
["", 5432, nil, nil, "projectname_test", "postgres", "mypassword"]
test
["", 5432, nil, nil, "postgres", "postgres", "mypassword"]
test
["", 5432, nil, nil, "projectname_test", "postgres", "mypassword"]
test
["", 5432, nil, nil, "postgres", "postgres", "mypassword"]
test
["", 5432, nil, nil, "projectname_test", "postgres", "mypassword"]
NOTICE:  CREATE TABLE will create implicit sequence "bookmarks_id_seq" for serial column "bookmarks.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "bookmarks_pkey" for table "bookmarks"

#.... a whole bunch more of these....

/home/username/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec ...many *_spec.rb files
test
["localhost", 5432, nil, nil, "projectname_test", nil, nil]
/home/username/.rvm/gems/ruby-2.1.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/postgresql_adapter.rb:1224:in `initialize': fe_sendauth: no password supplied (PG::Error)
/home/username/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec lots_of_spec_files_spec.rb failed

更多:

  • 如果我只是在终端中运行bundle exec rspec spec/它运行正常。但是,如果我运行bundle exec cucumber,则会抛出此错误。我可以用任何其他项目运行黄瓜,这很好。

  • 如果我在终端中运行rake任务,它会运行/home/username/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec ...many *_spec.rb files,但由于上述错误而失败。

编辑:按照建议增加了一些输出。

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

我能够解决此错误的唯一方法是将所有数据库配置从trust放到md5并创建一个新的postgres用户,其名称与我在Ubuntu上的登录名相同

不是一个很好的解决方案,我承认,但它已经成功了。因为我没有将我的数据库用于除了开发之外的任何东西。