473,387 Members | 1,493 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,387 software developers and data experts.

Recommended Procedure for Archiving Table Data

I need advice on archiving data from our production database.

Each night I would like to save and remove a day's data from two weeks ago, from all the tables. I know how to delete the data--though our schema does not specify cascaded deletes. However, I can't figure out how to save the desired data. I'd like to save it in SQL insert statement format, but I can't see how to get the data out. If I use psql to create a temp table with the old data in it, then the table disappears when I exit psql and I can't dump it with pg_dump. If I make a new table and put the data in it, then when I dump it with pg_dump, all the insert statements have the new table name rather than the original table name. I'm sure there's a good solution for this standard problem. Does anyone have a suggestion?

Thanks,
Sally
Nov 23 '05 #1
1 4781
Sally Ruggero wrote:
I need advice on archiving data from our production database.

Each night I would like to save and remove a day's data from two weeks
ago, from all the tables. I know how to delete the data--though our
schema does not specify cascaded deletes. However, I can't figure out
how to save the desired data. I'd like to save it in SQL insert
statement format, but I can't see how to get the data out. If I use
psql to create a temp table with the old data in it, then the table
disappears when I exit psql and I can't dump it with pg_dump. If I
make a new table and put the data in it, then when I dump it with
pg_dump, all the insert statements have the new table name rather than
the original table name. I'm sure there's a good solution for this
standard problem. Does anyone have a suggestion?
Create a temporary table from a query definition...
BEGIN;
create temp table archive_table as select * from foo where date between ....
delete from foo where date between ...
copy foo to '/tmp/archive.copy'
commit;

You probably want to at least do some basic checks on the data like row
counts
but that will archive out the data.

You could also just create an archival schema that you could push stuff to.

Sincerely,

Joshua D. Drake

Thanks,
Sally


--
Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC
Postgresql support, programming shared hosting and dedicated hosting.
+1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com
PostgreSQL Replicator -- production quality replication for PostgreSQL

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2

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

Similar topics

1
by: Cedric | last post by:
We have a table in db2 that has about 40 million rows added to it daily and want to keep a rolling period of 180 days worth of data on the table. We want to remove either one day or a few days...
7
by: narayana | last post by:
hi friends, i want to create a procedure like when i give a name as parameter to the procedure it should create a table with that name and with two column names as any type. plz explain it with...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
3
by: WindAndWaves | last post by:
Hi Everyone I was wondering if anyone has any great ideas on archiving. I have a database, lets say a sales database. Future transactions are really important, but past transactions are only...
4
by: Geoff | last post by:
I want to archive records from one recordset to another recordset. Not too sure of what to do in commented areas shown below. Dim Db As DAO.Database Dim Rec1 As DAO.Recordset 'Set as...
1
by: sandip | last post by:
Hi All, Can someone please help me with good and easy-to-use data archiving tools for DB2 database? Does anyone have previous experience with IBM DB2 Data Archive Expert tool? Is this a...
4
by: Paul H | last post by:
Could some one give me some pointers on basic archiving techniques? I have developed several databases but never been faced with this issue. Here is the basic scenario.. Suppose I have the...
3
bvdet
by: bvdet | last post by:
Following is an example that may provide a solution to you: """ Function makeArchive is a wrapper for the Python class zipfile.ZipFile 'fileList' is a list of file names - full path each name...
5
by: Massimo | last post by:
The iussue: Sql 2K I have to keep in the database the data from the last 3 months. Every day I have to load 2 millions records in the database. So every day I have to export (in an other...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.