可以通过查询数据字典视图DBA_DATA_FILES和DBA_FREE_SPACE获取Oracle数据库大小。
查询Oracle数据库大小的方法如下:
1、使用SQL语句查询表空间大小
查询所有表空间的大小:
```sql
SELECT tablespace_name, SUM(bytes) / 1024 / 1024 "Size (MB)"
FROM dba_data_files
GROUP BY tablespace_name;
```
查询指定表空间的大小:
```sql
SELECT tablespace_name, SUM(bytes) / 1024 / 1024 "Size (MB)"
FROM dba_data_files
WHERE tablespace_name = 'YOUR_TABLESPACE_NAME'
GROUP BY tablespace_name;
```
查询用户下所有表空间的大小:
```sql
SELECT owner, tablespace_name, SUM(bytes) / 1024 / 1024 "Size (MB)"
FROM dba_segments
WHERE segment_type = 'TABLE' AND owner = 'YOUR_USERNAME'
GROUP BY owner, tablespace_name;
```
2、使用数据字典视图查询表空间大小
查询所有表空间的大小:
```sql
SELECT tablespace_name, sum(bytes)/1024/1024 "Size (MB)"
FROM dba_data_files
GROUP BY tablespace_name;
```
查询指定表空间的大小:
```sql
SELECT tablespace_name, sum(bytes)/1024/1024 "Size (MB)"
FROM dba_data_files
WHERE tablespace_name = 'YOUR_TABLESPACE_NAME'
GROUP BY tablespace_name;
```
查询用户下所有表空间的大小:
```sql
SELECT owner, tablespace_name, sum(bytes)/1024/1024 "Size (MB)"
FROM dba_segments
WHERE segment_type = 'TABLE' AND owner = 'YOUR_USERNAME'
GROUP BY owner, tablespace_name;
```
3、使用SQL*Plus命令查询表空间大小
查询所有表空间的大小:
```sql
COLUMN size format 999,999 heading "Size (MB)" FORMAT A80;
SELECT tablespace_name, sum(bytes)/1024/1024 "Size (MB)" FROM dba_data_files GROUP BY tablespace_name;
```
查询指定表空间的大小:
```sql
COLUMN size format 999,999 heading "Size (MB)" FORMAT A80;
SELECT tablespace_name, sum(bytes)/1024/1024 "Size (MB)" FROM dba_data_files WHERE tablespace_name = 'YOUR_TABLESPACE_NAME' GROUP BY tablespace_name;
```
查询用户下所有表空间的大小:
```sql
COLUMN size format 999,999 heading "Size (MB)" FORMAT A80;
SELECT owner, tablespace_name, sum(bytes)/1024/1024 "Size (MB)" FROM dba_segments WHERE segment_type = 'TABLE' AND owner = 'YOUR_USERNAME' GROUP BY owner, tablespace_name;
```
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/506903.html