docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.17k stars 1.13k forks source link

Skip postgres restart on first run #1232

Open arvenil opened 5 months ago

arvenil commented 5 months ago

Hi, we are using docker images with testcontainers. Each time new container is created, the db is initialized, migration scripts are applied and postgres server is restarted, adding around 25-50% startup time of whole container. This multiplied by hundred containers adds unnecessarily few hundred seconds. I've conducted some tests with pre-initialized database and the startup time significantly dropped, but that's really tricky to be done.

Any chance we could get a optimization setting for tests, to skip this server restart?

tianon commented 5 months ago

See https://github.com/docker-library/postgres/issues/929#issuecomment-2071146443 for somewhere I was answering something else recently, but I think my explanation there is probably helpful for explaining why what you're asking for isn't something we can reasonably accomplish with stock PostgreSQL, specifically:

We can't run SQL commands against PostgreSQL (generally) unless it is running and we have an appropriate method of access, and we can't start up PostgreSQL as the container's "PID 1" and still run more code reliably (nor can we start it and then "graduate" that instance to be PID 1)