Joh*_*hir 6 postgresql ruby-on-rails database-migration
我想statement_timeout为单独的迁移设置 postgres。我似乎无法做到这一点。这是我的实验:
def change
execute <<~SQL
SET LOCAL statement_timeout = 1; -- ms
-- this does not cause a timeout which is expected, because pg
-- only applies the timeout to the next protocol message / statement,
-- and rails sends everthing inside execute in the same statement
select pg_sleep(1); -- seconds
SQL
# if uncommented, this DOES cause a timeout, which is expected
# execute <<~SQL
# select pg_sleep(1); -- seconds
# SQL
# this does not cause a timeout, which is unexpected
remove_column :foos, :bar
# we do get here, which is unexpected
raise "we finished"
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
打开log_duration并进行更多调查后,我想我得出的结论是,postgres 不会考虑删除该列以花费超过 1 毫秒,即使记录了如下内容:
statement: ALTER TABLE "foos" DROP COLUMN "bar"
duration: 1.171 ms
duration: 0.068 ms
duration: 0.328 ms
Run Code Online (Sandbox Code Playgroud)
但是按照下面的食谱,
statement: ALTER TABLE "foos" DROP COLUMN "bar"
duration: 1.171 ms
duration: 0.068 ms
duration: 0.328 ms
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4920 次 |
| 最近记录: |