2016-07-15 179 views
0

我試圖將我的rails應用程序部署到heroku。該應用程序已上傳,但由於某種原因無法正常運行。當我鍵入部署到Heroku,Rails應用程序

heroku run rake db:migrate

我得到一個錯誤說

ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)

我使用PUMA的服務器,我會發布一些文件,這些文件可能會導致問題...請詢問任何可能會導致此錯誤!

配置/ database.ymi

production: 
    adapter: postgresql 
    host:  localhost 
    encoding: unicode 
    database: FastOrder_production 
    pool:  5 
    username: <%= ENV['FASTORDER_DATABASE_USER'] %> 
    password: <%= ENV['FASTORDER_DATABASE_PASSWORD'] %> 
    template: template0 
    url: <%= ENV["DATABASE_URL"] %> 
    pool: ENV['RAILS_MAX_THREADS'] 

配置/ puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2) 
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) 
threads threads_count, threads_count 

preload_app! 

rackup  DefaultRackup 
port  ENV['PORT']  || 3000 
environment ENV['RACK_ENV'] || 'development' 

on_worker_boot do 
    # Worker specific setup for Rails 4.1+ 
    # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot 
    ActiveRecord::Base.establish_connection 
end 
+0

你的項目文件夾下添加procfile?如所述https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server – mrvncaragay

+0

在proc文件下他們說「但我們建議生成一個配置文件」,我發佈了 –

+0

這就是不同。你有config/puma.rb,但是你沒有'Procfile file'文件包含這一行'web:bundle exec puma -C config/puma.rb' – mrvncaragay

回答

0

使用

production: 

pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %> 

現在你可以上設置配置變量設置連接池的大小Heroku的。例如,如果你想將它設置爲10,你可以運行:

$ heroku config:set DB_POOL=10 

這並不意味着每個賽道現在有10個打開的連接,而只是說如果需要一個新的連接將直至創建每個Rails進程最多使用10個。

0

,必須先創建你的數據庫:

heroku run rake db:create 

此外,還要檢查該Heroku的文檔有關數據庫連接:https://devcenter.heroku.com/articles/concurrency-and-database-connections

+0

This導致相同的錯誤「無法在5.000秒內獲得數據庫連接(等待5.000秒)」。無法爲{「adapter」=>「postgresql」,「host」=>「ec2-52-273-201-84.compute-1.amazonaws.com」,「encoding」=>「unicode」創建數據庫, 「database」=>「dej0vekqovntg」,「pool」=>「ENV ['RAILS_MAX_THREADS']」,「username」=>「fluwgnxblabla」,「password」=>「blablabla」,「template」=>「template0」, 「端口」=> 5432} –