1

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!

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

got it. an additional question, is it good to use Postgres+PVC+PV as database in production? or should I use AWS RDS or Google SQL?
If you are asking whether you should run PostgreSQL yourself or use a database hosted somewhere, both is ok. When running PostgreSQL yourself, you have to monitor it and take care of it, but you have more freedom and more options than with a hosted database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.