Re: optimal method for purging time based data
Date: Thu, 24 Sep 2009 11:05:03 -0700 (PDT)
On Sep 23, 10:24 am, uberchump <bobdu..._at_gmail.com> wrote:
> On Sep 21, 2:56 pm, joel garry <joel-ga..._at_home.com> wrote:
> > On Sep 21, 10:24 am, "bobdu..._at_gmail.com" <bobdu..._at_gmail.com> wrote:
> > > Hi,
> > > I'm a develper of a j2ee based web application that supports mutliple
> > > databases (oracle obviously included). We access oracle via their
> > > JDBC driver.
> > > We have several tables in our database that store time based events,
> > > and periodically we have a routine in our code that "purges" the
> > > data. We run a query similar to the one below, this one will purge
> > > all but the last 7 days of data:
> > > DELETE FROM someeventtable WHERE eventdate < (LOCALTIMESTAMP +
> > > INTERVAL '-10080' MINUTE);
> > > This "someeventtable" is constantly being inserted to in our
> > > application as well. We've found that on busy systems this query can
> > > take a VERY long time. I did some experimentation in the past and
> > > found that using "CURRENT_TIMESTAMP" is in fact far slower than
> > > "LOCALTIMESTAMP" so thats why we're using that - however, i'm hoping
> > > we can do better.
> > > Can anyone suggest a SQL based method for doing this more
> > > efficiently? It must be SQL based as we support other DB's and need
> > > to remain agnostic as much as possible.
> > > Thx,
> > > Bob
> > This is one of those things where using a database blind command can
> > really bite you in places you don't want to be bitten. I'm pretty
> > sure Jonathan Lewis has written something recently about these kinds
> > of windowed deletes, but I couldn't find it with a quick google.
> > However, I did findhttp://jonathanlewis.wordpress.com/2008/09/29/index-analysis-2/
> > , which, if you follow some links, gives some idea of the types of
> > specific problems one can run into. Of course, specific problems tend
> > to have specific solutions, so in the Oracle world they tend to be
> > things like coalescing after deleting, or using partitioning, or doing
> > a create table as select for the rows you want to keep, then renaming
> > table.
> > For situations like these, you might as well fork code for database
> > engines. The alternative is to have people think badly of your work.
> > Blaming Oracle for having Oracle specific solutions is pretty silly,
> > too.
> > You also might want to poke around on asktom.oracle.com, I'm sure this
> > subject has been covered there, somewhere.
> > There is a tuning book by Cary Millsap (http://carymillsap.blogspot.com/
> > ) that has a methodology for figuring out what is slowing you down.
> > You also should use the tools available to you to figure out what is
> > actually slowing you down, rather than relying on mysterious
> > incantations that may do nothing to solve your problem. Look for
> > tools that ogle tables with wait in the table name. Enterprise
> > Manager allows you to drill down and look at what a slow session is
> > doing.
> > jg
> > --
> > _at_home.com is bogus.
> > Step aside!http://www3.signonsandiego.com/stories/2009/sep/21/webs-general-store...
> Hi Joel,
> Thanks for the comments! I'm definitely not blaming oracle for
> anything here, and certainly do have some flexibility as to forking
> code and doing db specific operations, but for complexity reasons we
> try to keep it as simple as possible.
> To that end, is there anything i can/should do after these deletes?
> For example (based on what you've pointed me to and some addtional
> reading), i could run "alter index coalesce" after massive deletes. I
> could for instance say if the delete operation took longer than 1 or 5
> minutes to operate, run this command to hopefully free up some of the
> space. Does this sound like a decent idea? I can run any other
> similar commands before and after the delete as long as the table
> itself is not affected (as it will continue to be inserted to during
> the delete operation).
> Its tricky because we do our best to have a hands off approach for
> customers to their DB and try to manage things as much as we can. But
> when we run into issues like these, it is clear that a real DBA should
> come in help determine whats going wrong (as you may have guess
> ianadba :)).
> Let me know if you have further thoughts, thanks!
Ah, the phrase I couldn't think of was "sweeper index." See http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6601312252730 and richardfoote.wordpress.com for some excellent descriptions of what really goes on. Under presentations and demos Richard shows when to rebuild or coalesce, and his blogs go into the issues in detail.
+oracle "sweeper index"
-- _at_home.com is bogus. http://www.blogofdeath.com/archives/001228.htmlReceived on Thu Sep 24 2009 - 13:05:03 CDT