部署到Heroku,Rails应用程序
我试图将我的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
使用
production:
pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %>
现在你可以上设置配置变量设置连接池的大小Heroku的。例如,如果你想将它设置为10,你可以运行:
$ heroku config:set DB_POOL=10
这并不意味着每个赛道现在有10个打开的连接,而只是说如果需要一个新的连接将直至创建每个Rails进程最多使用10个。
,必须先创建你的数据库:
heroku run rake db:create
此外,还要检查该Heroku的文档有关数据库连接:https://devcenter.heroku.com/articles/concurrency-and-database-connections
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} –
你的项目文件夹下添加procfile?如所述https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server – mrvncaragay
在proc文件下他们说“但我们建议生成一个配置文件”,我发布了 –
这就是不同。你有config/puma.rb,但是你没有'Procfile file'文件包含这一行'web:bundle exec puma -C config/puma.rb' – mrvncaragay