一次pga 異常消耗分析
os: aix 6
db:10205
------使用os 命令觀察oracle 進程記憶體消耗情況
#ps gv
...... size
23396516 - A 14907:02 5203 14324376 2058800 xx 90815 38576 2.0 3.0 oracle
23396516 - A 14907:02 5203 14324376 2058800 xx 90815 38576 2.0 3.0 oracle
57540768 - A 3711:33 8331 15108164 15146740 xx 90815 38576 1.9 23.0 oracle
16318890 - A 10639:03 187 15110924 15009560 xx 90815 38576 2.0 23.0 oracle
33554712 - A 17263:24 13740 9598740 185552 xx 90815 38576 2.1 0.0 oracle
41877820 - A 10492:10 826 15110484 15018716 xx 90815 38576 2.0 23.0 oracle
..............
單個進程消耗近15g 明顯有問題啊
AIX/LINUX 如何查看單個進程在os層面的記憶體消耗 http://blog.csdn.net/lixora/article/details/24060299
這裡提供其他查看進程記憶體大方法
----查看對應oracle的應用進程記憶體消耗情況
select p.username,p.spid,p.program,pm.category,pm.used,pm.allocated,pm.max_allocated
from v$process p ,v$process_memory pm;
-----where p.pid=pm.pid and program like '%TNS%';
41877820 :
USERNAME SPID PROGRAM CATEGORY USED ALLOCATED MAX_ALLOCATED
--------------- ------------ ------------------------------------------------ --------------- ---------- ---------- -------------
oracle 41877820 oracle@sssdb SQL 1.3077E+10 1.3081E+10 1.3081E+10
oracle 41877820 oracle@sssdb PL/SQL 224 2008 2008
oracle 41877820 oracle@sssdb Other 2178876745 2178876745
33554712:
USERNAME SPID PROGRAM CATEGORY USED ALLOCATED MAX_ALLOCATED
--------------- ------------ ------------------------------------------------ --------------- ---------- ---------- -------------
oracle 33554712 oracle@sssdb SQL 5380315176 5382747784 5382747784
oracle 33554712 oracle@sssdb PL/SQL 26240 31224 37560
oracle 33554712 oracle@sssdb Other 4398399145 4398399145
USERNAME SPID PROGRAM CATEGORY USED ALLOCATED MAX_ALLOCATED
--------------- ------------ ------------------------------------------------ --------------- ---------- ---------- -------------
oracle 16318890 oracle@sssdb SQL 1.3066E+10 1.3070E+10 1.3070E+10
oracle 16318890 oracle@sssdb PL/SQL 224 2008 2008
oracle 16318890 oracle@sssdb Other 2185355529 2185355529
USERNAME SPID PROGRAM CATEGORY USED ALLOCATED MAX_ALLOCATED
--------------- ------------ ------------------------------------------------ --------------- ---------- ---------- -------------
oracle 57540768 oracle@sssdb SQL 1.3291E+10 1.3294E+10 1.3294E+10
oracle 57540768 oracle@sssdb PL/SQL 224 2008 2008
oracle 57540768 oracle@sssdb Other 2093690553 2093690553
USERNAME SPID PROGRAM CATEGORY USED ALLOCATED MAX_ALLOCATED
--------------- ------------ ------------------------------------------------ --------------- ---------- ---------- -------------
oracle 23396516 oracle@sssdb SQL 1.1608E+10 1.1611E+10 1.1611E+10
oracle 23396516 oracle@sssdb PL/SQL 224 2008 2008
oracle 23396516 oracle@sssdb Other 2769131497 2769131497
大部分記憶體花銷在sql 上
select program, MODULE, TERMINAL , MACHINE from v$session where paddr in (select addr from v$process where spid in(23396516,57540768,33554712,16318890 ,41877820));
----確定相應的應用
SQL> select program, MODULE, TERMINAL , MACHINE from v$session where paddr in (select addr from v$process where spid in(23396516,57540768,33554712,16318890 ,41877820));
PROGRAM MODULE TERMINAL MACHINE
------------ ------------- ----------------- ----------------
xxx.exe xxx.exe sfd DC9A29A
xxx.exe xxx.exe sdf72172 WOR722C72172
xxx.exe xxx.exe GR5FD WORKG-4715FD
xxx.exe xxx.exe FSK051 WOBG051
xxx.exe xxx.exe CD3LVB0U MSVWCVB0U
---------這裡繼續跟蹤相應應用的session 來確定這個應用中到底是那些操作造成了如此大的記憶體開銷
1、找出應用的sid和serial#
SQL> select sid,serial# from v$session where lower(program) like '%isap_client%';
SID SERIAL#
---------- ----------
78 1703
2、開始跟蹤
SQL> exec sys.DBMS_SYSTEM.set_sql_trace_in_session(78,1703,true);
PL/SQL procedure successfully completed.
3、期間做點關於這個應用的操作(保證和資料庫能有互動)
4、停止跟蹤,在user_dump_dest目錄下會產生跟蹤的trace檔案
SQL> exec sys.DBMS_SYSTEM.set_sql_trace_in_session(78,1703,false);
PL/SQL procedure successfully completed.
5、找出並進入user_dump_dest目錄,最後產生那個檔案就是要用的trace檔案
SQL> set lines 1024
SQL> show parameter user_dump_dest
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
user_dump_dest string /opt/oracle/db01/app/oracle/ad
min/ORCL/udump
SQL> exit
$ cd /opt/oracle/db01/app/oracle/admin/ORCL/udump
$ ls -otr | tail -1
-rw-r----- 1 oracle 576097 Jan 8 16:15 orcl_ora_24884.trc
$
6、使用tkprof格式化trace檔案,sys=no的意思是不查看sys使用者的操作,看了也沒啥用
$ tkprof orcl_ora_24884.trc report.txt sys=no
TKPROF: Release 9.2.0.4.0 - Production on Tue Jan 8 16:19:35 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
$
7、查看格式化後的檔案report.txt,裡頭就有跟蹤期間發生的所有預存程序(預存程序中執行的sql操作也會逐條顯示)和sql操作,還有各sql執行的統計資料,可以瞭解哪些sql快,哪些慢了
$ more report.txt