文章詳情頁
Oracle中用腳本跟蹤存儲(chǔ)過程實(shí)例講解
瀏覽:79日期:2023-11-24 17:58:49
一、用腳本啟動(dòng)并設(shè)置跟蹤的示例 我們可以用腳本進(jìn)行跟蹤存儲(chǔ)過程,當(dāng)然要了解這些存儲(chǔ)過程的具體語法和參數(shù)的含義,至于這些語法和參數(shù)含義請(qǐng)查詢聯(lián)機(jī)幫助。下面請(qǐng)看一實(shí)例: /****************************************************//* Created by: SQL Profiler *//* Date: 2004/06/19 16:50:05 *//****************************************************/-- Create a Queuedeclare @rc intdeclare @TraceID intdeclare @maxfilesize bigintset @maxfilesize = 5 -- Please replace the text InsertFileNameHere, with an appropriate-- filename prefixed by a path, e.g., c:MyFolderMyTrace. The .trc extension-- will be appended to the filename automatically. If you are writing from-- remote server to local drive, please use UNC path and make sure server has-- write Access to your network shareexec @rc = sp_trace_create @TraceID output, 0, N'c:test', @maxfilesize, NULL if (@rc != 0) goto error-- Client side File and Table cannot be scripted-- Writing to a table is not supported through the SP's-- Set the eventsdeclare @on bitset @on = 1exec sp_trace_setevent @TraceID, 12, 1, @onexec sp_trace_setevent @TraceID, 12, 12, @onexec sp_trace_setevent @TraceID, 12, 14, @on-- Set the Filtersdeclare @intfilter intdeclare @bigintfilter bigintexec sp_trace_setfilter @TraceID, 10, 0, 7, N'SQL Profiler'set @intfilter = 100exec sp_trace_setfilter @TraceID, 22, 0, 4, @intfilterset @intfilter = 1exec sp_trace_setfilter @TraceID, 23, 1, 0, @intfilterexec sp_trace_setfilter @TraceID, 35, 1, 6, N'pubs'-- Set the trace status to startexec sp_trace_setstatus @TraceID, 1-- display trace id for future referencesselect TraceID=@TraceIDgoto finisherror: select ErrorCode=@rcfinish: go二、生成跟蹤腳本的最簡(jiǎn)式 事件探查器建立跟蹤, 并設(shè)置好各種選項(xiàng), 完成后運(yùn)行跟蹤,然后生成腳本。 事件探查器--文件--導(dǎo)出跟蹤定義的文件--選擇合適的版本。這樣就會(huì)生成一個(gè)跟蹤的腳本, 打開生成的腳本, 修改里面的:exec @rc = sp_trace_create部分, 設(shè)置跟蹤結(jié)果的保存文件(用語句跟蹤的時(shí)候, 跟蹤結(jié)果只能保存到文件)。然后, 在需要跟蹤的時(shí)候, 運(yùn)行這個(gè)腳本來啟動(dòng)跟蹤。啟動(dòng)跟蹤后, 跟蹤自動(dòng)進(jìn)行, 所以你可以關(guān)閉查詢分析器做其他事情去了。 三、已知的問題 1.跟蹤記錄不是實(shí)時(shí)寫入跟蹤文件的, 因此, 可能會(huì)到你停止跟蹤的時(shí)候, 跟蹤信息才寫入跟蹤文件 2.查看當(dāng)前已經(jīng)進(jìn)行的跟蹤可以用(關(guān)于結(jié)果集的解釋, 請(qǐng)看聯(lián)機(jī)幫助): SELECT * FROM ::fn_trace_getinfo(0)3. 停止某個(gè)跟蹤, 可以在sp_trace_create 語句中設(shè)置自動(dòng)停止時(shí)間, 也可以手動(dòng)停止跟蹤, 用下面的語句: EXEC sp_trace_setstatus @traceid = 1 , -- 跟蹤的id @status = 0 -- 停止, 這樣以后還可能指定此項(xiàng)為來啟用EXEC sp_trace_setstatus @traceid = 1 , @status = 2 -- 關(guān)閉, 徹底釋放
標(biāo)簽:
Oracle
數(shù)據(jù)庫
排行榜
