1

期间,我们做以下操作的ETL:AWS Redshift可以删除包含在事务中的表吗?

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; 

的SQL命令由AWS数据管道进行的,如果这是非常重要的。

然而,管道有时会失败,出现以下错误:

ERROR: table 111566 dropped by concurrent transaction 

红移支持串行化隔离。其中一个命令是否会破坏隔离?

回答

0

是的,但如果生成临时表需要一段时间,您可以期望在运行时看到其他查询的错误。您可以尝试在单独的事务中生成临时表(除非担心源表的更新,否则可能不需要事务)。然后快速旋转表名,以便争用的时间少得多:

-- 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; 
+0

Thaks,我听从了你的建议,并且在一段时间内没有看到错误。我仍然不确定我遇到的行为是不是bug。 –

+1

由于只有当前会话将达到target_old表。知道为什么它很重要,如果drop table命令在commit命令之后或之前? –