News for hackers. Stuff that matters.
Re:AWS open-sourced Postgres active-active replication exten... by nico on Wednesday July 16, 2025 @12:54PM (#44584435)
Tangential, but related. Is there a way to have a "locally writable" read replica, ie. a secondary db that reads from a primary, but that can also hold local changes that doesn't send back to the primary?

One of the use cases is to have a development db that can get data from production or staging (and doesn't send local changes back)

What I've done usually is have some script/cron/worker run periodically to get data, either via dump or running some queries, create a snapshot, store it in S3, then have a script on the local dev code that gets the snapshot and inserts/restores the data in the local db. This works for many cases, but index building can be a pain (take a long time), depending on the data

Re:AWS open-sourced Postgres active-active replication exten... by mdavidn on Wednesday July 16, 2025 @01:15PM (#44584673)
Load the snapshot to a "pristine" local database that you never modify. Whenever you need a "reset" of your dev database, drop it, then copy the pristine database using `createdb --template`. This copies prebuilt indexes rather than rebuild them, which is much faster.
Re:AWS open-sourced Postgres active-active replication exten... by nico on Wednesday July 16, 2025 @01:39PM (#44584932)
But when loading that pristine local db from the original source, it would still create the indices and thus take a long time?

The goal is not necessarily having an easy way to reset, but rather an easy/quick way to load real data

Re:AWS open-sourced Postgres active-active replication exten... by AYBABTME on Wednesday July 16, 2025 @01:01PM (#44584510)
Just FYI that most people would recommend against doing this for legal reasons. PII information and the likes are not usually allowed to land in a staging or dev environment, for various reasons. Doing this or allowing it, is a huge liability.
Re:AWS open-sourced Postgres active-active replication exten... by nico on Wednesday July 16, 2025 @01:32PM (#44584861)
Agreed, and there’s a few ways to deal with that, like not including certain tables or excluding the data via queries when creating the snapshot

Having said that, legal exposure and risk will highly depend on what you are working on. Probably for most projects this isn’t a big deal. IANAL, this is not legal advice

Re:AWS open-sourced Postgres active-active replication exten... by xinu2020 on Wednesday July 16, 2025 @01:11PM (#44584629)
Curious about this - How would local writes conflicting with remote updates be handled? I can't think of a merge strategy working on all scenario (or even most of the time)
Re:AWS open-sourced Postgres active-active replication exten... by nico on Wednesday July 16, 2025 @01:45PM (#44584985)
Great question, I don't know. However, at least in my case, I wouldn't mind the source data always overwriting the local data. In fact, that's the way it works now when loading a newer snapshot, the local db is dropped and then re-built from the snapshot

Thinking about the developer experience though, when loading a snapshot manually, the dev knows they are overwriting their local db. However, if replication happened automatically/continuously on the background, it could lead to some really confusing/annoying behaviors

Re:AWS open-sourced Postgres active-active replication exten... by ForHackernews on Wednesday July 16, 2025 @05:38PM (#44587063)
AFAIK that is the standard behavior with a Postgres logical replication setup. There is nothing preventing you doing writes on the replica, they just won't get sent back anywhere else.
Re:AWS open-sourced Postgres active-active replication exten... by ethan_smith on Wednesday July 16, 2025 @11:26PM (#44589404)
You can use Postgres logical replication with a filter to create a one-way replica, then just disable the replication slot when you want to make local changes without affecting the primary.
Re:AWS open-sourced Postgres active-active replication exten... by nico on Thursday July 17, 2025 @11:15AM (#44594295)
> then just disable the replication slot when you want to make local changes without affecting the primary

This would be all the time, ie. in my local dev, I’d like to have an up to date (daily is ok), copy of the source db that I can modify anytime, but that everyday will sync with the source, without having to fully rebuild indices

How would you go about managing/coordinating that?