在ETL期间,我们执行以下操作:

    begin transaction;

    drop table if exists target_tmp;
    create table target_tmp like target;

    insert into target_tmp select * from source_a inner join source_b on ...;
    analyze table target_tmp;

    drop table target;
    alter table target_tmp rename to target;

    commit;

如果这很重要,则由AWS Data Pipeline执行SQL命令。

但是,管道有时会失败,并显示以下错误:
    ERROR: table 111566 dropped by concurrent transaction

Redshift支持可序列化的隔离。这些命令之一会中断隔离吗?

最佳答案

是的,这是可行的,但是如果生成临时表需要花费一些时间,则可以预期该错误在运行时会在其他查询中看到该错误。您可以尝试在单独的事务中生成临时表(除非担心源表的更新,否则可能不需要进行事务处理)。然后快速旋转表名,以减少争用时间:

-- generate target_tmp first then
begin;
alter table target rename to target_old;
alter table target_tmp rename to target;
commit;
drop table target_old;

关于sql - AWS Redshift能否删除包装在事务中的表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42297723/

10-11 07:24
查看更多