1,Problem Description:
After running for a period of time,database's error log find some error information:
ORA-01000 maximum open cursors exceeded field
2,Problem analyse:
ora-01000: maximum open cursors exceeded. means a session's open cursors exceed the valus which on parameters file
The root cause of ORA-01000 maybe the following:1,the open cursor's is too low to run our system 2,The user open too many cursors,and not close the cursor after the application complete!
On our Netman's system it set to 1000,it is means every session can open 1000 cursor concurrent.It is large enough for our system!So the root cause of ORA-01000 must exist on application!
We often find ORA-01000 on Java code,on java when we execute conn.createStatement() and conn.prepareStatement() it will open a cursor.Especially we use createStatement() and prepareStatement() on a loop,it is very easy occur the error! For your continue open
the cursor and not close it!So in general we should use createStatement() and prepareStatement() out of loop and after the statment is complete we should close it!It is better to close statment after you run executeQuery、executeUpdate and read the resultSet!
On java we better use follow way:
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery('select xx from yy');
...
} catch (SQLExeption e) {
e.printlStackTrace();
} finally {
if (rs!= null) {
try {rs.close();} catch (SQLException e) { }
}if(stmt!=null){
try {stmt.close();} catch (SQLException e) { }
}if(con!=null){
try {con.close();} catch (SQLException e) { }
}
}
3,How to find the problem sql:
--1,find which session cause open cursor issue
select sid,sum(value) open_cursor from v$sesstat where STATISTIC#=3 group by sid order by open_cursor;
--2,find what he is doing
SELECT * FROM V$OPEN_CURSOR WHERE SID IN (****);
Notice:On oracle,V$OPEN_CURSOR mease the used and opened cursor,it is a part of total cursors! v$sesstat where STATISTIC#=3,it means the total cursors used on session(include open and non-open)!For we only find sql on V$OPEN_CURSOR,it means we only find used and opened cursor sql and can't find used and non-opened cursor!
本文详细解析了ORA-01000错误的原因及解决方法,包括如何定位问题SQL语句,以及在Java应用中如何避免因过多打开游标导致此错误。
1074

被折叠的 条评论
为什么被折叠?



