can many Postgres processes run with the same data directory?

11/28/2018

enter image description here

I have an application running in multiple pods. You can imagine the app as a web application which connects to Postgres (so each container has both app and Postgres processes). I would like to mount the volume into each pod at /var/lib/postgresql/data so that every app can have the same state of the database. They can read/write at the same time.

This is just an idea of how I will go. My question is: is there any concern I need to be aware of? Or is this the totally wrong way to go?

Or will it be better to separate Postgres from the app container into a single pod and let the app containers connect to that one pod?

If my questions show knowledge I lack, please provide links I should read, thank you!

-- Yi Feng Xie
kubernetes
postgresql

1 Answer

11/28/2018

This will absolutely fail to work, and PostgreSQL will try to prevent you from starting several postmasters against the same data directory as good as it can. If you still manage to do it, instant data corruption will ensue.

The correct way to do this is to have a single database server and have all your “pods” connect to that one. If you have many of these “pods”, you should probably use a connection pooler like pgbouncer to fight the problems caused by too many database connections.

-- Laurenz Albe
Source: StackOverflow