檢查系統(tǒng)層面。
root#df -h
- 檢查內(nèi)存使用情況
root#free -m 查看available值
- 檢查CPU使用情況
root#top
a)看第一行 load average的3個(gè)值,如果超過(guò)cpu數(shù)*70%,那就說(shuō)明cpu負(fù)載過(guò)高。
b)在top命令下按大寫(xiě)C,可以按cpu負(fù)載總量排序
c)查看cpu數(shù)方法:
通過(guò)命令lscpu,可以看到sockets數(shù)量、每個(gè)socket的核心數(shù)、每個(gè)核心線(xiàn)程數(shù),總的邏輯cpu數(shù)量=sockets數(shù)量*每個(gè)socket核心數(shù)*每個(gè)核心線(xiàn)程數(shù)。如下截圖,
cpus數(shù)量=socket數(shù)量(1)*每個(gè)socket的Cores(16)*每個(gè)core的Threads(2)
=32
檢查數(shù)據(jù)庫(kù)層面。
- 檢查表空間使用情況
SQL>select dbf.tablespace_name, dbf.totalspace “總量(M)”, dbf.totalblocks as 總塊數(shù),
dfs.freespace “剩余總量(M)”, dfs.freeblocks “剩余塊數(shù)”, (dfs.freespace / dbf.totalspace) * 100 “空閑比例”
from (select t.tablespace_name, sum(t.bytes) / 1024 / 1024 totalspace, sum(t.blocks) totalblocks
from dba_data_files t group by t.tablespace_name) dbf,
(select tt.tablespace_name, sum(tt.bytes) / 1024 / 1024 freespace, sum(tt.blocks) freeblocks
from dba_free_space tt group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name);
- 檢查數(shù)據(jù)庫(kù)連接情況
SQL>select STATUS,count(*) from v$session t group by status;
- 檢查無(wú)效對(duì)象
SQL>select owner,object_name,object_type from dba_objects where
status’VALID’ and owner’SYS’ and owner’SYSTEM’ and owner’PUBLIC’;
- 高水位表查詢(xún)(實(shí)際占用空間/預(yù)估空間 > 2 并且 實(shí)際占用空間>1G)
SQL> SELECT T.owner, TABLE_NAME, NUM_ROWS, AVG_ROW_LEN,
AVG_ROW_LEN * NUM_ROWS / 1024 / 1024 / 0.9 as preditSizeM,
BLOCKS * 8 / 1024 as factSize FROM dba_tables T
WHERE owner=’BOOKPLAT’ AND NUM_ROWS>0 and AVG_ROW_LEN>0
AND (BLOCKS * 8 / 1024) / (AVG_ROW_LEN * NUM_ROWS / 1024 / 1024 / 0.9 ) > 2 AND BLOCKS * 8 / 1024 >=1024;
降水位方法(3種):
- 收縮表:
alter table enable row movement ;
alter table shrink space ;
alter table disable row movement ;
analyze table compute statistics;
- 對(duì)表進(jìn)行MOVE操作:
alter table move; –注意:move時(shí)會(huì)對(duì)表鎖定
重建表的索引:
alter index rebuild online;
- 復(fù)制數(shù)據(jù)到臨時(shí)表T1,然后drop原表T,再rename T1 to T。
create table T1 as select * from T;
drop table T purge;
rename T1 to T;
- 行遷移查詢(xún):
a) analyze table list chained rows into CHAINED_ROWS;
其中:表CHAINED_ROWS可以通過(guò)rdbms/admin/utlchain.sql創(chuàng)建;
b) select table_name, num_rows, CHAIN_CNT from user_tables where table_name=” ;
c) 通過(guò)先備份到一個(gè)臨時(shí)表,然后delete再insert消除。
數(shù)據(jù)庫(kù)日志。
- 警告日志alert.log
SQL> show parameter background_dump_dest;
- 聯(lián)機(jī)(在線(xiàn))重做日志
SQL>select * from v$logfile;
SQL>select * from v$log;
- 歸檔重做日志
SQL> select * from v$archived_log t where t.dest_id=1 order by first_time desc;
需要查看fires_time和next_time的間隔,如果一直間隔都很小,可以考慮增加日志組并調(diào)整每個(gè)日志文件的大小。
- 跟蹤日志
SQL>select name,value from v$diag_info;
awr/addm/ash報(bào)告。
- AWR報(bào)告
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba;
SQL> @awrrpt.sql
Type Specified: html (報(bào)告格式)
Enter value for num_days:7 (查詢(xún)幾天內(nèi)的快照)
Enter value for begin_snap: 49456 (開(kāi)始快照id)
Enter value for end_snap: 49480 (結(jié)束快照id)
Enter value for report_name: awr_test.html (報(bào)告名字)
- ADDM報(bào)告
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba;
SQL>@addmrpt.sql
Enter value for begin_snap: 49456
Enter value for end_snap: 49480
Enter value for report_name: addm_test.txt (默認(rèn)是txt格式)
- ASH報(bào)告
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba;
SQL> @ashrpt.sql
Enter value for report_type: html
Enter value for begin_time: -30 (查詢(xún)最近半小時(shí))
Enter value for duration:
Enter value for report_name: ash_test.html