oracle命令

查看实例名:
select * from v$instance;
查看数据库名:
select name from v$database;
查看数据库用到几个表空间:  在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。关键词 DISTINCT 用于返回唯一不同的值。
select distinct TABLESPACE_NAME from tabs;  查出TABLESPACE_NAME列唯一的值
查看oracle所有的表空间
Select * From Dba_Tablespaces
[root@flt flt]# pwd  一个表空间在文件系统上至少存在一个数据文件.dbf
/oracle/oradata/flt
select * from dba_free_space
查看当前用户的缺省表空间
SQL>select username,default_tablespace from user_users;
查看当前用户的角色
SQL>select * from user_role_privs;
查看当前用户的系统权限和表级权限
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
查看用户下所有的表
SQL>select * from user_tables;
select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;  查看表空间物理文件的名称及大小
select * from V$SESSION WHERE STATUS = ‘INACTIVE‘ AND USERNAME IS NOT NULL;  显示当前连接
Select Created, Log_Mode from V$Database;   查看数据库的创建日期与归档方式
Select version from Product_component_version Where SUBSTR(PRODUCT,1,6)=‘Oracle‘  查看数据库的版本
select owner, object_type, status, count(*) count# from all_objects group by owner, object_type, status;  查看数据库库对象
select member from v$logfile;    查看日志文件
select name from v$controlfile;    查看控制文件
select status from v$Instance;  进入sqlplus查看数据库的状态,显示当前数据库的状态为OPEN
select * from all_users;  查看所有用户
select table_name from user_tables;
select * from tab;
SQL*PLUS命令书上介绍了连接命令、编辑命令、文件操作命令和交互式命令,下面我们补充一下格式化命令,这类命令的作用是对查询结果进行格式化输出,使得用户查看时更加直观。
常用的格式化命令有:
    COLUMN(COL)
    REPHEADER(REPH)
    REPFOOTER(REPF)
    TTITLE(TTI)
    BTITLE(BTI)

查看表空间已经使用的百分比
select   a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024   "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  
from  
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   a,  
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)   b  
where   a.tablespace_name=b.tablespace_name  
order   by   ((a.bytes-b.bytes)/a.bytes)   desc

“Sum MB”表示表空间所有的数据文件总共在操作系统占用磁盘空间的大小
比如:test表空间有2个数据文件,datafile1为300MB,datafile2为400MB,那么test表空间的“Sum MB”就是700MB
“userd MB”表示表空间已经使用了多少
“free MB”表示表空间剩余多少
“percent_user”表示已经使用的百分比

从上面中查看到FLT_INDX表空间已使用百分比达到90%以上,可以查看该表空间总共有几个数据文件,每个数据文件是否自动扩展,可以自动扩展的最大值。
select   file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB"   from   dba_data_files  
where tablespace_name=‘USERS‘

查看 xxx 表空间是否为自动扩展   
select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc;

确认磁盘空间足够,增加一个数据文件
alter   tablespace   MLOG_NORM_SPACE  
add   datafile   ‘/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf‘  
size   10M   autoextend   on   maxsize   20G  

验证已经增加的数据文件
select   file_name,file_id,tablespace_name   from   dba_data_files  
where   tablespace_name=‘MLOG_NORM_SPACE‘

如何删除表空间数据文件,如下:
alter   tablespace   MLOG_NORM_SPACE  
drop    datafile ‘/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf‘

通过查询dba_free_space表可以了解一个tablespace的空间使用情况。
TABLESPACE_NAME:
    Name of the tablespace containing the extent
FILE_ID:
    ID number of the file containing the extent
BLOCK_ID:
    Starting block number of the extent
BYTES:
    Size of the extent in bytes
BLOCKS:
    Size of the extent in ORACLE block

查询表空间的free space

select  
tablespace_name,  
count(*) as extends,  
round(sum(bytes)/1024/1024, 2) as MB,  
sum(blocks) as blocks  
from dba_free_space group by tablespace_name;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。