

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://www.amazonaws.cn/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# SYS\_LOAD\_HISTORY
<a name="SYS_LOAD_HISTORY"></a>

使用 SYS\_LOAD\_HISTORY 查看 COPY 命令的详细信息。每行代表一个 COPY 命令，其中包含某些字段的累积统计数据。它包含正在运行和已完成的 COPY 命令。

SYS\_LOAD\_HISTORY 对所有用户可见。超级用户可以查看所有行；普通用户只能查看其自己的数据。有关更多信息，请参阅 [系统表和视图中的数据可见性](cm_chap_system-tables.md#c_visibility-of-data)。

## 表列
<a name="SYS_LOAD_HISTORY-table-columns"></a>


| 列名称  | 数据类型  | 描述  | 
| --- | --- | --- | 
| user\_id | integer | 提交副本用户的标识符。 | 
| query\_id | bigint | 副本的查询标识符。 | 
| transaction\_id | bigint | 事务标识符。 | 
| session\_id | integer | 运行副本的进程的进程标识符。 | 
| database\_name | 文本 | 在发起操作时用户连接到其中的数据库的名称。 | 
| status | 文本 | 副本的状态。有效值为 running、completed、aborted。 | 
| table\_name | 文本 | 复制到其中的表名称。 | 
| start\_time | timestamp | 复制开始的时间。 | 
| end\_time | timestamp | 复制完成的时间。 | 
| duration | bigint | 在 COPY 命令中花费的时间（微秒）。 | 
| data\_source | 文本 | 要复制的文件输入的 Amazon S3 位置。 | 
| file\_format | 文本 | 源文件格式。格式包括 csv、txt、json、avro、orc 或 parquet。 | 
| Loaded\_rows | bigint | 复制到表的行数。 | 
| Loaded\_bytes | bigint | 复制到表的字节数。 | 
| source\_file\_count | integer | 源文件中的文件数目。 | 
| source\_file\_bytes | bigint | 源文件中的字节数。 | 
| file\_count\_scanned | 整数 | 从 Amazon S3 中扫描到的文件的数量。 | 
| file\_bytes\_scanned | bigint | 从 Amazon S3 内的文件中扫描到的字节数。 | 
| error\_count | bigint | 错误计数。 | 
| copy\_job\_id  | bigint  | 复制作业标识符。0 表示没有作业标识符。 | 

## 示例查询
<a name="SYS_LOAD_HISTORY-sample-queries"></a>

以下查询显示了特定复制命令的加载行、字节、表和数据源。

```
SELECT query_id,
       table_name,
       data_source,
       loaded_rows,
       loaded_bytes
FROM sys_load_history
WHERE query_id IN (6389,490791,441663,74374,72297)
ORDER BY query_id,
         data_source DESC;
```

示例输出。

```
 query_id |    table_name    |                               data_source                             | loaded_rows | loaded_bytes
----------+------------------+-----------------------------------------------------------------------+-------------+---------------
     6389 | store_returns    | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/store_returns/    |   287999764 | 1196240296158
    72297 | web_site         | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/web_site/         |          54 |         43808
    74374 | ship_mode        | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/ship_mode/        |          20 |          1320
   441663 | income_band      | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/income_band/      |          20 |          2152
   490791 | customer_address | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/customer_address/ |     6000000 |     722924305
```

以下查询显示了复制命令的加载行、字节、表和数据源。

```
SELECT query_id,
       table_name,
       data_source,
       loaded_rows,
       loaded_bytes
FROM sys_load_history
ORDER BY query_id DESC
LIMIT 10;
```

示例输出。

```
 query_id |       table_name       |                                 data_source                                 | loaded_rows |  loaded_bytes
----------+------------------------+-----------------------------------------------------------------------------+-------------+-----------------
   491058 | web_site               | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/web_site/               |          54 |           43808
   490947 | web_sales              | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/web_sales/              |   720000376 |  22971988122819
   490923 | web_returns            | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/web_returns/            |    71997522 |     96597496325
   490918 | web_page               | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/web_page/               |        3000 |            1320
   490907 | warehouse              | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/warehouse/              |          20 |            1320
   490902 | time_dim               | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/time_dim/               |       86400 |            1320
   490876 | store_sales            | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/store_sales/            |  2879987999 | 151666241887933
   490870 | store_returns          | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/store_returns/          |   287999764 |   1196405607941
   490865 | store                  | s3://load-test/data-sources/tpcds/2.8.0/textfile/1T/store/                  |        1002 |          365507
```

 以下查询显示了复制命令的每日加载行和字节。

```
SELECT date_trunc('day',start_time) AS exec_day,
       SUM(loaded_rows) AS loaded_rows,
       SUM(loaded_bytes) AS loaded_bytes
FROM sys_load_history
GROUP BY exec_day
ORDER BY exec_day DESC;
```

示例输出。

```
      exec_day       | loaded_rows |   loaded_bytes
---------------------+-------------+------------------
 2022-01-20 00:00:00 |  6347386005 |  258329473070606
 2022-01-19 00:00:00 | 19042158015 |  775198502204572
 2022-01-18 00:00:00 | 38084316030 | 1550294469446883
 2022-01-17 00:00:00 | 25389544020 | 1033271084791724
 2022-01-16 00:00:00 | 19042158015 |  775222736252792
 2022-01-15 00:00:00 | 19834245387 |  798122849155598
 2022-01-14 00:00:00 | 75376544688 | 3077040926571384
```