# PostgreSQL database backup & restore

**URL:** <https://community.fly.io/t/postgresql-database-backup-restore/4557>\
**Category:** General\
**Created:** [March 30, 2022, 6:50pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557 "2022-03-30T18:50:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickluger](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickluger](https://community.fly.io/u/nickluger)\
**Post date:** [March 30, 2022, 6:50pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/1 "2022-03-30T18:50:17Z")

</div>

How is the status regarding PostgreSQL db backup & restore. Is there something planned/some ETA for this?

Many managed database services out there offer some kind of [PITR](https://pgdash.io/blog/postgres-incremental-backup-recovery.html) besides automatic snapshots.

I discovered [volume snapshots](https://fly.io/docs/getting-started/multi-region-databases/#listing-snapshots) but they have a an [RPO](https://en.wikipedia.org/wiki/Disaster_recovery#Recovery_Point_Objective) of 24 hours?

Also: Read-replicas don’t protect against human error or malicious events (`DROP TABLE`), as they propagate instantly. (Although having a [delayed replication](https://about.gitlab.com/blog/2019/02/13/delayed-replication-for-disaster-recovery-with-postgresql/) would work)…

We could set up all this ourselves using something like WAL-G, ([here’s](https://supabase.com/blog/2020/08/02/continuous-postgresql-backup-walg) a nice tutorial), but that binds many resources - especially to get it right and have recovery tested properly, too.

Still, one should maybe backup to an external provider like AWS S3 for increased resilience.

I think a solid production ready DB setup is a pretty important feature for Fly, because when picking a cloud provider **everything lives or dies with the database**. The location of the database determines everything else, because even small latencies add up tremendously, when doing READ-WRITE-READ patterns etc.

What’s the current recommendation for disaster recovery? Is there something on the way? What’s your experience with that?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [April 1, 2022, 11:22pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/2 "2022-04-01T23:22:21Z")

</div>

Doh, I had a draft reply all written up for you and never posted it. Here it is!

* * *

Delayed read replicas are your best bet, and what we suggest. We don’t do this automatically, but you can configure one cluster to be a delayed read replica of a second cluster. This would make a good doc! Stolon includes some settings for creating clusters that are delayed replicas of other clusters, you can probably run two [Fly.io](http://Fly.io) Postgres apps in this config: [stolon/standbycluster.md at master · sorintlab/stolon · GitHub](https://github.com/sorintlab/stolon/blob/master/doc/standbycluster.md)

Our long term goal is to “give” Postgres to a company like Supabase that is focused on a really nice dev UX for postgres itself. The launch story would be the same, but their tooling would handle things like point in time restores, forks, etc. You can use them right now with Fly apps, if you want.

The plumbing we build is meant to be general purpose. We’ve made it easy to create Postgres, but probably won’t ship Postgres specific infrastructure. We will be exposing volume snapshot settings soon, though. And potentially incremental volume snapshots.

---

<div class="post-metadata">

**Author:** ![nickluger](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickluger](https://community.fly.io/u/nickluger)\
**Post date:** [April 2, 2022, 6:03am UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/3 "2022-04-02T06:03:55Z")

</div>

Hey Kurt,

thank you for your comprehensive answer, that helps us move forward and set up a solid strategy.

I have to mitigate my statement about latency, though, as latency in some regions between AWS and Fly (e.g., `fra`) seems perfectly sufficient for distributing hosting between providers, in case that’s what someone wants to do.

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [April 2, 2022, 3:35pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/4 "2022-04-02T15:35:44Z")

</div>

Yes, good point! There are many regions with \<1ms latency between us and AWS. Generally, if they’re in the same city they work really well.

---

<div class="post-metadata">

**Author:** ![spiffytech](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/spiffytech/32/2414_2.png) [@spiffytech](https://community.fly.io/u/spiffytech)\
**Post date:** [April 20, 2022, 8:31pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/5 "2022-04-20T20:31:48Z")

</div>

Are there options for me to set up point-in-time restores for Fly’s Postgres? All of the off-the-shelf tools I see want either to either run an agent on the Postgres server or SSH into it.

---

<div class="post-metadata">

**Author:** ![binajmen](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/binajmen/32/13396_2.png) [@binajmen](https://community.fly.io/u/binajmen)\
**Post date:** [May 12, 2022, 7:24pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/6 "2022-05-12T19:24:58Z")

</div>

> [@kurt](#):
>
> Our long term goal is to “give” Postgres to a company like Supabase that is focused on a really nice dev UX for postgres itself. The launch story would be the same, but their tooling would handle things like point in time restores, forks, etc. You can use them right now with Fly apps, if you want.

Could you elaborate on that? Are you suggesting to look at Supabase for the Postgres hosting? What would be the consequence regarding the egress traffic cost? Would love to know more on your long-term strategy about Postgres, if you have any big plans 🙏

---

<div class="post-metadata">

**Author:** ![joelmoss](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/joelmoss/32/3488_2.png) [@joelmoss](https://community.fly.io/u/joelmoss)\
**Post date:** [May 13, 2022, 12:00pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/7 "2022-05-13T12:00:12Z")

</div>

Yes, I would also like to know about this “giving” of postgres. That would surely affect latency between our apps and the DB if the DB is hosted elsewhere? ie. Supabase.

I’m currently evaluating heroku alternatives, so need to know things like this.

---

<div class="post-metadata">

**Author:** ![lessless](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lessless/32/3503_2.png) [@lessless](https://community.fly.io/u/lessless)\
**Post date:** [May 14, 2022, 11:51am UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/8 "2022-05-14T11:51:09Z")

</div>

@kurt @nickluger, it seems that it’s possible to create volume snapshots manually and hence have a “simple” app to apply a custom backup strategy.

For example, create snapshots every 6 hours and keep snapshots only for the last three months.

That’s if snapshots are not removed automatically.

---

<div class="post-metadata">

**Author:** ![nickluger](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nickluger](https://community.fly.io/u/nickluger)\
**Post date:** [May 14, 2022, 5:32pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/9 "2022-05-14T17:32:36Z")

</div>

Yes, that’s possible.

For us, it’s not an acceptable solution, though, as we have a shorter RPO, i.e., we cannot tolerate potential data loss of worst case 6 hours. Depends on the use case, of course.

We decided to go with AWS RDS in the end as they have PITR with an RPO of 5 minutes, everything fully managed for a reasonable price. Latency is not as low as within the Fly network, but sufficient for us.

---

<div class="post-metadata">

**Author:** ![lessless](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lessless/32/3503_2.png) [@lessless](https://community.fly.io/u/lessless)\
**Post date:** [June 2, 2022, 10:21am UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/10 "2022-06-02T10:21:44Z")

</div>

We are taking the same direction 🙂

---

<div class="post-metadata">

**Author:** ![qqwy](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/qqwy/32/7475_2.png) [@qqwy](https://community.fly.io/u/qqwy)\
**Post date:** [June 3, 2022, 9:08pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/11 "2022-06-03T21:08:08Z")

</div>

Some of you might already be aware, but others might find this interesting as well:  
I recently [opened a PR](https://github.com/fly-apps/postgres-ha/pull/71) on Fly’s postgres-ha repository, to add support for wal-g to Fly’s postgres image.

Feedback from people savvy with wal-g or the streaming backup/restore space in general would be very welcome!

---

<div class="post-metadata">

**Author:** ![Elder](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@Elder](https://community.fly.io/u/Elder)\
**Post date:** [August 19, 2022, 8:45pm UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/13 "2022-08-19T20:45:52Z")

</div>

@qqwy Awesome! Any chance it will get accepted?

---

<div class="post-metadata">

**Author:** ![qqwy](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/qqwy/32/7475_2.png) [@qqwy](https://community.fly.io/u/qqwy)\
**Post date:** [September 2, 2022, 10:59am UTC](https://community.fly.io/t/postgresql-database-backup-restore/4557/14 "2022-09-02T10:59:04Z")

</div>

It was accepted and merged just now. you should be able to run `fly image update` on your DB app to pick up the changes, and then start using it as per the instructions in the PR.

🥳
