postgresqldockerdocker-volumedata-synchronization

Docker multi postgres containers with one mount point


I have two Postgres databases and I want to sync data between themes.

So far I have these two containers, exactly the same with different posts and different names.

docker container run --name='p1' -d -p 5435:5432 -v /tmp/dbs/test/:/var/lib/postgresql/data postgres


docker container run --name='p2' -d -p 5436:5432 -v /tmp/dbs/test/:/var/lib/postgresql/data postgres  

The problem happens when something changed.

If I change something in p1 like insert a row, then I can't see it in p2.

But if I kill, and run containers again, then I can see the inserted data in both of themes.

Why this is happening?
Is there a way to sync data between themes?


Solution

  • Running two postmaster processes on the same files is a sure road to data corruption. Don't do that.

    You cannot have multi-master replication with standard PostgreSQL, but you can have a read-only standby server.