首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将现有的MySQL rails应用程序转换为使用Postgres:“所有池连接都在使用中”

将现有的MySQL rails应用程序转换为使用Postgres:“所有池连接都在使用中”
EN

Stack Overflow用户
提问于 2019-01-28 01:21:06
回答 1查看 193关注 0票数 2

我正在将一个项目从MySQL转换为PostgreSQL。在配置它之后,当我运行rake db:createrake db:migrate时,我得到错误:ActiveRecord::ConnectionTimeoutError: could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use

我试着把赌注增加到50。同一台机器上的另一个rails项目使用PostgreSQL也很好。你知道会发生什么吗?

完整的堆栈跟踪是:

代码语言:javascript
运行
复制
ActiveRecord::ConnectionTimeoutError: could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in wait_poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `loop'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `wait_poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:154:in `internal_poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:278:in `internal_poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `block in poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:158:in `synchronize'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `poll'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:747:in `acquire_connection'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:500:in `checkout'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `connection'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `retrieve_connection'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_handling.rb:116:in `retrieve_connection'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/connection_handling.rb:88:in `connection'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/schema_migration.rb:20:in `table_exists?'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/schema_migration.rb:24:in `create_table'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/migration.rb:1125:in `initialize'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/migration.rb:1007:in `new'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/migration.rb:1007:in `up'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/migration.rb:985:in `migrate'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/activerecord-5.1.6.1/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/bin/ruby_executable_hooks:24:in `eval'
/Users/tonyporteous/.rvm/gems/ruby-2.5.3@citydash/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

配置文件部分如下所示:

代码语言:javascript
运行
复制
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: projectx_development

我像这样添加了gem:

代码语言:javascript
运行
复制
gem 'pg', '>= 0.18', '< 2.0'
EN

Stack Overflow用户

发布于 2019-01-28 01:42:06

问题已解决:由database.yml文件中的错误引起:

代码语言:javascript
运行
复制
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

应该是

代码语言:javascript
运行
复制
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

这(我猜)导致了池大小为0的抽出。

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54390819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档