获取有关 Redshift `stl_load_errors` 错误的 table 信息
Getting table information for Redshift `stl_load_errors` errors
我正在使用 Redshift COPY 命令将数据从 S3 加载到 Redshift table。当出现问题时,我通常会收到错误 ERROR: Load into table 'example' failed. Check 'stl_load_errors' system table for details
。我总是可以手动查找 stl_load_errors
以获取详细信息。现在,我想弄清楚如何自动执行此操作。
从 documentation 看来,以下查询应该可以提供我需要的所有详细信息:
SELECT *
FROM stl_load_errors errors
INNER JOIN svv_table_info info
ON errors.tbl = info.table_id
AND info.schema = '<schema-name>'
AND info.table = '<table-name>'
然而它总是returns什么都没有。我也尝试使用 stv_tbl_perm
而不是 svv_table_info
,但仍然没有。
经过一些故障排除后,我发现有两点我不明白:
- 我在
stv_tbl_perm
和 svv_table_info
中看到多个不同的 ID 完全相同 table。这是为什么?
- 我看到在
stl_load_errors
上提交的 tbl
引用了 stv_tbl_perm
或 svv_table_info
中不存在的 ID。又是为什么?
感觉我不理解这些 table 的结构,但它完全让我逃避了什么。
这是因为tbl和table_id的类型不同。第一个是整数,第二个是iod.
当您将 iod 转换为整数时,各列具有相同的值。您可以查看此查询:
SELECT table_id::integer, table_id
FROM SVV_TABLE_INFO
我执行就有结果了
SELECT errors.tbl, info.table_id::integer, info.table_id, *
FROM stl_load_errors errors
INNER JOIN svv_table_info info
ON errors.tbl = info.table_id
请注意内部联接是 ON errors.tbl = info.table_id
您可以尝试按文件名查找。并没有真正回答有关加入各种表的问题,但我使用这样的查询将属于同一清单文件的文件分组,并让我将其与 maxerror
设置进行比较:
select min(starttime) over (partition by substring(filename, 1, 53)) as starttime,
substring(filename, 1, 53) as filename, btrim(err_reason) as err_reason, count(*)
from stl_load_errors where filename like '%/some_s3_path/%'
group by starttime, filename, err_reason order by starttime desc;
这对我有用,没有任何转换:
schemaz=# select i.database, e.err_code from stl_load_errors e join svv_table_info i on e.tbl=i.table_id limit 5
schemaz-# ;
database | err_code
-----------+----------
schemaz | 1204
schemaz | 1204
schemaz | 1204
schemaz | 1204
schemaz | 1204
我终于弄明白了,它出奇的无聊而且可能对很多人没有用......
我有一个现有的 table。我创建 table 的代码被包裹在交易中,并且它在交易中删除了 table 。查询 stl_load_errors
的代码在事务之外。因此 table_id
外部和内部事务不同,因为它是不同的 table。
我正在使用 Redshift COPY 命令将数据从 S3 加载到 Redshift table。当出现问题时,我通常会收到错误 ERROR: Load into table 'example' failed. Check 'stl_load_errors' system table for details
。我总是可以手动查找 stl_load_errors
以获取详细信息。现在,我想弄清楚如何自动执行此操作。
从 documentation 看来,以下查询应该可以提供我需要的所有详细信息:
SELECT *
FROM stl_load_errors errors
INNER JOIN svv_table_info info
ON errors.tbl = info.table_id
AND info.schema = '<schema-name>'
AND info.table = '<table-name>'
然而它总是returns什么都没有。我也尝试使用 stv_tbl_perm
而不是 svv_table_info
,但仍然没有。
经过一些故障排除后,我发现有两点我不明白:
- 我在
stv_tbl_perm
和svv_table_info
中看到多个不同的 ID 完全相同 table。这是为什么? - 我看到在
stl_load_errors
上提交的tbl
引用了stv_tbl_perm
或svv_table_info
中不存在的 ID。又是为什么?
感觉我不理解这些 table 的结构,但它完全让我逃避了什么。
这是因为tbl和table_id的类型不同。第一个是整数,第二个是iod.
当您将 iod 转换为整数时,各列具有相同的值。您可以查看此查询:
SELECT table_id::integer, table_id
FROM SVV_TABLE_INFO
我执行就有结果了
SELECT errors.tbl, info.table_id::integer, info.table_id, *
FROM stl_load_errors errors
INNER JOIN svv_table_info info
ON errors.tbl = info.table_id
请注意内部联接是 ON errors.tbl = info.table_id
您可以尝试按文件名查找。并没有真正回答有关加入各种表的问题,但我使用这样的查询将属于同一清单文件的文件分组,并让我将其与 maxerror
设置进行比较:
select min(starttime) over (partition by substring(filename, 1, 53)) as starttime,
substring(filename, 1, 53) as filename, btrim(err_reason) as err_reason, count(*)
from stl_load_errors where filename like '%/some_s3_path/%'
group by starttime, filename, err_reason order by starttime desc;
这对我有用,没有任何转换:
schemaz=# select i.database, e.err_code from stl_load_errors e join svv_table_info i on e.tbl=i.table_id limit 5
schemaz-# ;
database | err_code
-----------+----------
schemaz | 1204
schemaz | 1204
schemaz | 1204
schemaz | 1204
schemaz | 1204
我终于弄明白了,它出奇的无聊而且可能对很多人没有用......
我有一个现有的 table。我创建 table 的代码被包裹在交易中,并且它在交易中删除了 table 。查询 stl_load_errors
的代码在事务之外。因此 table_id
外部和内部事务不同,因为它是不同的 table。