DWS 查看表占用空间大小
时间: 2023-09-01 10:10:52 浏览: 203
在 DWS 中,可以使用以下 SQL 语句查看表占用的空间大小:
```
SELECT
schemaname || '.' || tablename AS TableFullName,
pg_size_pretty(table_size) AS TableSize,
pg_size_pretty(total_size - table_size) AS IndexSize,
pg_size_pretty(total_size) AS TotalSize
FROM (
SELECT
pg_tablespace_size(spcname) AS tablespace_size,
pg_total_relation_size(relid) AS total_size,
pg_indexes_size(relid) AS index_size,
pg_total_relation_size(relid) - pg_indexes_size(relid) AS table_size,
schemaname,
tablename
FROM pg_catalog.pg_statio_user_tables
JOIN pg_catalog.pg_tables ON relname = tablename
JOIN pg_catalog.pg_namespace ON relnamespace = pg_namespace.oid
JOIN pg_catalog.pg_tablespace ON spcname = pg_tablespace.spcname
) AS table_sizes
ORDER BY total_size DESC;
```
这条 SQL 语句会返回一个结果集,其中包含每个表的全名、表占用空间大小、索引占用空间大小和总空间大小(以易读的格式显示)。你可以根据需要修改 SQL 语句中的过滤条件和排序方式。
阅读全文