oracle常用SQL语句
查看oracle状态的SQL语句
select status from v$instance;
查看oracle控制文件的SQL语句
select name from v$controlfile;
查看oracle数据文件的SQL语句
select name from v$datafile;
查看oracle联机日志文件
select * from v$logfile;
查看表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
2),
'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
查看表空间对应的数据文件
select file_name,tablespace_name from dba_data_files
where tablespace_name='SYSTEM';
添加表空间文件
alter tablespace USERS add datafile 'D:\orcle\product\10.2.0\oradata\orcl\USERS02.DBF' size 10M autoextend on maxsize 20G;
调整数据文件的大小,(不建议这么搞)
alter database datafile 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF' resize 7600M;
数据缓冲区的使用命中率
数据缓冲区的使用命中率=1 - ( physical reads / (db block gets + consistent gets) )。
select round( 1 -((SELECT value FROM v$sysstat WHERE name='physical reads')/
((SELECT value FROM v$sysstat WHERE name='consistent gets')+
(SELECT value FROM v$sysstat WHERE name='db block gets'))
),2)*100||'%' from dual;
用以下语句可以查看数据缓冲区的命中率:
SELECT name, value FROM v$sysstat WHERE name IN ('db block gets', 'consistent gets','physical reads');
查询出来的结果Buffer Cache的命中率应该在90%以上,否则需要增加数据缓冲区的大小。
查询表空间是否是自动扩展:
select tablespace_name,file_name,autoextensible from dba_data_files where tablespace_name = 'SYSTEM';