作为IT工程师,以下是几种查看Oracle数据库表空间的常用方法:
SELECT tablespace_name, status, contents, extent_management, allocation_type
FROM dba_tablespaces;
SELECT
df.tablespace_name "表空间名",
df.bytes/1024/1024 "总大小(MB)",
(df.bytes-fs.bytes)/1024/1024 "已使用(MB)",
fs.bytes/1024/1024 "空闲(MB)",
round(100*(df.bytes-fs.bytes)/df.bytes) "使用率(%)"
FROM
(SELECT tablespace_name, sum(bytes) bytes FROM dba_data_files GROUP BY tablespace_name) df,
(SELECT tablespace_name, sum(bytes) bytes FROM dba_free_space GROUP BY tablespace_name) fs
WHERE
df.tablespace_name = fs.tablespace_name;
SELECT
tablespace_name,
bytes_used/1024/1024 "已使用(MB)",
bytes_free/1024/1024 "空闲(MB)"
FROM
v$temp_space_header;
-- 查看表空间和数据文件
SELECT file_name, tablespace_name, bytes/1024/1024 MB, autoextensible, maxbytes/1024/1024 max_MB
FROM dba_data_files
ORDER BY tablespace_name;
-- 查看临时表空间
SELECT file_name, tablespace_name, bytes/1024/1024 MB, status
FROM dba_temp_files;
SELECT
tablespace_name,
sum(bytes)/1024/1024 "空闲空间(MB)"
FROM
dba_free_space
GROUP BY
tablespace_name;
SELECT
tablespace_name,
file_name,
autoextensible,
increment_by*(8192/1024/1024) "增量(MB)",
maxbytes/1024/1024 "最大大小(MB)"
FROM
dba_data_files;
user_tablespaces
和user_free_space
视图代替dba_
开头的视图以上方法可以帮助您全面了解Oracle数据库中表空间的使用情况和配置信息。