1 查看值得懷疑的SQL

創(chuàng)新互聯(lián)建站秉承實現(xiàn)全網(wǎng)價值營銷的理念,以專業(yè)定制企業(yè)官網(wǎng),網(wǎng)站制作、做網(wǎng)站,小程序設(shè)計,網(wǎng)頁設(shè)計制作,手機網(wǎng)站制作,營銷型網(wǎng)站幫助傳統(tǒng)企業(yè)實現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對客戶都以感恩的心態(tài)奉獻自己的專業(yè)和所長。
select substr(to_char(s.pct,'99.00'),2)||'%'load,
s.executions executes,
p.sql_text
from(select address,
disk_reads,
executions,
pct,
rank() over(order by disk_reads desc) ranking
from(select address,
disk_reads,
executions,
100*ratio_to_report(disk_reads) over() pct
from sys.v_$sql
where command_type!=47)
where disk_reads50*executions) s,
sys.v_$sqltext p
where s.ranking=5
and p.address=s.address
order by 1, s.address, p.piece;
2 查看消耗內(nèi)存多的sql
select b.username ,a.buffer_gets ,a.executions,
a.disk_reads/decode(a.executions,0,1,a.executions),a.sql_text SQL
from v$sqlarea a,dba_users b
where a.parsing_user_id = b.user_id
and a.disk_reads 10000
order by disk_reads desc;
3 查看邏輯讀多的SQL
select*
from(select buffer_gets, sql_text
from v$sqlarea
where buffer_gets500000
order by buffer_gets desc)
where rownum=30;
4 查看執(zhí)行次數(shù)多的SQL
select sql_text, executions
from(select sql_text, executions from v$sqlarea order by executions desc)
where rownum81;
5 查看讀硬盤多的SQL
select sql_text, disk_reads
from(select sql_text, disk_reads from v$sqlarea order by disk_reads desc)
where rownum21;
6 查看排序多的SQL
select sql_text, sorts
from(select sql_text, sorts from v$sqlarea order by sorts desc)
where rownum21;
7 分析的次數(shù)太多,執(zhí)行的次數(shù)太少,要用綁變量的方法來寫sql
set pagesize 600;
set linesize 120;
select substr(sql_text,1,80) "sql",count(*),sum(executions) "totexecs"
from v$sqlarea
where executions5
group by substr(sql_text,1,80)
having count(*)30
order by 2;
8 游標(biāo)的觀察
set pages 300;
select sum(a.value), b.name
from v$sesstat a, v$statname b
where a.statistic#=b.statistic#
and b.name='opened cursors current'
group by b.name;
select count(0) from v$open_cursor;
select user_name, sql_text,count(0)
from v$open_cursor
group by user_name, sql_text
having count(0)30;
9 查看當(dāng)前用戶username執(zhí)行的SQL
select sql_text
from v$sqltext_with_newlines
where(hash_value, address) in
(select sql_hash_value, sql_address
from v$session
where username='username')
order by address, piece;
oracle日志查看
一.oracle日志的路徑:
登錄:sqlplus
"/as
sysdba"
查看路徑:sql
select
*
from
v$logfile;
sql
select
*
from
v$logfile;(#日志文件路徑)
二.oracle日志文件包含哪些內(nèi)容:(日志的數(shù)量可能略有不同)
control01.ctl
example01.dbf
redo02.log
sysaux01.dbf
undotbs01.dbf
control02.ctl
redo03.log
system01.dbf
users01.dbf
control03.ctl
redo01.log
shttest.dbf
temp01.dbf
三.oracle日志的查看方法:
sqlselect
*
from
v$sql
(#查看最近所作的操作)
sqlselect
*
fromv
$sqlarea(#查看最近所作的操作)
oracle
數(shù)據(jù)庫的所有更改都記錄在日志中,從目前來看,分析oracle日志的唯一方法就是使用oracle公司提供的logminer來進行,因為原始的日志信息我們根本無法看懂,oracle8i后續(xù)版本中自帶了logminer,而logminer就是讓我們看懂日志信息的工具,通過這個工具可以:查明數(shù)據(jù)庫的邏輯更改,偵察并更正用戶的誤操作,執(zhí)行事后審計,執(zhí)行變化分析。
1、因為oracle運行在Linux系統(tǒng)下,首先,要連接Linux系統(tǒng)。
2、切換到oracle安裝用戶下。 我的用戶是 oracle。
3、運行oracle的環(huán)境變量,在oracle 的根目錄下面,運行 soruce .bash_prfile 命令, 以便輸入相關(guān)命令。
4、運行命令: cd $ORACLE_HOME 進入oracle的安裝目錄。
5、在此輸入命令: find -name listener.log ,查找監(jiān)控日志文件。
6、運行命令 cd 到查看到的日志文件目錄。
7、運行cat listener.log命令 查看日志文件。
首先了解什么是外部表,與其它表的區(qū)別,建立一個簡單的外部表(主要看操作過程),最后我們用外部表查看ORACLE報警日志
1.了解oracle外部表
外部表定義:結(jié)構(gòu)被存放在數(shù)據(jù)字典,而表數(shù)據(jù)被放在OS文件中的表
作用:在數(shù)據(jù)庫中查詢OS文件的數(shù)據(jù),還可以將OS文件數(shù)據(jù)裝載到數(shù)據(jù)庫中
與其它表的區(qū)別:在外部表上不能執(zhí)行DML操作,也不能在外部表上建索引,只能執(zhí)行select操用
2.建一個簡單的外部表1.建一個OS上的文件
因為外部表主要是查看OS上的文件,首先在OS上建一個文件
mkdir -p /oracle/ext
vi /oracle/ext/ext.dat
10,20,30
40,50,60
70,80,90
2.授予用戶權(quán)限,并建立目錄對象
在此我們先建一個新用戶
create user test identified by “123” default tablespace test quota unlimited on test;
用戶授權(quán)
SQL grant create any directory to test;
建立目錄對象
SQL conn test / 123
Connected.
SQL create directory ext as '/oracle/ext';
Directory created.
3.建立外部表
SQL create table exttable(
id number,name varchar2(10),i number
)organization external
(type oracle_loader
default directory ext
access parameters
(records delimited by newline
fields terminated by ','
)location('ext.dat')
);
4.測試
SQL select * from exttable;
ID NAMEI
---------- ---------- ----------
10 20 30
40 50 60
70 80 90
測試成功,可見在數(shù)據(jù)庫中可以查詢OS文件的數(shù)據(jù)
2. 使用外部表查看oracle報警日志
由于在上面實驗中已建立了一個用戶,并賦相應(yīng)的權(quán)限,而且也有了OS文件(即報警文件alert_SID.log),所以在此直接建立目錄對象并建立外部表就可以了。
1.建立目錄對象
SQL conn test / 123
Connected.
SQL create directory bdump as '/oracle/u01/app/oracle/admin/db2/bdump';
Directory created.
2.建立外部表
SQL create table alert_log(
text varchar2(400)
)organization external
(type oracle_loader
default directory bdump
access parameters
(records delimited by newline
)location('alert_db2.log')
);
3.測試
首先查看能否查到alert_db2.log的內(nèi)容
SQL select * from alert_log where rownum 10;
TEXT
--------------------------------------------------------------------------------
Thu Jun 11 00:51:46 2009
Starting ORACLE instance (normal)
Cannot determine all dependent dynamic libraries for /proc/self/exe
Unable to find dynamic library libocr10.so in search paths
RPATH = /ade/aime1_build2101/oracle/has/lib/:/ade/aime1_build2101/oracle/lib/:/a
de/aime1_build2101/oracle/has/lib/:
LD_LIBRARY_PATH is not set!
The default library directories are /lib and /usr/lib
Unable to find dynamic library libocrb10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths
9 rows selected.
測試成功
然后我們測試查報警信息’ORA-%’
SQL select * from alert_log where text like 'ORA-%';
TEXT
--------------------------------------------------------------------------------
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27037: unable to obtain file status
ORA-205 signalled during: ALTER DATABASE MOUNT…
ORA-00301: error in adding log file '/home/oracle/oracle/oradata/testdb/redo01.l
og' - file cannot be created
ORA-27040: file create error
ORA-1501 signalled during: CREATE DATABASE db2
ORA-00200: control file could not be created
TEXT
--------------------------------------------------------------------------------
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27038: created file already exists
ORA-1501 signalled during: CREATE DATABASE db2
ORA-00200: control file could not be created
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27038: created file already exists
ORA-1501 signalled during: CREATE DATABASE db2
測試成功,
可見我們可以使用外部表來方便的查看ORACLE的報警信息
Oracle日志文件查看方法:
1、以sysdba權(quán)限用戶登錄數(shù)據(jù)庫。
2、執(zhí)行sql語句:
select?*?from?v$logfile;
3、結(jié)果顯示即為日志路徑:
4、另外還有其他的操作日志可用以下兩個sql語句查詢:
select?*?from?v$sql;--(#查看最近所作的操作)
select?*?fromv?$sqlarea;--(#查看最近所作的操作)
方法1:使用LogMiner工具
優(yōu)點:可以完全挖掘日志內(nèi)容,找出所有執(zhí)行過的SQL語句
缺點:
1. 如果沒有啟用歸檔日志,則只能對聯(lián)機日志進行挖掘
2. 需要掌握LogMiner的用法
本文名稱:怎么讀oracle日志 oracle怎么查看日志
文章位置:http://chinadenli.net/article16/hihogg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、關(guān)鍵詞優(yōu)化、Google、網(wǎng)站營銷、定制網(wǎng)站、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)