SQL "cleanup" query as opposed to multiple databases?

Forum for users that want to write their own custom queries against the PT database either via the Structured Query Language (SQL) or using the PT3 custom stats/reports interface.

Moderator: Moderators

SQL "cleanup" query as opposed to multiple databases?

Postby trackalot » Sat May 21, 2011 6:44 am

Hi, I'm new to PT3 and have a large number of commingled played and observed hands that I want to manually import. I also expect to have large numbers of observed hands in the future, some of which may be duplicates of auto-imported "played" hands.

I would like to get rid of obsolete "observed" hands after 6 months or so, and am considering following the advice in this tutorial: Managing Multipe Databases

However, from my research here and my own guessing, I believe there are these limitations:

  • HUD will combine data from multiple DBs but if there are any duplicate hands the stats will be inaccurate
  • HUD may suffer in performance if querying multiple DBs
  • Reports can only be run on a single active database
I am wondering if instead I just imported everything into one huge database, could I then just periodically delete older "observed" hands that I no longer want?

It seems like this should be pretty easy to do with a delete query, except for the part about knowing whether it's an "observed" or "played" hand.

In my pig-latin SQL, what I want to do is:

Code: Select all
DELETE (all hand related records) OLDER THAN (some date) UNLESS (one of hero's aliases was at the table)

Can this be done, and if so -- pushing my luck :) -- what would that query look like?

Finally, can such a query be executed from within PT3, or if not is there a postgreSQL utility that can do it?
trackalot
 
Posts: 10
Joined: Thu Feb 12, 2009 2:06 am

Re: SQL "cleanup" query as opposed to multiple databases?

Postby WhiteRider » Sat May 21, 2011 9:54 am

Your "limitations" are all correct, except that if the cache is up to date on all databases, and you don't have too many being read by the HUD at once, then the performance won't suffer too much.

You can certainly purge observed hands with other filters (such as dates) applied too, though, so if you don't have so many hands that it makes one database too slow (in the main tracker, for instance) then that is certainly an option.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

Re: SQL "cleanup" query as opposed to multiple databases?

Postby trackalot » Sun May 22, 2011 3:31 am

Thanks for the fast reply - I have now imported 1M+ old hands and am already experiencing slowdown, so I want to try to "purge observed hands with other filters" as you suggest, but don't know how to go about it.

Are you referring to filters configured using the button in the main PT3 screen? I was able to set a filter on the dates I want to get rid of, but was not able to further limit that to hands where Hero was not at the table. And even if I did figure that out, I couldn't see how to delete the records that are now displayed.

Or if you mean I should do it with a SQL query, can you suggest a way to do this and/or point me to some documentation showing how to execute a SQL query on the PT3 database.

BTW, it seems as if this would be a useful feature to have built-in, i.e. "Purge Stale Records" that purges records more than X days old that do not involve Hero or his aliases.
trackalot
 
Posts: 10
Joined: Thu Feb 12, 2009 2:06 am

Re: SQL "cleanup" query as opposed to multiple databases?

Postby WhiteRider » Sun May 22, 2011 4:47 am

Sorry, I intended to give you the link to the Tutorial: Purging Sessions.

Have you run housekeeping to update the cache since you imported? You need to do that for optimum performance before you worry about purging.
WhiteRider
Moderator
 
Posts: 54025
Joined: Sat Jan 19, 2008 7:06 pm
Location: UK

Re: SQL "cleanup" query as opposed to multiple databases?

Postby trackalot » Sun May 22, 2011 5:16 am

I'm not sure how to quantify the performance, it's not terrible but not snappy like it was with a small DB.

I did the automatic housekeeping after the manual import, and it shows the cache status as 100% at the bottom of the main screen. I'm loathe to run it again if that display is accurate -- it took hours to do -- but I will do it again overnight when I have a chance. You may have guessed my machine is a little old too. :)

Appreciate the help again, wish all support was this good! I will try the Purge thing on a small test DB to verify, but it sounds like it is exactly the feature I was requesting.
trackalot
 
Posts: 10
Joined: Thu Feb 12, 2009 2:06 am

Re: SQL "cleanup" query as opposed to multiple databases?

Postby kraada » Sun May 22, 2011 8:39 am

If the cache status is 100% the only housekeeping you need to do regularly is vacuum and analyze, which should only take you a few minutes to run.
kraada
Moderator
 
Posts: 54430
Joined: Wed Mar 05, 2008 2:32 am
Location: NY


Return to Custom Stats, Reports, and SQL [Read Only]

Who is online

Users browsing this forum: No registered users and 0 guests