Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

data archiving Expand / Collapse
Author
Message
Posted Friday, August 22, 2008 10:27 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 15, 2009 12:57 PM
Points: 32, Visits: 114
Hi members,

I have some tables in my database and in each table every month fresh data gets added to the previous data. The approximate size of the data that get added to the tables is 1.5 - 2 million records and my Project Manager wants to archive the data. She wants only 6 months of data in main table and rest of the data should be archived to respective archive tables.

Can anyone explain me how to archive the data in a table and what are the methods in archiving the data. Please suggest me along within an example and also explain me how to access that data which is archived later point of time when all my procedures initially referring to the main table.

Thanks in advance

sai
Post #557514
Posted Friday, August 22, 2008 6:31 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:22 AM
Points: 2,832, Visits: 8,514

This sounds a bit like a generic homework assignment ..... so here's a generic answer

1) Copy records older than 6 months into archive tables.

insert into Archive_table select * from Prod_table
where Archive_date < DATEADD(MONTH, -6, (getdate()))

2) Delete records older than 6 months from production tables.

delete from Prod_table
where Archive_date < DATEADD(MONTH, -6, (getdate()))

3) Change your stored procedures to point to the archive tables.



Post #557690
Posted Sunday, August 24, 2008 11:58 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
You may want to research table partitioning.
Table partitioning allows for the fastest and cleanest way to achive data archiving and purging.


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #557860
Posted Sunday, August 24, 2008 4:41 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:25 PM
Points: 35,372, Visits: 31,925
Sai,

Once you get the intial archive done, how many rows would need to be archived on a daily basis? Also, please post the CREATE TABLE statement for the table involved as well as what the indexes are... you'll get a much better answer. ;)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #557889
Posted Monday, August 25, 2008 7:51 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 12, 2013 2:03 AM
Points: 79, Visits: 211
PaulB (8/24/2008)
You may want to research table partitioning.
Table partitioning allows for the fastest and cleanest way to achive data archiving and purging.


Sorry, I am curious how the table partitioning affect the database, if the database is running 24/7. I found all the example in MSDN is cold archiving, I once tried to use the hot archiving (dynamic queries for table partitioning to let it running weekly/bi-weekly/monthly) but the table still get locked, thought the partition switching is pretty fast.
Post #558143
Posted Monday, August 25, 2008 7:58 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 10:36 AM
Points: 1,199, Visits: 574
You can go for the sliding window partitioning. See the whitepaper by Kimberly Tripp on this - http://msdn.microsoft.com/en-us/library/ms345146(SQL.90).aspx

Post #558149
Posted Monday, August 25, 2008 8:10 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 12, 2013 2:03 AM
Points: 79, Visits: 211
Yes, I have gone thru' that. That's what I meant cold archiving (predefined values). I have tried to do something like this:

SET @SQLString = N'ALTER PARTITION SCHEME [' + @archiveScheme + '] NEXT USED [FileGroup_MDPTSP]'
...
SET @SQLString = N'ALTER PARTITION FUNCTION ' + @archiveFunction + '()
SPLIT RANGE ('''
SET @strTEMP = CONVERT(NCHAR(8), DATEADD(day, 7, @dtStart), 112) -- +7 next partition
SET @SQLString = @SQLString + @strTEMP + ''')'
..
SET @SQLString = N'ALTER TABLE ' + @factTable + ' Switch Partition 1
TO ' + @archiveTable + ' Partition 2 '
...
SET @SQLString = N'ALTER PARTITION FUNCTION ' + @factFunction + '()
SPLIT RANGE ('''
SET @strTEMP = CONVERT(NCHAR(8), DATEADD(day, (7 + 1) , @dtEnd), 112) -- +1 bcoz of this is executre 2nd last day
SET @SQLString = @SQLString + @strTEMP + ''')'

in order let it work dynamically. Is that way right?
Post #558157
Posted Monday, August 25, 2008 10:19 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:25 PM
Points: 35,372, Visits: 31,925
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #558582
Posted Tuesday, August 26, 2008 9:20 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, June 12, 2013 2:03 AM
Points: 79, Visits: 211
Jeff Moden (8/25/2008)
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

Hi Jeff, are you answered to my question? 20,000 rows ? what about 200, 000 or even 2,000,000 rows?
Post #558984
Posted Tuesday, August 26, 2008 6:21 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:25 PM
Points: 35,372, Visits: 31,925
gan (8/26/2008)
Jeff Moden (8/25/2008)
If the clustered key is set by date or, perhaps, identity and the identity column is indicative of entry order, then sectional deletes (or insert to archive, delete from source) of, say, 20,000 rows at a time will work just fine.

Hi Jeff, are you answered to my question? 20,000 rows ? what about 200, 000 or even 2,000,000 rows?


Yep... answering your question and the OPs question... if the system is a 24/7 operation and the table you want to archive is in use, then trust me and do it 20,000 rows at a time. Or, not... simple delete with very few indexes runs very fast and will probably delete 2 million rows, no problem. Oh, but there's that 24 hour thingy getting in the way and since the table is probably indexed for use and maybe has a clustered index that isn't exactly chronilogical, it could take several hours to delete just 2 million rows. Only way to know for sure is to try it... run the delete for 2 million rows... if it takes more than about 10 minutes, you should probably stop it and rollback. If it takes less than 10 minutes, then problem solved. By the way, there will be some serious blocking on the table during the 2 million row delete... I wouldn't try it on a real busy 24/7 system that has short SLA requirements. :)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #559285
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse