STL_LOAD_ERRORS - Amazon Redshift

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

STL_LOAD_ERRORS

顯示所有 Amazon Redshift 載入錯誤的記錄。

STL_LOAD_ERRORS 包含所有 Amazon Redshift 載入錯誤的歷史記錄。如需可能載入錯誤和說明的完整清單,請參閱載入錯誤參考

在您查詢 STL_LOAD_ERRORS 以了解有關錯誤的一般資訊之後,查詢 STL_LOADERROR_DETAIL 以取得其他詳細資訊,例如發生剖析錯誤的確切資料列和欄。

所有使用者都可看見 STL_LOAD_ERROR。超級使用者可以看見所有資料列;一般使用者只能看見自己的資料。如需詳細資訊,請參閱 系統資料表和檢視中資料的可見性

注意

STL_LOAD_ERRORS 僅包含在主叢集上執行的查詢。但不包含在並行擴縮叢集上執行的查詢。若要存取在主要和並行擴縮叢集上執行的查詢,建議您使用 SYS 監視檢視 SYS_LOAD_ERROR_DETAIL。SYS 監視檢視中的資料會格式化為更易於使用和理解。

資料表欄

欄名稱 資料類型 描述
userid integer 產生項目的使用者之 ID。
分割 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 如果值為 true (1),則表示輸入檔在 COPY 操作期間被分割為多個範圍。如果此值為 false (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