dbTalk Databases Forums  

Recommended Procedure for Archiving Table Data

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss Recommended Procedure for Archiving Table Data in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sally Ruggero
 
Posts: n/a

Default Recommended Procedure for Archiving Table Data - 10-29-2004 , 02:42 PM






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

Reply With Quote
  #2  
Old   
Joshua D. Drake
 
Posts: n/a

Default Re: Recommended Procedure for Archiving Table Data - 10-29-2004 , 03:21 PM






Sally Ruggero wrote:

Quote:
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



Quote:
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 (AT) commandprompt (DOT) com - http://www.commandprompt.com
PostgreSQL Replicator -- production quality replication for PostgreSQL



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.