oracle  8i系统检查

set echo on
spool d:\bk\1.txt
select sysdate from dual;
--版本信息
select * from v$version;

--安装的产品
col PARAMETER for a50;
col value for a10;
select * from v$option order by 2;

--用户信息
set linesize 100
set pagesize 100
COL USERNAME FOR A18
COL PASSWORD FOR A18
COL DEFAULT_TABLESPACE FOR A18
COL PROFILE FOR A18
col account_status for a18
SELECT USERNAME,PASSWORD,DEFAULT_TABLESPACE,PROFILE,account_status
FROM DBA_USERS ORDER BY 5,3;

--日志文件
col MEMBERS for 9;
SELECT * FROM V$LOG;
SELECT * FROM V$LOGFILE;

--归档信息,目录,格式,归档进程
col DEST_NAME for a25 
col DESTINATION for a60
col value for a20
select DESTINATION   from v$archive_dest where DESTINATION is not null;
select value from v$parameter where name='log_archive_format';
select * from v$archive_processes where status='ACTIVE';
col value clear


--数据文件基本信息
SELECT TABLESPACE_NAME,FILE_NAME,TRUNC(BYTES/1024/1024) MB
FROM DBA_data_files ORDER  BY TABLESPACE_NAME;

--数据文件的可否自动扩展,如果可以扩展每次增加的块数
select FILE_NAME,STATUS,AUTOEXTENSIBLE,round(MAXBYTES/1024/1024/1024) gb,
INCREMENT_BY "每次增加块数"
from dba_data_files
order by 3;

--表空间的基本信息
select TABLESPACE_NAME,STATUS,CONTENTS,EXTENT_MANAGEMENT,
ALLOCATION_TYPE
from dba_tablespaces
order by 3;

--表空间的总容量和空闲空间,表空间的碎片个数和最大的碎片
select t.tablespace_name,TOTAL_MB-FREE_MB userd_mb,FREE_MB,TOTAL_MB,number_space,max_space
from 
(SELECT TABLESPACE_NAME,TRUNC(SUM(BYTES)/1024/1024) TOTAL_MB
FROM DBA_data_files 
GROUP BY TABLESPACE_NAME) t,
(SELECT TABLESPACE_NAME,TRUNC(SUM(BYTES)/1024/1024) FREE_MB,
count(*) number_space,round(max(bytes)/1024/1024) max_space
FROM DBA_FREE_SPACE 
GROUP BY TABLESPACE_NAME) f
where t.tablespace_name=f.tablespace_name
order by number_space desc;

--数据文件的碎片个数和最大的碎片
col name for a40

select file_name,TOTAL_MB-FREE_MB userd_mb,FREE_MB,TOTAL_MB,number_space,max_space
from
(SELECT file_id,file_name,TRUNC(SUM(BYTES)/1024/1024) TOTAL_MB
FROM DBA_data_files 
GROUP BY file_id,file_name) t,
(SELECT file_id,TRUNC(SUM(BYTES)/1024/1024) FREE_MB,
count(*) number_space,trunc(max(bytes)/1024/1024) max_space
FROM DBA_FREE_SPACE group by file_id ) f
where f.file_id=t.file_id
order by number_space desc;


--控制文件
col type for a25
col name for a42
select * from v$controlfile;
select * from v$controlfile_record_section;
col type clear
--临时表空间和临时文件

select * from v$tempfile;

--分区表的信息
SELECT owner,TABLE_NAME,PARTITIONING_TYPE, SUBPARTITIONING_TYPE,PARTITION_COUNT
FROM DBA_PART_TABLES
where owner not in('SYSTEM','SH');

--找到大的段
col SEGMENT_NAME for a30;
col SEGMENT_type for a20;
select OWNER,SEGMENT_NAME,SEGMENT_TYPE,TABLESPACE_NAME,BLOCKS,EXTENTS
from dba_segments
where EXTENTS>50 or BLOCKS>10000
order by BLOCKS desc;

--索引信息,找到无效的索引
col owner for a12;
col tablespace_name for a12;
select index_name,owner,table_name,tablespace_name,status
from dba_indexes
where owner not in ('SYS','SYSTEM') 
and status != 'VALID' 
and tablespace_name is not null;

--排序段信息
select * from V$sort_usage;

--内存信息
col name for a30;
col value clear;
select * from v$sga;
select gethitratio*100
from v$librarycache
where namespace = 'SQL AREA';

select * from V$SHARED_POOL_RESERVED;

SELECT (1 - (phy.value -lob.value -dir.value)/ses.value)*100 "CACHE HIT RATIO"
FROM v$sysstat ses, v$sysstat lob,
v$sysstat dir, v$sysstat phy
WHERE ses.name = 'session logical reads'
AND dir.name = 'physical reads direct'
AND lob.name = 'physical reads direct (lob)'
AND phy.name = 'physical reads';


--综合统计
col value clear
col name for a53
select * from v$sysstat where value<>0;

--等待事件
select * from v$system_event;
select * from v$session_wait
where event not in
('rdbms ipc message','null event','smon timer','pmon timer','wakeup time manager');

--回退信息
select SEGMENT_NAME,INITIAL_EXTENT,NEXT_EXTENT,MIN_EXTENTS,MAX_EXTENTS,STATUS
from dba_rollback_segs;

select USN "编号",EXTENTS "现有范围",RSSIZE "现有大小" ,HWMSIZE "最大值",
SHRINKS "回缩次数",AVESHRINK "平均回缩大小",EXTENDS "扩展次数" from v$rollstat;

--锁的信息
col sid for 999
col LMODE for 9
col REQUEST for 9
col BLOCK for 9
col type clear
select * from v$lock;

--并行查询
col value clear;
col STATISTIC for a30;
SELECT * FROM V$PQ_SYSSTAT;

--参数文件
col name for a40
col value for a50
select name,value from v$parameter where value is not null and value<>'0';

--后台进程
col name for a15;
select paddr, NAME, DESCRIPTION from v$bgprocess where paddr<>'00';

--总进程信息
col PROGRAM for a30
select ADDR,BACKGROUND ,PROGRAM,TERMINAL,USERNAME 
from  v$process order by 2 ;

spool off

oracle 8i系统检查-LMLPHP

05-09 21:24