Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

DBI - cursors left open in Oracle

by Stegalex (Chaplain)
on Sep 08, 2001 at 22:30 UTC ( #111195=perlquestion: print w/replies, xml ) Need Help??
Stegalex has asked for the wisdom of the Perl Monks concerning the following question:

I have had a persistent problem for a while with my httpd daemons consuming all my box's memory and CPU after a couple of hours. Now most people will say that this is normal, httpd sucks memory and you can't always believe what top says. However, site performance slows down and some programs die from memory starvation, so this is far from an OK thing.

After much research, I have pinpointed the problem to one lousy sql statement that sometimes inexplicably leaves a cursor opened in Oracle. When this happens, the httpd process it is running under bloats and starts sucking CPU and doesn't stop until I restart httpd.

I am certain that there is not a logic error in my code. The cursors are SPORADICALLY left open even though the cursor is closed unconditionally after it's no longer needed.

Before I go much further, here's the info about my setup.

Apache 1.3.12
Perl 5.6.0
RH Linux 7
DBI 1.14
mod_perl 1.24
html::embperl 1.3.1

Has anyone else encountered situations where doing an $sth->finish; doesn't work?

I know the cursors are being left open because I have examined the sql_text column in the v$open_cursors view in oracle and it shows me the statement that has the open cursor. When I kill the offending httpd process, the cursor gets closed.


Replies are listed 'Best First'.
Re: DBI - cursors left open in Oracle
by seesik (Initiate) on Sep 08, 2001 at 23:05 UTC
    first off, what dbd::oracle version are you using? i had some trouble w/ 1.03 and cursor refs, but nothing on 1.06.

    secondly, are you using pl/sql cursors, or just the statement handle cursor? can we see your query, and can you tell us what your database's open_cursors/max_open_cursors init param is (check v$parameter)?

    remember, $sth->finish does NOT DESTROY the handle. it just sets the handle's Active attribute to false. you could try undef'ing the handle explicitly just to see if it get's gc'd.

    lastly, if you're on a production machine, i'd advise getting off of 8.1.5x altogether; either downgrade to 8.0.5 or up to 8.1.7 (skip 8.1.6 and 9.0.1).there have been a few times now that i've seen 8.1.5's SMON freak out and chew up 99% cpu time just trying to allocate extents. not that this has anything to do w/ your cursor issue...

      I don't have anything new to add other than to reiterate what seesik mentioned based on my experience. Consider it a second opinion ;-)

      Upgrade to 8.1.7. Your mother would tell you that it's good for you. And undef every handle after you've finished with it.

      Hope this helps!

      DBD::Oracle version 1.06

      This particular cursor is a statemtent handle cursor of the form:

      $sql = "select 'x', 'y' from dual";
      ($x, $y) = $sth->fetchrow_array;

      open_cursors parameter is 50
      there does not seem to be a max_open_cursors param defined

      Thanks for any and all comments!
(jptxs) Re: DBI - cursors left open in Oracle - for now...
by jptxs (Curate) on Sep 08, 2001 at 23:02 UTC
    I've never seen this particular behavior, but I have seen Oracle do a number of incredibly odd things on Linux. Oracle has told me that the client on Linux is the root of the cause in many cases. What I had done in one case where mystery sessions were being spawned was to simply write a script to query the sys views (v$sessions in my case, but v$open_cursors in yours) for the offending conditions periodically through cron and to kill off the asociated processes. It will depend on your exact configuration and session management style, but this may work for you for now as well. At least until you get through this.

    we eventually had to run Oracle on Sun to get the stability we needed.

    We speak the way we breathe. --Fugazi

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://111195]
Approved by root
[Corion]: perldigious: That seems to be more the export and likely it's the recipients of that export that like the titles changes
[Corion]: ... "changed"
[Corion]: I usually expect fixed header names, but am sometimes lenient in the order of columns. But changing the report titles often sounds to me as if you are not the sole consument of the export ;)
[shmem]: perldigious: as always - if it ain't broke, don't fix it. Ther must be a very compelling reason for changing column names in a database. Those are rare.
[Corion]: If you have whitespace in the column names in the database, whap the DBAs ;)
[shmem]: It's common for some vendors to have column names such as WRSTVG or some other such whizzbang, and another table where these names are mapped to something meaningful depending on how you look at the data
[shmem]: afair in SAP that occurs all the time

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-05-25 13:35 GMT
Find Nodes?
    Voting Booth?