

 从补丁 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/)。

# SVV\_DISKUSAGE
<a name="r_SVV_DISKUSAGE"></a>

Amazon Redshift 通过联接 STV\_TBL\_PERM 和 STV\_BLOCKLIST 表来创建 SVV\_DISKUSAGE 系统视图。SVV\_DISKUSAGE 视图包含数据库中表的数据分配的相关信息。

针对 SVV\_DISKUSAGE 使用聚合查询（如以下示例所示）可确定为每个数据库、表、切片或列分配的磁盘数据块的数目。每个数据块使用 1 MB。您还可以使用 [STV\_PARTITIONS](r_STV_PARTITIONS.md) 查看有关磁盘利用率的摘要信息。

SVV\_DISKUSAGE 仅对超级用户可见。有关更多信息，请参阅 [系统表和视图中的数据可见性](cm_chap_system-tables.md#c_visibility-of-data)。

**注意**  
此视图仅在查询预置集群时可用。

## 表列
<a name="r_SVV_DISKUSAGE-table-rows"></a>


| 列名称  | 数据类型  | 描述  | 
| --- | --- | --- | 
| db\_id  | integer  | 数据库 ID。 | 
| 名称  | character(72)  | 表名称。 | 
| slice  | integer  | 分配到表的数据切片。 | 
| col  | integer  | 列的零基索引。您创建的每个表都附加有以下三个隐藏列：INSERT\_XID、DELETE\_XID 和 ROW\_ID (OID)。包含 3 个用户定义的列的表实际上包含 6 列，用户定义的列在内部编号为 0、1 和 2。在此示例中，INSERT\_XID、DELETE\_XID 和 ROW\_ID 列分别编号为 3、4 和 5。 | 
| tbl  | integer  | 表 ID。 | 
| blocknum  | integer  | 数据块的 ID。 | 
| num\_values  | integer  | 数据块上包含的值的数目。 | 
| minvalue  | bigint  | 数据块上包含的最小值。 | 
| maxvalue  | bigint  | 数据块上包含的最大值。 | 
| sb\_pos  | integer  | 磁盘上超级数据块位置的内部标识符。 | 
| pinned  | integer  | 是否在预加载时将数据块固定到内存中。0 = false；1 = true。默认设置为“假”。 | 
| on\_disk  | integer  | 是否自动在磁盘上存储数据块。0 = false；1 = true。默认设置为“假”。 | 
| modified  | integer  | 是否已修改数据块。0 = false；1 = true。默认设置为“false”。 | 
| hdr\_modified  | integer  | 是否已修改数据块标头。0 = false；1 = true。默认设置为“假”。 | 
| unsorted  | integer  | 数据块是否未排序。0 = false；1 = true。默认为“真”。 | 
| tombstone  | integer  | 供内部使用。 | 
| preferred\_diskno  | integer  | 数据块应该位于的磁盘的编号（除非磁盘已出故障）。磁盘一旦修复，该数据块就将移回到该磁盘。 | 
| temporary  | integer  | 数据块是否包含临时表或中间查询结果等位置的临时数据。0 = false；1 = true。默认设置为“假”。 | 
| newblock  | integer  | 指示数据块是新数据块（真）还是以前从未提交到过磁盘（假）。0 = 假；1 = 真。 | 

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

分配的每个磁盘数据块在 SVV\_DISKUSAGE 中对应一行，因此选择所有行的查询可能会返回非常多的行。建议仅对 SVV\_DISKUSAGE 使用聚合查询。

返回曾经分配到 USERS 表中第 6 列（EMAIL 列）的最大数据块数。

```
select db_id, trim(name) as tablename, max(blocknum)
from svv_diskusage
where name='users' and col=6
group by db_id, name;

db_id  | tablename | max
--------+-----------+-----
175857 | users     |   2
(1 row)
```

对于名为 SALESNEW 的 10 列大型表中的所有列，下面的查询返回相似的结果。（列 10 到 12 的最后三行用于隐藏元数据列。） 

```
select db_id, trim(name) as tablename, col, tbl, max(blocknum)
from svv_diskusage
where name='salesnew'
group by db_id, name, col, tbl
order by db_id, name, col, tbl;

db_id  | tablename  | col |  tbl   | max
--------+------------+-----+--------+-----
175857 | salesnew   |   0 | 187605 | 154
175857 | salesnew   |   1 | 187605 | 154
175857 | salesnew   |   2 | 187605 | 154
175857 | salesnew   |   3 | 187605 | 154
175857 | salesnew   |   4 | 187605 | 154
175857 | salesnew   |   5 | 187605 |  79
175857 | salesnew   |   6 | 187605 |  79
175857 | salesnew   |   7 | 187605 | 302
175857 | salesnew   |   8 | 187605 | 302
175857 | salesnew   |   9 | 187605 | 302
175857 | salesnew   |  10 | 187605 |   3
175857 | salesnew   |  11 | 187605 |   2
175857 | salesnew   |  12 | 187605 | 296
(13 rows)
```