【发布时间】:2019-05-21 08:36:45
【问题描述】:
我的用例是从 x 个 Lambda 函数中以增量方式实时提取、转换和加载数据。我希望多个 Lambda 函数能够同时运行,并且 Redshift 能够为读取查询保持活动状态。
由于 Redshift 不强制执行主键约束,我使用 aws 文档 Merge examples - Example of a merge that replaces existing rows 来强制执行唯一行。当只有 1 个 lambda 函数实例在运行时,此方法可以正常工作。
-- Start a new transaction
begin transaction;
-- Delete any rows from SALES that exist in STAGESALES, because they are updates
-- The join includes a redundant predicate to collocate on the distribution key
-- A filter on saletime enables a range-restricted scan on SALES
delete from sales
using stagesales
where sales.salesid = stagesales.salesid
and sales.listid = stagesales.listid
and sales.saletime > '2008-11-30';
-- Insert all the rows from the staging table into the target table
insert into sales
select * from stagesales;
-- End transaction and commit
end transaction;
-- Drop the staging table
drop table stagesales;
但只要 > 1 个 lambda 函数同时运行并访问同一个表,我就会收到:
"ERROR: 1023 DETAIL: Serializable isolation violation on table in Redshift" when performing operations in a transaction concurrently with another session.
我应该如何修改这个示例以允许它在并发环境中运行?
【问题讨论】:
-
这不是 PostgreSQL 错误消息。我将删除 PostgreSQL 标记,因为似乎没有连接。
标签: aws-lambda amazon-redshift