I have set two postgresql docker containers to write to a mounted nfs volume at /var/lib/postgresql/data/ in a Kubernetes Cluster.
I noted that new changes are written correctly but data written by one container does not reflect on the database of the other container.
On deleting the pods/containers and recreating other two containers, the new containers do not reflect data in the database that was contained in database of previous containers even though the data files do exist.
Why does this happen?
In short, you can't share the file system between 2 postgres instance.
Binding 2 instances to the same volume is referred as Shared Disk Failover (ref): the second instance is a backup and should only be put in use after the first one stops. The pair is by no mean to be used together, doing so will cause "severe data corruption".
If you are looking for ways to speed up database read / write, search for replication and sharding.