

 从补丁 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\_MV\_REFRESH\_HISTORY
<a name="SYS_MV_REFRESH_HISTORY"></a>

结果包括有关所有实体化视图的刷新历史记录的信息。结果包括刷新类型（例如手动或自动）以及最近刷新的状态。

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

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


| 列名称  | 数据类型  | 描述  | 
| --- | --- | --- | 
| user\_id | 整数 | 提交刷新的用户的标识符。 | 
| session\_id | 整数 | 运行实体化视图刷新的进程的进程标识符。 | 
| transaction\_id | bigint | 事务标识符。 | 
| database\_name | char(128) | 包含实体化视图的数据库。 | 
| schema\_name | char(128) | 实体化视图的架构。 | 
| mv\_id | bigint | 实体化视图的对象 ID。 | 
| mv\_name | char(128) | 实体化视图名称。 | 
| refresh\_type | char(32) | 刷新的类型，例如手动或自动。 | 
| status | text | 刷新的状态。有关状态的详细信息，请参阅 [SVL\_MV\_REFRESH\_STATUS](r_SVL_MV_REFRESH_STATUS.md) 的状态列。 | 
| start\_time | timestamp | 刷新的开始时间。 | 
| end\_time | timestamp | 刷新的结束时间。 | 
| duration | bigint | 刷新实体化视图所用的时间（以微秒为单位）。 | 
| consumer\_account | char(12) | 启动刷新的使用者集群的 Amazon 账户 ID。当在数据共享设置中从使用者集群启动刷新时，将填充此字段。 | 
| consumer\_region | char(32) | 启动刷新的使用者集群的 Amazon 区域。当在数据共享设置中从使用者集群启动刷新时，将填充此字段。 | 
| consumer\_namespace | char(36) | 启动刷新的使用者集群的命名空间标识符。当在数据共享设置中从使用者集群启动刷新时，将填充此字段。 | 

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

以下查询显示了实体化视图的刷新历史记录。

```
SELECT user_id, 
     session_id, 
     transaction_id, 
     database_name, 
     schema_name, 
     mv_id, 
     mv_name,
     refresh_type,
     status,
     start_time,
     end_time,
     duration,
     consumer_account,
     consumer_region,
     consumer_namespace
     from sys_mv_refresh_history;
```

查询返回以下示例输出：

```
 user_id | session_id | transaction_id | database_name | schema_name                | mv_id  |  mv_name           |  refresh_type  |  status                                                                                              |  start_time                |  end_time                  |  duration | consumer_account | consumer_region | consumer_namespace
---------+------------+----------------+---------------+----------------------------+--------+--------------------+----------------+------------------------------------------------------------------------------------------------------+----------------------------+----------------------------+-----------+------------------+-----------------+------------------------------------
       1 | 1073815659 |          15066 | dev           | test_stl_mv_refresh_schema | 203762 | mv_incremental     | Manual         | MV was already updated                                                                               | 2023-10-26 15:59:20.952179 | 2023-10-26 15:59:20.952866 |      687 |                  |                 |
       1 | 1073815659 |          15068 | dev           | test_stl_mv_refresh_schema | 203771 | mv_nonincremental  | Manual         | MV was already updated                                                                               | 2023-10-26 15:59:21.008049 | 2023-10-26 15:59:21.008658 |      609 |                  |                 |
       1 | 1073815659 |          15070 | ext_db        | producer_schema            | 203779 | producer_mv        | Manual         | Refresh successfully updated MV incrementally                                                        | 2023-10-26 15:59:21.064252 | 2023-10-26 15:59:21.064885 |      633 | 0123456789       | us-east-1       | 623d8ff2-4391-4381-83d7-177caa6767af
       1 | 1073815659 |          15074 | dev           | test_stl_mv_refresh_schema | 203762 | mv_incremental     | Manual         | Refresh successfully updated MV incrementally                                                        | 2023-10-26 15:59:29.693329 | 2023-10-26 15:59:43.482842 | 13789513 |                  |                 |
       1 | 1073815659 |          15076 | dev           | test_stl_mv_refresh_schema | 203771 | mv_nonincremental  | Manual         | Refresh successfully recomputed MV from scratch                                                      | 2023-10-26 15:59:43.550184 | 2023-10-26 15:59:47.880833 |  4330649 |                  |                 |
       1 | 1073815659 |          15078 | dev           | test_stl_mv_refresh_schema | 203779 | mv_refresh_error   | Manual         | Refresh failed due to an internal error                                                              | 2023-10-26 15:59:47.949052 | 2023-10-26 15:59:52.494681 |  4545629 |                  |                 |
       1 | 1073815659 |          15071 | dev           | test_stl_mv_refresh_schema | 203778 | mv_test            | Manual         | Cascade refresh failed because materialized view test_stl_mv_refresh_schema.child was not refreshed. | 2023-10-26 15:30:21.432252 | 2023-10-26 15:30:21.432252 |      532 |                  |                 |
       1 | 1073815659 |          15071 | dev           | test_stl_mv_refresh_schema | 203761 | child              | Manual         | Refresh failed due to an internal error.                                                             | 2023-10-26 15:30:21.432252 | 2023-10-26 15:30:21.432252 |      532 |                  |                 |
       1 | 1073815659 |          15069 | dev           | test_stl_mv_refresh_schema | 203778 | mv_test            | Manual         | Cascade refresh skipped because materialized view test_stl_mv_refresh_schema.child was not refreshed.| 2023-10-26 15:21:43.550369 | 2023-10-26 15:21:43.550369 |      633
       1 | 1073815659 |          15069 | dev           | test_stl_mv_refresh_schema | 203761 | child              | Manual         | Refresh failed due to an internal error.                                                             | 2023-10-26 15:21:43.550369 | 2023-10-26 15:21:43.550369 |      633
(10 rows)
```