一、查看表空间
--1、查看表空间的名称及大小
SELECT t.tablespace_name,round(SUM(bytes / (1024 * 1024)),0) ts_size
FROM dba_tablespaces t,dba_data_files d
WHERE t.tablespace_name = d.tablespace_name
GROUP BY t.tablespace_name;
SELECT tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024),0) total_space
FROM dba_data_files
ORDER BY tablespace_name;
--3、查看回滚段名称及大小
SELECT segment_name,
tablespace_name,
r.status,
(initial_extent / 1024) initialextent,
(next_extent / 1024) nextextent,
max_extents,
v.curext curextent
FROM dba_rollback_segs r,v$rollstat v
WHERE r.segment_id = v.usn(+)
ORDER BY segment_name;
--4、查看控制文件
SELECT NAME FROM v$controlfile;
--5、查看日志文件
SELECT MEMBER FROM v$logfile;
--6、查看表空间的使用情况
SELECT SUM(bytes) / (1024 * 1024) AS free_space,tablespace_name
FROM dba_free_space
GROUP BY tablespace_name;
SELECT a.tablespace_name,
a.bytes/(1024*1024) total,
b.bytes/(1024*1024) used,
c.bytes/(1024*1024) free,
(b.bytes * 100) / a.bytes "USERATE",
(c.bytes * 100) / a.bytes "FREERATE"
FROM sys.sm$ts_avail a,sys.sm$ts_used b,sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name
order by USERATE desc;
--7、查看数据库库对象
SELECT owner,object_type,status,COUNT(*) count#
FROM all_objects
GROUP BY owner,status;
--8、查看数据库的版本
SELECT version
FROM product_component_version
WHERE substr(product,1,6) = 'Oracle';
--9、查看数据库的创建日期和归档方式
SELECT created,log_mode,log_mode FROM v$database;
--查看表属于哪个表空间
SELECT TABLE_NAME,TABLESPACE_NAME FROM USER_TABLES;
--查询表空间下有哪些表
select * from all_tables where tablespace_name='T_SYS_AUTH_FEATURE_INFO_09'
二、修改表空间大小
2.查看各表空间分配情况。
select tablespace_name,sum(bytes) / 1024 / 1024 from dba_data_files
group by tablespace_name;
3.查看各表空间空闲情况。
select tablespace_name,sum(bytes) / 1024 / 1024 from dba_free_space group by tablespace_name;
4.更改数据表大小(10G)
alter database datafile '/home/oracle/oradata/orcl/undotbs01.dbf' resize 10240m;
5.设置表空间不足时自动增长
5.1查看表空间是否自动增长
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;
5.2 设置表空间自动增长
ALTER DATABASE DATAFILE '/home/oracle/oradata/orcl/undotbs01.dbf' AUTOEXTEND ON;//打开自动增长
ALTER DATABASE DATAFILE '/home/oracle/oradata/orcl/undotbs01.dbf' AUTOEXTEND ON NEXT 200M ;//每次自动增长200m
ALTER DATABASE DATAFILE '/home/oracle/oradata/orcl/undotbs01.dbf' AUTOEXTEND ON NEXT 200M MAXSIZE 1024M;//每次自动增长200m,数据表最大不超过1G
原文链接:https://www.f2er.com/oracle/207720.html