kartoza / docker-postgis

Dockerfile for postgis
GNU General Public License v2.0
648 stars 317 forks source link

provide a documented way to wait for the database initialisation scripts to have completed #475

Closed adk-swisstopo closed 2 months ago

adk-swisstopo commented 2 months ago

Feature description

docker-postgis would rock even more if there was an easy way to wait for the database to be populated. When we use this container we feed it various SQL scripts via docker-entrypoint-initdb.d then we use pg_isready to wait until the database is ready. However I think there is a possible race condition where the database is "ready" and we can connect to it but the scripts have not finished running yet.

I think we can work around that by wrapping all our scripts in transactions and checking the last one succeeded. But it would be nice to have a more explicit way provided by docker-postgis. Either in the form of a second lockfile that is created after the scripts have finished running or an environment variable that ensure nothing external can connect until the scripts have finished running.

To be clear, we never ran into that race condition so it's entirely possible it does not exist but if it's not documented as such, it doesn't seem safe to rely on that behaviour.

Additional context

No response

adk-swisstopo commented 2 months ago

Looking at the implementation, I think it does the right thing and it's just a matter of updating the documentation to clarify no connection is allowed until the scripts completed.

NyakudyaA commented 2 months ago

@adk-swisstopo Feel free to do a PR with suggested wording changes.