-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostgreSQL not starting correctly if image already contains data #5359
Comments
A more generic wait strategy for jdbc. i.e Postgres has different output when the container database has data that doesn't match with the default wait strategy. See gh-5359
Hey @TomCools, sorry for answering so late, especially considering you did such a great job authoring the issue 🙂 We already have a The JDBC strategy sounds intuitively like a good idea, but the funny thing is, that we used to implicitly have it in the past and it would lead to a race condition, because of the restart behavior of the official postgres image (strategy could sometimes succeed before the restart). Since @eddumelendez started to look into this as well, depending on the image version, we might be able to identify better and more stable log message readiness indicators. |
Busy conference life eh? 🙂 On topic: |
A more generic wait strategy for postgres. i.e Postgres has different output when the container database has data that doesn't match with the default wait strategy. First evaluation looks for (db doesn't contain data): * PostgreSQL init process complete * database system is ready to accept connections Second evaluation looks for (db contains data): * PostgreSQL Database directory appears to contain a database * database system is ready to accept connections See gh-5359
A more generic wait strategy for postgres. i.e Postgres has different output when the container database has data that doesn't match with the default wait strategy. First evaluation looks for (db doesn't contain data): * PostgreSQL init process complete * database system is ready to accept connections Second evaluation looks for (db contains data): * PostgreSQL Database directory appears to contain a database * database system is ready to accept connections See gh-5359
Hi everyone. Reporting this after my TestContainers talk at Jfokus and talking about this with @kiview.
Description
If the image you are running with already contains data in the database (because it was built for that specific reason... with built in testdata or with fully ran migrations), then the TestContainer doesn't recognize correctly that the database has started.
The reason for this is the default WaitStrategy, which waits until "database system is ready" is logged 2 times.
This waiter is correct when running with an empty database. Starting a new container like below results in a logfile with 2x that log line.
Results in the following logs: postgresdb-no-data.txt
However, when you build a custom image which includes some data (like I have done below), then the logs will only contain "database system is ready" a single time.
postgresdb-with-data-test-logs.txt
Workaround
The way I have worked around this for now, it to change the default waiter with a custom one that only waits until the log has passed a single time.
Possible solution directions
The contribution documentation states that, in order for something to become a module, it needs to "add value", where one of the examples given is:
Given that statement, I'd expect the PostgreSQLContainer to be bootstrapped with a waiter that can handle both images with or without data present.
Possible ideas:
I'm willing to help implement this. If no solution is implemented, I'd say we at least document the workaround on the PostgreSQL page.
Kind regards,
Tom
The text was updated successfully, but these errors were encountered: