簡體   English   中英

AWS Redshift可以刪除包含在事務中的表嗎?

[英]Can AWS Redshift drop a table that is wrapped in transaction?

在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;

如果這很重要,則SQL命令由AWS Data Pipeline執行。

但是,管道有時會失敗並出現以下錯誤:

    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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM