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命令之後或之前? –