Oracle数据库常用指令
查看用户和表空间关系
select username, default_tablespace, temporary_tablespace from dba_users;
查看表空间和文件关系
select tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space from dba_data_files order by tablespace_name;
查看表空间大小
SELECT tablespace_name "表空间名" , bytes total / (1024 * 1024 * 1024) "表空间大小(G)" FROM dba_data_files ;
查看表空间剩余大小
SELECT a.tablespace_name "表空间名", total / (1024 * 1024 * 1024) "表空间大小(G)", free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)", round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free FROM dba_free_space GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total FROM dba_data_files GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name ;
## 修改表空间大小
alter database datafile 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\URMDB.ORA' resize 40960m
查看表空间利用情况 表/索引等占内存情况
Select Segment_Name as a, Sum(bytes) / 1024 / 1024 as sum From User_Extents Group By Segment_Name
添加表空间数据文件并设置自增长及上限
alter tablespace BHSATABLESPACE add datafile 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\URMDB05.ORA' size 500M autoextend on maxsize 32767M;
重建索引
alter index IX_T_INDICATOR_SIGNAL rebuild