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

STV_TBL_PERM

STV_TBL_PERM 表包含有关 Amazon Redshift 中永久表的信息,其中包括用户为当前会话创建的临时表。STV_TBL_PERM 包含所有数据库中的所有表的信息。

此表不同于 STV_TBL_TRANS,后者包含有关系统在查询处理期间创建的临时数据库表的信息。

STV_TBL_PERM 仅对超级用户可见。有关更多信息,请参阅系统表和视图中的数据可见性

表列

列名称 数据类型 描述
slice integer 分配到表的节点分片。
id integer 表 ID。
名称 character(72) 表名称。
rows bigint 分片中的数据行数。
sorted_rows bigint 已在磁盘上排序的分片中行的数目。如果此数目与 ROWS 数目不符,则真空化表以重新排序行。
temp integer 该表是否为临时表。0 = false;1 = true。
db_id integer 表创建于的数据库的 ID。
insert_pristine integer 供内部使用。
delete_pristine integer 供内部使用。
backup integer 指示表是否包含在集群快照中的值。0 = no;1 = yes。有关更多信息,请参阅 CREATE TABLE 命令的 BACKUP 参数。
dist_style 整数 切片所属表的分布方式。有关值的更多信息,请参阅查看分配方式。有关分布方式的更多信息,请参阅分配方式
block_count 整数 切片使用的数据块数。在无法计算数据块数时,该值为 -1。

示例查询

以下查询返回不同表 ID 和名称的列表:

select distinct id, name from stv_tbl_perm order by name; id | name --------+------------------------- 100571 | category 100575 | date 100580 | event 100596 | listing 100003 | padb_config_harvest 100612 | sales ...

其他系统表使用表 ID,因此知道特定表对应于哪个表 ID 会非常有用。在此示例中,SELECT DISTINCT 用于删除重复项(表分布在多个分片中)。

要确定 VENUE 表中每一列所使用的块数,请键入以下查询:

select col, count(*) from stv_blocklist, stv_tbl_perm where stv_blocklist.tbl = stv_tbl_perm.id and stv_blocklist.slice = stv_tbl_perm.slice and stv_tbl_perm.name = 'venue' group by col order by col; col | count -----+------- 0 | 8 1 | 8 2 | 8 3 | 8 4 | 8 5 | 8 6 | 8 7 | 8 (8 rows)

使用说明

ROWS 列包括尚未真空化(或者已真空化但使用 SORT ONLY 选项)的已删除行的计数。因此,当您直接查询给定表时,STV_TBL_PERM 表中的 ROWS 列的 SUM 可能与 COUNT(*) 结果不符。例如,如果从 VENUE 中删除了两行,则 COUNT(*) 结果为 200,但 SUM(ROWS) 结果仍为 202:

delete from venue where venueid in (1,2); select count(*) from venue; count ------- 200 (1 row) select trim(name) tablename, sum(rows) from stv_tbl_perm where name='venue' group by name; tablename | sum -----------+----- venue | 202 (1 row)

要同步 STV_TBL_PERM 中的数据,请对 VENUE 表运行完全真空化。

vacuum venue; select trim(name) tablename, sum(rows) from stv_tbl_perm where name='venue' group by name; tablename | sum -----------+----- venue | 200 (1 row)