Cursor memory use in a background job
714253Aug 4 2009 — edited Aug 5 2009I am researching a solution for a client, and need help as I'm admittedly an Oracle greenhorn. They run 10g Enterprise Edition.
{color:navy}*The problem*{color}: create a low-priority background process that uses DB inactivity windows to read through a large table (over 25 million records) a row at a time, and perform some simple operations with a few fields from each row. The process needs to be running 24x7 by default, although able to be administratively paused/restarted at any time. It also needs to pause itself M hours after last row read, and restart after a subsequent N hours.
h3.
Oracle Jobs
First, I'm wondering whether this sounds like a task suitable for a "job" managed by the Scheduler (<tt>DBMS_SCHEDULER</tt>), which could be enabled or disabled to mimic pausing/restarting functionality.
h3.
Cursors and memory usage
My second, main question lies with memory usage. One of their main concerns is that the background process not occupy much memory on the server. The general flow I've worked up:
<li> Function1: declare and open a cursor for the main SELECT. This would be run once only. Call Function2.
<li> Function2: the second, main function would perform a fetch of one row on the cursor, and make a call to an auxiliary function to operate on the data. Function2 would be executed constantly as the main process.
<li> Function3: close the cursor. Would be executed upon reaching the last row of the table, or if for some reason the admin. should decide to abort the process prematurely.
<li> If the client decides such, this process may be constant, so it would be restarted automatically with a call back to Function1.
However, I don't understand cursors enough to know if that would occupy a lot of memory on the server throughout the life-cycle of the master process, knowing ahead of time that the resultset the cursor identifies is very large. I've attempted to research this both in manuals (the DB Administrator, SQL Reference, Application Developer's Guide) and these forums, but not able to track down a clear answer -- I got lost somewhere between PGA and SGA memory. The furthest I've gotten in understanding cursors is that they're a mere instruction set, not a copy of the resultset, and therefore don't occupy a substantial amount of resident memory. I would very much appreciate some verification about whether this is accurate or not.
I'm wide open to suggestions -- thanks in advance for the help!