STL_LOAD_ERRORS - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

STL_LOAD_ERRORS

显示所有 Amazon Redshift 加载错误的记录。

STL_LOAD_ERRORS 包含所有 Amazon Redshift 加载错误的历史记录。有关可能的加载错误和说明的全面列表,请参阅加载错误参考

在您查询 STL_LOAD_ERRORS 以了解有关错误的一般信息后,可查询 STL_LOADERROR_DETAIL 以获取其他详细信息,如发生解析错误的准确的数据行和列。

STL_LOAD_ERRORS 对所有用户可见。超级用户可以查看所有行;普通用户只能查看其自己的数据。有关更多信息,请参阅系统表和视图中的数据可见性

注意

STL_LOAD_ERRORS 仅包含在主集群上运行的查询。它不包含在并发扩展集群上运行的查询。要访问在主集群和并发扩展集群上运行的查询,我们建议您使用 SYS 监控视图 SYS_LOAD_ERROR_DETAIL。SYS 监控视图中的数据经过格式化处理,便于使用和理解。

表列

列名称 数据类型 描述
userid integer 生成该条目的用户 ID。
slice integer 发生错误的切片。
tbl integer 表 ID。
starttime timestamp 加载的开始时间(采用 UTC 表示)。
session integer 执行加载的会话的会话 ID。
query integer 查询 ID。查询列可用于连接其他系统表和视图。
filename character(256) 加载的输入文件的完整路径。
line_number bigint 加载文件中的错误所在的行号。对于 JSON 中的 COPY,这是存在错误的 JSON 对象的最后一行的行号。
colname character(127) 存在错误的字段。
type character(10) 字段的数据类型。
col_length character(10) 列长度(如果适用)。当数据类型具有限制长度时填充此字段。例如,对于数据类型为“character(3)”的列,此列将包含值“3”。
position integer 字段中的错误的位置。
raw_line character(1024) 包含错误的原始加载数据。加载数据中的多字节字符替换为句点。
raw_field_value char(1024) 字段“colname”的预解析值,可导致解析错误。
err_code integer 错误代码。
err_reason character(100) 有关错误的说明。
is_partial integer 值,如果为真 (1) 表示在 COPY 操作期间输入文件被拆分为范围。如果此值为假 (0),则不会拆分输入文件。
start_offset bigint 值,如果在 COPY 操作期间拆分输入文件,则表示拆分的偏移值(以字节为单位)。如果文件中的行号未知,则行号为 -1。如果文件未拆分,则此值为 0。
copy_job_id bigint 复制作业标识符。0 表示没有作业标识符。

示例查询

以下查询将 STL_LOAD_ERRORS 联接到 STL_LOADERROR_DETAIL 以查看最近加载期间发生的错误的详细信息。

select d.query, substring(d.filename,14,20), d.line_number as line, substring(d.value,1,16) as value, substring(le.err_reason,1,48) as err_reason from stl_loaderror_detail d, stl_load_errors le where d.query = le.query and d.query = pg_last_copy_id(); query | substring | line | value | err_reason -------+-------------------+------+----------+---------------------------- 558| allusers_pipe.txt | 251 | 251 | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | ZRU29FGR | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | Kaitlin | String contains invalid or unsupported UTF8 code 558| allusers_pipe.txt | 251 | Walter | String contains invalid or unsupported UTF8 code

以下示例结合使用 STL_LOAD_ERRORS 和 STV_TBL_PERM 来创建新视图,然后使用该视图来确定在将数据加载到 EVENT 表中时发生的错误:

create view loadview as (select distinct tbl, trim(name) as table_name, query, starttime, trim(filename) as input, line_number, colname, err_code, trim(err_reason) as reason from stl_load_errors sl, stv_tbl_perm sp where sl.tbl = sp.id);

接下来,以下查询实际返回在加载 EVENT 表时发生的最后一个错误:

select table_name, query, line_number, colname, starttime, trim(reason) as error from loadview where table_name ='event' order by line_number limit 1;

查询返回 EVENT 表发生的最后一个加载错误。如果未发生任何加载错误,则查询返回零行。在此示例中,查询返回一个错误:

table_name | query | line_number | colname | error | starttime ------+-----+----+----+--------------------------------------------------------+---------------------- event | 309 | 0 | 5 | Error in Timestamp value or format [%Y-%m-%d %H:%M:%S] | 2014-04-22 15:12:44 (1 row)

在 COPY 命令自动拆分大的、未压缩的、以文本分隔的文件数据以促进并行化的情况下,line_numberis_partialstart_offset 列显示与拆分有关的信息。(在原始文件中行号不可用的情况下,行号可能是未知的。)

--scan ranges information SELECT line_number, POSITION, btrim(raw_line), btrim(raw_field_value), btrim(err_reason), is_partial, start_offset FROM stl_load_errors WHERE query = pg_last_copy_id(); --result -1,51,"1008771|13463413|463414|2|28.00|38520.72|0.06|0.07|NO|1998-08-30|1998-09-25|1998-09-04|TAKE BACK RETURN|RAIL|ans cajole sly","NO","Char length exceeds DDL length",1,67108864