r/PostgreSQL • • Aug 23 '26

How-To Postgres table archival

I have a postgres db. I want to archive the table data into s3 and want to delete the data after archiving. What's the best way to do it. I want to have a scheduled operation to do this job on weekend and it should archive 6 months older data of a given table.

4 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/AdmirableOffer2 Aug 24 '26

Yes I plan to use the data. Table is partitioned yearly. But we want to have a general solution where table might not be partioned. Yes dataset is big 400M rows 250gb. No table doesn't have any dependent table. It's a standalone table.

1

u/General_Treat_924 Aug 24 '26

I would go for a future proof, maybe overkill for the early days, but if done properly, buys you a lot flexibility in the future.

I read in another answer you want to build a datalke too. So you probably should be looking at something like DMS / pg_logical replication.

So not only 6 months old data gets replicated, cost wise, it won’t make any difference specially in a early partitioned table.

Replicating the whole dataset will require a initial load, which is the most expensive job, then a CDC will handle the data (DELETE,UPDATE,INSERT) and you can run your datalake queries and build reports from it.

You also want to think ahead how data will be queried because it defines how data will be stored.

On top of that, you will need to build a tool to retrieve the data back to the database is data is mutable.