service/start-odk: expose postgres connection errors & allow failure - #2054
Conversation
Wicher and I did discuss |
|
That understanding is just based on Wicher's comment, I haven't actually confirmed it myself. |
|
@matthew-white thanks for the explanation. In light of that discussion, I think either: A. the messaging needs updating:"waiting for PostgreSQL to become connectable to..." is accurate for B. switching to
|
|
Not sure if this is a good idea, but what about an option C of using both? Using |
The current Switching to
A hybrid approach could look something like: log "waiting for PostgreSQL to become connectable to..."
while ! pg_isready --quiet; do
log "sleeping 1 second waiting for a database connection"
sleep 1
done
log "testing database connection..."
if ! psql --no-password --command ""; then
sleep 1 # reduce thrashing
exit 1
fioutput: This will still restart the container after failure. Per the comment at #1671 (comment):
If avoiding restarting the container is an explicit goal, then I think this PR should be closed and replaced with one which:
|
I feel like I'm getting to the limit of my knowledge of Docker best practice. Wicher seems to have wanted to avoid restarting the container. Is that a good idea / a beneficial approach? If so, I like the idea of exploring an alternative PR that corrects log messages and stops swallowing errors. |
Probably not. If the database is available, then presumably the hostname is correct. If the connection fails due to other misconfiguration (db name, username, password) then this can be resolved by:
Any changes made via 1 will only be available once the container has restarted. Additionally, any healthchecks looking at container liveness or lifetime won't see any problems with a container that never restarts on connection failure. |
|
Sounds good, I'm convinced that we don't need to avoid restarting the container. 👍 I kind of like the look of your hybrid approach above. I like that it fails fast, before reaching "running migrations.." Do you have a preference between the current approach of this PR vs. a hybrid approach? |
I prefer this PR as it's less code. Comparing the failure messages, I don't think there's much in it:
If the |
|
@matthew-white if the PR direction is accepted, I'll update the title to:
|
Let's go with that then. 👍 I don't have a strong preference for the hybrid approach. I agree that the error messaging is pretty similar either way. |
psqlwithpg_isreadyWhat has been done to verify that this works as intended?
☑️ if
pg_isreadyis missing, it fails with:☑️ If host is incorrect if fails with:
☑️ If database name is incorrect if fails with:
☑️ If username is incorrect if fails with:
☑️ If password is incorrect if fails with:
Why is this the best possible solution? Were any other approaches considered?
See: https://www.postgresql.org/docs/current/app-pg-isready.html
How does this change impact users? Describe intentional behavior changes from code updates. What are the regression risks?
Low chance of regression, but perhaps the current approach is doing something non-obvious.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.