r/SQLServer • u/Anyone-UnderstandMe • Mar 06 '26
Question Archiving old data from a live SQL Server database to improve performance - looking for architecture feedback & any war stories or pitfalls
Hi everyone,
I’m currently working on a system where our SQL Server production database contains several years of historical data along with the current live operational data. This database is used by multiple backend services as well as a web application. Over time, as the data volume has grown, we’ve started noticing query timeouts and increased resource consumption.
We explored improving things through indexing, but many of our tables are both write-heavy and read-heavy, so adding more indexes begins to slow down insert and update operations. Because of that, indexing alone doesn’t seem like a sustainable long-term solution.
So I’m now considering implementing a cold data archiving strategy, and I’d love to hear thoughts from others who have dealt with similar scenarios in production.
Current system overview
The live database stores operational data such as workflow logs, alerts, and processing records. A simplified version of the flow looks something like this:
• A backend service calls an external API and fetches logs or alert data
• The data gets inserted into our database
• Workflows are triggered based on these inserts (tickets are created and assigned to business stakeholders)
• Stakeholders interact with these tickets and complete the workflow
• Throughout this lifecycle, multiple logs and updates related to that process are stored in the database
Our backend services continuously process these records and maintain several related log tables, while the current web UI directly queries the same database to display data to users.
As you can imagine, over several years this has resulted in fairly large tables containing both active operational data and older historical records.
Proposed approach
The idea I’m exploring is to separate hot operational data from cold historical data:
• Define a retention window in the live database (for example, 100 days)
• Create a separate archive database on the same SQL Server instance
• Implement a scheduled job/service that runs once per day
The job would perform the following steps:
• Identify records older than the retention threshold
• Move those records into the archive database
• After confirming successful insertion, delete those rows from the live database
With this approach:
• The live database contains only recent operational data
• The archive database stores older historical records
• The current application continues to use the live database
• A separate lightweight reporting web application can be used to query archived data when needed
Goals
• Reduce the size of tables in the live database
• Improve query performance and reduce timeouts
• Keep historical data accessible for reporting when required
• Avoid disrupting the existing operational workflows
Questions for those who have implemented similar solutions
• Does this sound like a reasonable architecture for long-running production systems?
• Are there any common pitfalls when moving data between live and archive databases like this?
• Would you recommend implementing this through batch jobs, table partitioning, or some other approach?
• Any best practices around safely deleting data after it has been archived?
I’d really appreciate any advice, lessons learned, or war stories from people who have handled large operational databases with long-term data retention requirements.
Thanks in advance for your insights!
10
u/Intrexa Mar 06 '26 edited Mar 06 '26
How much data we talking about? What are the actual business requirements?
EDIT:
I mean this no offense, but what you described as a workflow is bog standard. If you are coming to Reddit with that workflow, the answer is probably query tuning.
6
u/chandleya Mar 06 '26
Every single situation is different. Schema has a huge effect on this.
4
u/everydaynarcissism Mar 06 '26
Partitioned tables / indexes would be a good option if you don't want to rewrite your application or write a new one to be able to access a secondary database. That sounds like a lot of work and testing. You could put the archive database files on lower tiered storage to save some money.
2
u/quebecbassman Mar 06 '26
The first strategy is to pinpoint the offending queries, and fix them.
If you really want cold storage here is what I did once: I created a job that ran once a year, that was copying (backup+restore with a name including the year) the live database, make that database read-only, and then deleting the old records in the live database. The services/apps needed a way to choose which database it was connected to.
1
u/SirGreybush 1 Mar 06 '26
Only caveat is if you / your company don't own the App + DB; ie a bought software like INFOR Syteline ERP, that you want to optimize because the eBOM table has over 100M records and the Quotes table has over 5M, etc.
Ideally in bought/rented software you never directly delete, unless you go through a Support Ticket with the software manufacturer, or, use a tool they provide. If you delete directly, and screw things up, the ERP company won't support you unless you lie, and since most ERP software use AutoIncrement in their tables, any deletes will stick out and it will cost you a lot of $$$$ to fix. So be cognizant of this.
Start by making an ODS (operational data store) which is a 1-to-1 copy of the main DB, but on a different server, that this server is optimized for reporting. Less cores, more RAM, larger disks. Or put it in the Azure Cloud. Essentially you add columns to manage SCD2 (you need this!!!) in all the tables you want history for, or, simply remove all indexes, then make a single index on each table Clustered Column Store. Let the tables naturally grow.
SCD2 - you need to track changes, answer W5, and very important, capture deletes, and simply use IsDeleted (bit) column in the ODS database. You'd want IsCurrent (bit), ExportDateTime also, to properly track history.
I would use the CDC function of MS SQL - and thus avoid using Triggers. A simple SSIS or even Python with the proper library (I use SSIS) or a commercial ETL/ELT tool can read CDC structures. Be aware, this will slow down maybe 10% the main DB speed. However, you gain usually because the Analysts will use the ODS DB & Server instead of the live prod server.
Then you make scripts to export data (from the CDC), send the files over, then import the files. Frequency of this you decide. Once per hour is good. (S)FTP(S) is your friend if not "on-prem". Simple to setup a secure FTP server, and you can use an Azure Datalake container + folders too. Extra costs, but more security.
The beauty of ODS is that the users, with either Excel, PowerBI, Crystal Reports, simply change the "ServerName" property, everything else remains as-is. Extra column names are ignored by these reporting tools, unless the Analysts are SQL-for-Dummies trained and always do Select * in all their queries.
Resume:
Use CDC, a new server, do an ODS setup. Later, you can use the ODS to build either a DataVault or DataWarehouse, or simply use the ODS to send Delta Data to Snowflake into a raw (aka bronze) layer, and let your power user do Silver & Gold layers, instead of using PowerBI to do dimensional crunching.
Depends on the size of your company, how many analysts. Usually past 3 business analysts that use PowerBI, it is worthwhile to use Snowflake. Else, keep it "on-prem". Snowflake adds costs that is only worthwhile with a lot of users, and if you want suppliers & customers to view their data on the cloud in a secure fashion.
1
u/alexwh68 Mar 06 '26
Sounds to me like you need to establish why things are slow, memory, cpu and disks, how busy are they? What are the specs?
If you have queries that are timing out, look at those queries, query plans are a start, seeks rather than scans are the basic goal once we get into large datasets. Review the current indexes are they all being used, have the statistics been updated, do the indexes need to be rebuilt.
Partitioning of data eg archival rarely provides the wins expected in this situation, my guess is ram, cpu or disks, are busy, that busy can be old hardware like spinning rust compared to ssd/nvme drives, cpu’s not up to the job, not enough memory.
When I am tasked with these types job, I look at data volumes in each table, identifying tables with large row counts first, then I look at the queries that are problematic, query plans for those queries, covering and composite indexes done right can make a massive difference, the order of the fields in a composite index can have a big baring on the performance.
Look at the disk queue lengths this often tells you of the disks are struggling with the tasks.
1
u/SirGreybush 1 Mar 06 '26 edited Mar 06 '26
I can't stress enough, use a different server for the destination historical (aka ODS) database. Azure serverless works really well, you can also make an Azure VM + MSSQL core lic, or simply output to a DataLake container + folder(s), then use the DL to import into Snowflake.
If you keep everything on the same server to save $$$ you will absolutely regret it, your server performance will greatly suffer, and prod users will blame "you" - so make sure you are blameless.
If need be, SQL Express is free for prod use, and the real limit (worth mentionning) is the 10g database size, and not an issue if you make a lot of DBs (on a different server machine/vm) and use Clustered Column Store and no other indexes. 90% table size redux on avg, so will keep the .mdf / .ndf / .ldf very small. Use SIMPLE recovery model.
This is a super secret trick / hack. This is akin to using (100% free) DuckDB on a Linux VM, if internally nobody has Linux experience for internal support, Express should be considered. Won't be as fast, but, it's reporting or consulting history. For humans, this is good enough.
1
u/Naive_Moose_6359 Mar 06 '26
Temporal tables may be a fit (using columnstore for the history table)
1
u/Better-Credit6701 Mar 06 '26
We had a rather large databases (around .7 tb) that had a transactional database that broke out with more details was a couple of tb. Used car company with over 150 lots, database kept all details including payments, payment history, make/model, contract, taxes associated with the car repo, write offs ... In the transactional database, it would break it down into debits and credits. Example would be a payment amount paid, late fees, statistical all balancing out. Lots of data, some dating back decades.
Two main servers, one for the transaction side that the application used and that data was replicated via transactional replication to the other server that we would use as a report server. That way data was the same on both servers at any time and reports, some very heavy wouldn't have an effect on the end used trying to make a sale or car payment. Big reports would run on SSRS through jobs through the agent and sent out before business hours. Interest would be calculated on the first server on hundred of thousands of accounts and replicated to the report server starting at midnight. Transactions would also run sending the updated details to the transaction database. Originally the database with the transactions were going to be the report server but that didn't last long before discovering that wasn't going to work.
Throw in a log shipping server and a witness server and that was pretty much it. Ran like a charm and had around 2,000 machines hooked up to it at any given time making sales, taking payments, writing notes about customers (those were fun). Well, until people made mistakes like accidently repoing a car where I would have to write long queries of around a couple of thousand lines long to reverse it. That happened often. Plus had to check it for fraud which amazingly used car salesman aren't always trustworthy.
1
u/PossiblePreparation Mar 06 '26
I’ve seen this time and time again and it always leads to a complex system that goes wrong constantly and not really solving the original problem.
Go back to step one and identify where your time is really going. Then tune it. Hire experts if you need to.
1
u/drunkadvice Mar 06 '26
I think the term you’re looking for is “time based sharding.” I’m borrowing the term from MongoDB. But searching for SQL server solutions might turn up some info.
1
u/BigHandLittleSlap Mar 06 '26
If you need to "archive" data and/or have different indexes on stale data, then partitioning is your friend. It's relatively transparent to applications, and hence can be implemented by the DBA alone.
Different row/page compression settings can be applied per partition. Compress historical data to death. Don't forget to also compress the indexes, which should also use matching partitioning boundaries.
Similarly, filtered indexes can work really well to reduce the volume of data stored on disk.
Columnstore indexes can dramatically speed up queries over lots of historical data, especially in combination with filtered indexes, as they can "cover" a huge range of queries that might not be possible for the DB engine to optimise using filtered indexes.
I would advise against splitting the database outright. "There be dragons".
1
u/SeaMoose86 Mar 07 '26
If you’re not using a pre configured cloud craptastik sql server that starts with “A” look at partitioning, it will do exactly what you want without forcing you to move data around. As others have said 800Gb is a tiny database…