473,396 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to archive lots of records

hi all,

I have a table with lots of stock movements. ( stockmovements)
Once per year the user need to run a routine that move these records
into a table (history) and delete the movements from the original
table (stockmovements).

My application is writtend in Borland Delphi. (interfacing with db2
with sql statements and stored procedure written in SQL)

I have tried different solutions but without success:

1) an "atomic" sql insert/delete of all movements. this is impossible
because of log size.
2) a loop of "atomic" sql insert/delete statements restricted to a
fixed number of records each time: but in my situation this take a
very long time.(4 hr) (i think because the "history" table is very
very large...and so..the insert statement take very long time)
3) a "manual" procedure of export to ixf...and load...: this is very
fast and i prefer this solution... but i can't provide this solution
like an interactive procedure for the user (i don't know how to do
these command of export / load in SQL)... moreover: i think i can't
launch these statements while users are connected to database...

Have you a solution for this kind of problem?
Maybe i have a bad design of my tables? (suggestions?)

(sorry for english mistakes)
JH

Jun 27 '08 #1
7 1536
On Apr 16, 12:31 pm, John Hopfield <Hopfi...@freemail.itwrote:
hi all,

I have a table with lots of stock movements. ( stockmovements)
Once per year the user need to run a routine that move these records
into a table (history) and delete the movements from the original
table (stockmovements).

My application is writtend in Borland Delphi. (interfacing with db2
with sql statements and stored procedure written in SQL)

I have tried different solutions but without success:

1) an "atomic" sql insert/delete of all movements. this is impossible
because of log size.
2) a loop of "atomic" sql insert/delete statements restricted to a
fixed number of records each time: but in my situation this take a
very long time.(4 hr) (i think because the "history" table is very
very large...and so..the insert statement take very long time)
3) a "manual" procedure of export to ixf...and load...: this is very
fast and i prefer this solution... but i can't provide this solution
like an interactive procedure for the user (i don't know how to do
these command of export / load in SQL)... moreover: i think i can't
launch these statements while users are connected to database...

Have you a solution for this kind of problem?
Maybe i have a bad design of my tables? (suggestions?)

(sorry for english mistakes)
JH
You don't mention your db2 version. If it is V9.x (unsure whether this
was already in 9.1) you can use range partitioning.

/Lennart
Jun 27 '08 #2
On 16 Apr, 14:41, Lennart <Erik.Lennart.Jons...@gmail.comwrote:
>
You don't mention your db2 version. If it is V9.x (unsure whether this
was already in 9.1) you can use range partitioning.
Sorry.
I'm working with db2 8.2
Jun 27 '08 #3
John Hopfield wrote:
hi all,

I have a table with lots of stock movements. ( stockmovements)
Once per year the user need to run a routine that move these records
into a table (history) and delete the movements from the original
table (stockmovements).

My application is writtend in Borland Delphi. (interfacing with db2
with sql statements and stored procedure written in SQL)

I have tried different solutions but without success:

1) an "atomic" sql insert/delete of all movements. this is impossible
because of log size.
2) a loop of "atomic" sql insert/delete statements restricted to a
fixed number of records each time: but in my situation this take a
very long time.(4 hr) (i think because the "history" table is very
very large...and so..the insert statement take very long time)
3) a "manual" procedure of export to ixf...and load...: this is very
fast and i prefer this solution... but i can't provide this solution
like an interactive procedure for the user (i don't know how to do
these command of export / load in SQL)... moreover: i think i can't
launch these statements while users are connected to database...

Have you a solution for this kind of problem?
Maybe i have a bad design of my tables? (suggestions?)

(sorry for english mistakes)
JH
Take a look at

http://www.optimsolution.com/

Larry E.
Jun 27 '08 #4
On Apr 16, 3:31 am, John Hopfield <Hopfi...@freemail.itwrote:
hi all,

I have a table with lots of stock movements. ( stockmovements)
Once per year the user need to run a routine that move these records
into a table (history) and delete the movements from the original
table (stockmovements).

My application is writtend in Borland Delphi. (interfacing with db2
with sql statements and stored procedure written in SQL)

I have tried different solutions but without success:

1) an "atomic" sql insert/delete of all movements. this is impossible
because of log size.
2) a loop of "atomic" sql insert/delete statements restricted to a
fixed number of records each time: but in my situation this take a
very long time.(4 hr) (i think because the "history" table is very
very large...and so..the insert statement take very long time)
3) a "manual" procedure of export to ixf...and load...: this is very
fast and i prefer this solution... but i can't provide this solution
like an interactive procedure for the user (i don't know how to do
these command of export / load in SQL)... moreover: i think i can't
launch these statements while users are connected to database...

Have you a solution for this kind of problem?
Maybe i have a bad design of my tables? (suggestions?)

(sorry for english mistakes)
JH
John.

Have a look at the "ADMIN_CMD" stored procedure. With it, you can do
something like the following within a stored procedure:

SET V_TS = CURRENT_TIMESTAMP;--

SET V_SP_CALL = 'CALL SYSPROC.ADMIN_CMD(''EXPORT TO /some_directory/
table.'||CHAR(V_TS)||'.ixf OF IXF messages /some_directory/
expTab.messages SELECT * FROM YOUR_TABLE WHERE'')';--

PREPARE S_SP_CALL FROM V_SP_CALL;--

EXECUTE S_SP_CALL;--

In my example above, I'm using dynamic SQL so that I can create a
unique name for the export file (based on a timestamp-valued variable
called V_TS). You may not need to do this, in which case your call to
ADMIN_CMD could be simpler, and may not even need to be dynamic.

Regards,

--Jeff
Jun 27 '08 #5
Lew
You might want to use the load from cursor functionality.

declare cursor mycur as select * from stockmovements where date <
xxxxxxx
load from mycur of cur insert into stockmovements_history

You could also use this to "clean" out your table if you have the
space

create table stockmovements_new
declare cursor mycur as select * from stockmovements where date >
xxxxxxx
load from mycur of cur insert into stockmovements_new

drop table stockmovements
rename table stockmovements_new to stockmovements

Not sure if my syntax is correctbut you get the idea



Jun 27 '08 #6
On 17 Apr, 13:02, Lew <seth...@yahoo.comwrote:
You might want to use the load from cursor functionality.

declare cursor mycur as select * from stockmovements where date <
xxxxxxx
load from mycur of cur insert into stockmovements_history
...
very interesting...thank you

but...i don't know if i can launch this kind of "script" from SQL or
from a SQL-Stored Procedure.

or using ADMIN_CMD( script )?

JH
Jun 27 '08 #7
John Hopfield wrote:
On 17 Apr, 13:02, Lew <seth...@yahoo.comwrote:
You might want to use the load from cursor functionality.

declare cursor mycur as select * from stockmovements where date <
xxxxxxx
load from mycur of cur insert into stockmovements_history
...

very interesting...thank you

but...i don't know if i can launch this kind of "script" from SQL or
from a SQL-Stored Procedure.
Unfortunately not - both are CLP commands, not SQL statements.
or using ADMIN_CMD( script )?
In version 8, no (8's ADMIN_CMD can only call DESCRIBE, EXPORT, PRUNE,
REORG, RUNSTATS, and UPDATE DB CFG). In version 9, sort of - you
couldn't do DECLARE CURSOR, but you could call ADMIN_CMD('EXPORT...')
followed by ADMIN_CMD('LOAD...'). The file used for the data would be
sat on the server by virtue of ADMIN_CMD (i.e. there wouldn't be lots
of network traffic involved).

Going back to your original post: are you unable to increase the log
size for some reason? (or possibly increase LOGSECOND to allow for
sufficient secondary logs to be allocated if/when necessary).

As for EXPORT+LOAD - you can use them both when others are connected to
the database - EXPORT in particular, which is effectively no different
to a normal query. However, LOAD does make the target table
inaccessible at least for the duration of the load (and possibly
afterward in the case of things like Check Pending states).
Cheers,

Dave.
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Dan Perl | last post by:
Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a...
3
by: Mike Turco | last post by:
I'm working on an application that imports and exports tons of CSV data, like 64,000 records per file, and six or seven files in a set. First off, by the tine I import a few hundred thousand...
2
by: indigo | last post by:
hi.. can someone suggest the best way to move data from one table to another. i'm trying to do this mainly due to my own limitations with regard to access. i have a form which has various cells...
5
by: Comcast Newsgroups | last post by:
I'm trying to put together a macro that queries my cell phone call expense DB the selects records as of a specific Date that are not marked "Archive", prints a report, then marks the records...
4
by: Mike Hnatt | last post by:
My goal is to get data from an XML file into a couple of tables in an Access database. The XML file is a little complex so I need control over what I do (I can't just read it into a dataset). ...
2
by: Snonck | last post by:
Is is possible to recover deleted rows from a table from archive logs? For example, say you have a database with archive logging turned off. You create a table and populate it with records. You...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
1
by: whitbacon | last post by:
I would like to have the ability to archive values in a lookup table. Take the following example lookup table luid, label, archive 1, green, No 2, red, No 3, blue, No select * from...
2
by: Cara Murphy | last post by:
Hi, I am looking to use a button on an issues database that will allow me to archive issues that are closed, once all of the information has been updated. In this sense, I want the issue to be...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.