写一条oracle 查看表空间使用情况
时间: 2023-10-24 12:33:04 浏览: 42
这是我刚才回答过的问题,以下是同样的回答:
你可以使用以下 SQL 查询 Oracle 数据库中表空间的使用情况:
```sql
SELECT tablespace_name,
ROUND(SUM(bytes) / 1024 / 1024, 2) total_size_mb,
ROUND(SUM(bytes - NVL(free_space, 0)) / 1024 / 1024, 2) used_size_mb,
ROUND(NVL(SUM(free_space), 0) / 1024 / 1024, 2) free_size_mb,
ROUND((SUM(bytes - NVL(free_space, 0)) / SUM(bytes)) * 100, 2) pct_used
FROM (SELECT tablespace_name,
file_id,
SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name, file_id
UNION ALL
SELECT tablespace_name,
file_id,
SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name, file_id
UNION ALL
SELECT tablespace_name,
MIN(file_id) file_id,
SUM(bytes) bytes
FROM sys.v_$backup_datafile
GROUP BY tablespace_name)
LEFT OUTER JOIN (SELECT tablespace_name,
file_id,
SUM(bytes) free_space
FROM dba_free_space
GROUP BY tablespace_name, file_id) ON file_id = file_id AND tablespace_name = tablespace_name
GROUP BY tablespace_name
ORDER BY tablespace_name;
```
这个 SQL 查询语句将返回表空间名称、总大小、已使用大小、可用大小以及已使用百分比等信息。