改变表格时遇到僵局
我在包含大量行的表上的Rails应用程序中运行以下迁移:
rake db:migrate *** [] rake aborted! *** [] An error has occurred, this and all later migrations canceled: *** [] *** [] PG::Error: ERROR: deadlock detected *** [] DETAIL: Process 33319 waits for AccessExclusiveLock on relation 18486 of database 16948; blocked by process 29772. *** [] Process 29772 waits for ShareLock on transaction 8652; blocked by process 33319. *** [] HINT: See server log for query details. *** [] : ALTER TABLE "topics" DROP "most_recent_post_id" *** [] *** [] Tasks: TOP => db:migrate *** [] (See full trace by running task with --trace) ** [] == RemoveMostRecentPostsColumnsOnTopics: migrating ** [] Updated 56875150 rows out of 568715 tries ** [] -- remove_column(:topics, :most_recent_post_id)
运行的代码是这样的:
def self.up rows_updated = 0 rows_tried = 0 Topic.find(:all).each do |topic| rows_tried += 1 rows_updated += 1 if topic.update_attribute :updated_at, topic.most_recent_post_created_at end puts "Updated #{rows_updated} rows out of #{rows_tried} tries" remove_column :topics, :most_recent_post_id remove_column :topics, :most_recent_post_created_at end
然后我尝试将其作为显式锁,但在搜索有关问题的信息时,我意识到ALTER TABLE已经使用ACCESS EXCLUSIVE锁锁定表,根据这个: http : //www.postgresql.org/docs /9.1/static/explicit-locking.html
我可以做些什么来完成我的更改?
您有两个进程尝试获得独占访问权限:
Process 33319 waits for AccessExclusiveLock on relation 18486 of database 16948; blocked by process 29772. Process 29772 waits for ShareLock on transaction 8652; blocked by process 33319.
其中之一是您的迁移任务。 我假设另一个是你的服务器。 我建议:
- 如果您正在运行开发环境,请退出服务器,运行迁移并重新启动服务器。
- 如果您正在运行生产环境并且需要运行期望经常运行迁移,则可以将#migrate方法添加到服务器应用程序,以便它在同一进程中运行。
(老实说,我刚开始在多处理环境中深入研究PostgreSQL – 如果我了解更多,我会发布一个更好的答案。)
- Gem Load Error是:未定义的方法`type_cast_from_database’用于类`ArJdbc :: MSSQL :: UUIDType’
- 当form_for使用符号时,fields_for不起作用
- rails migration:postgresql for md5 of random string as default
- 有没有办法将Rails默认时间戳更改为Ymd H:i:s(而不是Ymd H:i:su)或laravel忽略Ymd H的小数部分:i:su?
- 用于生产的Rails性能调优?
- 在ruby / ActiveRecord中生成类似Instagram或Youtube的不可语句字符串ID
- 我如何计算Rails中工作表中的总票数
- Ruby中DateTime的毫秒分辨率
- 为什么此ActiveRecord语句在Server中失败但在Console中失败
- Rails无法登录postgresql – PG ::错误 – 密码 – 正确的信息
- 如何修复PG :: DuplicatePstatement:ERROR?