2017-02-09 7 views
0

私はHerokuホストのpostgresデータベースに接続しようとしていますが、残念ながら「ホスト名をアドレスに変換できませんでした。それに見た後、私は問題リモートからHeroku pgデータベースへの接続エラー:ホスト名をアドレスに変換できません

db_parts = ENV['DATABASE_URL'].split(/\/|:|@/) 
username = db_parts[3] 
password = db_parts[4] 
host = db_parts[5] 
db = db_parts[7] 
に、この解決策を見つけ

C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize': could not 
translate host name "postgres://address_to_db.1.amazonaws.com:5432/ (PG::Connecti 
onBad) 
" to address: Unknown server error 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initializ 
e' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql 
_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new 
_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `che 
ckout_new_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acq 
uire_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `blo 
ck in checkout' 
     from C:/Ruby21-x64/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `che 
ckout' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `blo 
ck in connection' 
     from C:/Ruby21-x64/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `con 
nection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `ret 
rieve_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/connection_handling.rb:87:in `connection' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:93:in `columns' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/attributes.rb:98:in `columns_hash' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:64:in `block in valid?' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:64:in `each' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:64:in `all?' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:64:in `valid?' 
     from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activerecord-4.2.7.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing' 

:establish_connectionブロックに示されているように私は直接、エラーのトレースがある

ActiveRecord::Base.establish_connection(
    :adapter => "postgresql", 
    :host  => `heroku config:get DATABASE_URL -amy_app`, 
    :database => "my_db", 
    :username  => "postgres", 
    :password => "password") 

下にHerokuのからDATABASE_URLを取ります

から:Can't connect to PostgreSQL database on Heroku using Ruby - could not translate host name

私はこれを行うNoDatabaseErrorを受け取る。私は手動でdb nameを何も成功せずに入力しました。これがデータベースを見つけることができたかどうかは、私にとっては不明です。

これを解決する方法はありますか?どんな助けでも大歓迎です。

編集:私はheroku config:get DATABASE_URL -amy_appを実行して、事前接続URL「接続情報」を個々のフィールドに手動で読み込んで接続することができませんでした。ルビシステムコールによってリクエストが行われたときに、a)URLだけが返される理由は不明です。 b)splitメソッドを使用していない理由

Tl; dr:Herokuのドキュメントでは、アプリケーションのデータベースにリモートで接続する方法や、少なくともドキュメントが完全なDATABASE_URLであることを示しています。

おかげで、 SOliver

答えて

0

データベースが実際にあるかどうかを確認する(PSequelのような)GUIクライアントを使用してサーバーに接続してみてください。 そうでない場合は、

bundle exec rake db:create 
bundle exec rake db:migrate 
+0

お返事ありがとうございます。私は 'heroku pg:psql'を使ってデータベースに接続することができ、アプリケーション自体がデータベースに接続します。 – CBusBus

+0

だから、あなたは "heroku run rake db:migrate"をやったとします。あなたはもう一度やって、出力が何であるか見ることができますか? –

+1

待機中の移行はありません。数日前に実行され、すべて正常に処理されました。私は手動でheroku configの "connection information"セクションを分割しました:DATABASE_URLを取得すると、今接続しているようです。 Herokuのドキュメントではこれについて説明していないので、私はそれらを電子メールで送信します。うまくいけば、ユーザーにURLを分割する必要があることを伝えることができます。 – CBusBus

関連する問題