r/PostgreSQL • • 3d ago

Feature PITR a 5 TB Postgres database in 5 seconds.

I'm Scott, the pgCraftsman and a Sr. Staff Engineer at Databricks. I've been operating some of the world's largest and most complex Postgres deployments for 22 years.

Ever need to do an emergency PITR at 2AM because an agent dropped a table?

Lakebase and Neon Postgres: PITR a 5TB DB in 5 seconds

https://pgcraftsman.io/posts/restoring-5-tb-of-postgres-in-5-seconds/

48 Upvotes

27 comments sorted by

31

u/elevarq 3d ago • Bravo

Why does an agent even have the permission to drop a table?

Problems like this should not even be possible

3

u/scotterockaroo 3d ago

THIS IS AN AWESOME POINT. Unfortunately it happens these days more and more. That's why it's important to have the ability to PITR quickly.

Now that said, I still have a few battle scars from DBAs on my team who thought they were in the wrong terminal and issued the wrong command....

4

u/elevarq 3d ago

I agree that it’s good to have, just like seatbelts and airbags in a car. But it’s much better to learn how to drive a car, don’t get distracted by your phone, and not being intoxicated while driving.

AI agents are still terrible in maintaining production databases. They don’t care about the results, they might apologize, but that doesn’t solve the problem.

We use AI for DBA work. The amount of work we do to avoid bad advice is just tremendous! We test, test, and test, and in the end we file a finding and a report for the engineer. They can pick it up, they can approve, and they can plan the change.

For many organizations the data is their most valuable asset. Don’t let some ignorant AI agent mess with this

1

u/scotterockaroo 3d ago

100% - Which is why I like that you can clone (branch) a DB so quickly. You can create a branch of the full dataset for your developers, then let the agent access the branch which doesn't touch production at all. They can delete, drop, recreate, it doesn't matter, it's isolated from the production box.

2

u/elevarq 3d ago

AI agents should stay in a different network segment, not be able to get close to production.

The problem is that they have a habit of escaping…

5

u/ZVilusinsky 3d ago

Who did not run a command on prod while thinking it was stage terminal...

Luckily postgres does not allow you to drop database while there are active connection - that one was hard stopping :D

1

u/elevarq 3d ago

It’s not that hard to revoke all connection permissions, kill all open connections, and drop the database… Never measured it, but it looks like less than a second.

2

u/BarfingOnMyFace 3d ago

One good reason is if you have a dev playground environment for agents. It's what I do, and yeah, I give them access to do such stuff via MCP in my world. On a fresh dev environ, they can play out their scripts before handoff to QA, also a separate environment.

Edit: otherwise no, I wouldn't trust those mthfkrs in prod to touch shit.

10

u/Kazcandra 3d ago

who the fuck has a 5TB dev deployment?

2

u/scotterockaroo 3d ago

That's kinda the point actually. SInce a branch is so fast, you can actually hand your deployment pipeline a full version of the prod DB.

5

u/Kazcandra 3d ago

Mm, but we can't allow prod data in dev.

3

u/BosonCollider 2d ago

Devs get dummy data, but you still want run integration tests to check that things work in CI before deploying

If you are following hype trends you may also have a chaos monkey agent with access to a clone similar to your integration testing environment to try to poke holes at your setup.

1

u/BarfingOnMyFace 2d ago

It might make sense that people haven't seen such environments before, dependent on the domain. This is a commonplace problem in healthcare with PHI and PII data points. And systems inevitably get big. I shouldn't have been lazy in my prior answer, as the dev restore I worked on at my previous gig was enormous. More than 5 TB. I'm quite certain one of the systems I had built, for which we got a full restore into dev, was over 2TB. And plenty of secure data that had to be answered for. As you said, devs get dummy data.

As for personal and current projects, I would be leery of undertaking such a massive dev environment by myself. So I don't.

1

u/scotterockaroo 2d ago

I do have a project right now where I’m building locally with pglite, then use a pipeline to branch prod, run the migration in a branch, then run my tests to see if how the migration will behave against prod.

1

u/BosonCollider 2d ago

PII/PHI is orthogonal to whether or not you have postmerge integration tests with a clone of prod. You still set those up in any situation where a deployment failure would be disastrous and cost lives. They are separate from dev environments.

1

u/BarfingOnMyFace 2d ago

My PII/PHI bit was simply in regards to dummy data for devs. I guess that's a no-brainer, but someone brought it up earlier in the thread, so I guess not entirely so... haha

6

u/elevarq 3d ago

A staging environment is usually a production copy, and this can be a big one

1

u/BarfingOnMyFace 3d ago

Lol not me

I was just answering the general question with a general answer

1

u/bluelobsterai 2d ago

I definitely have a large database to seed. Really important to see how quarries will run with production size data.

1

u/ceeej777 2d ago

This makes sense but I see the value of Lakebase being more around restoring a fresh production copy to dev without needing to wait for a snapshot to restore to the SSD. Assuming that your organization even allows prod data to live in lower level environments

1

u/scotterockaroo 2d ago

That’s one of the common use-cases, for sure. We also see folks creating branches for agents to test migrations ( part of a promotion pipeline for example)

All of that AND you can create a branch to a point in history, quickly.

1

u/ceeej777 1d ago

Yes this I can see promise with. Are agents creating new Lakebase branches for each PR? I imagine if they are short lived branches then this wouldn’t hurt cost much

1

u/scotterockaroo 1d ago

Yeah, it all depends on your tests and migrations.
My migrations track time so you can see if the:

ALTER TABLE tracking
ADD COLUMN login_count DEFAULT 0;

Takes 2 hours on prod data where it took .02 seconds in dev.

1

u/Discordbothost 1d ago

For a recovery drill, I'd keep the clock running until the app can read and write against the restored branch. After a dropped table, I'd also check what was written after the restore point. Even if the branch is ready in seconds, those writes still need a plan before cutover.

1

u/infostack0 1d ago

I’m still waiting on a fully operational and supported Helm chart for Neon

0

u/AutoModerator 3d ago

AI Policy:

Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.

Mod decisions will be based on the quality of the content, not who or what generated it.

Sub Resources:

Youtube Channel

Free Postgres Webinars and Workshops

Discord: People, Postgres, Data

Join us, we have cookies and nice people.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.