Har*_*tty 8 ruby activerecord ruby-on-rails puma
偶尔我们PG::UndefinedTable在使用ActiveRecord时会出错.关联表名称是一些损坏的方式,我经常看到
Cancelled附加到表名的末尾.
例如:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "fooCancell" does not exist
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "Cancelled" does not exist
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "barC" does not exist
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我使用foo和模糊了表名bar.
当rails项目在Puma中运行时,我们会看到这个错误.队列工作人员似乎做得很好.
错误消息中的表与实际表或模型不对应.看起来像是内存损坏的情况.有没有人见过这样的问题?如果是这样,你是如何解决它的?
on_worker_boot do
ActiveRecord::Base.establish_connection
end
Run Code Online (Sandbox Code Playgroud)
production:
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV['DB_CONNECTION_POOL_SIZE'] || 5%>
reaping_frequency: <%= ENV['DB_CONNECTION_REAPING_FREQUENCY'] || 10 %>
prepared_statements: false
Run Code Online (Sandbox Code Playgroud)
基于这个可能相关的错误,我在这里冒险猜测......
但你可能是:
fork;或者其中任何一个都会破坏 ActiveRecord 的同步并导致多个进程共享数据库连接池而不同步其使用(导致交错和损坏的数据库命令)。
如果您使用的是fork,请确保关闭所有 ActiveRecord 数据库连接并重新初始化连接池(有一个函数调用可以执行此操作,但我不记得了,也许ActiveRecord.disconnect!是 或ActiveRecord.connection_pool.disconnect!)。
否则,在运行 Puma 之前(无论是在初始化过程中还是使用 Puma 的after_fork),请关闭所有 ActiveRecord 数据库连接并重新初始化连接池。
| 归档时间: |
|
| 查看次数: |
240 次 |
| 最近记录: |