-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make it easy to wait for connection #880
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
Comments
You can grep for the line "PostgreSQL init process complete; ready for start up." $ docker logs postgres
. . .
PostgreSQL init process complete; ready for start up.
2021-09-10 16:28:37.737 UTC [1] LOG: starting PostgreSQL 13.4 (Debian 13.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-09-10 16:28:37.739 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-09-10 16:28:37.740 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-09-10 16:28:37.743 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-09-10 16:28:37.750 UTC [66] LOG: database system was shut down at 2021-09-10 16:28:37 UTC
2021-09-10 16:28:37.758 UTC [1] LOG: database system is ready to accept connections
[node2] (local) root@192.168.0.18 ~
$ docker logs postgres 2>&1 | grep "init process complete"
PostgreSQL init process complete; ready for start up. |
Indeed, the "right" solution is going to depend entirely on your target environment and available tools -- there are a lot of solutions to this problem (and even varying definitions of "ready"), so we cannot reasonably provide a standard bit of guidance. For some, the port listening is sufficient (which is easy to test). For some, looping on something that tries to connect with a |
@tianon any working solution that will replace the text "wait for DB" will do. Otherwise the instructions are not helpful. |
@wglambert I've seen the links, and they don't solve the usability problem of choice. Just a single scenario that works without human supervision would suffice for the hub. |
The FAQ says this.
I doubt that these many users have as much unique ideas, Instead FAQ could just list all the common sense cases with links to corresponding examples in https://github.com/docker-library/healthcheck.
Even if there are more, I doubt there are more than 10 cases to fit in the list. |
It took a week to come up with this recipe.
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 5s
timeout: 5s
retries: 10
#!/bin/bash
# healthy
# unhealthy
# starting
CONTAINER=warehouse_db_1
check() {
docker inspect --format "{{.State.Healthcheck.Status }}" $CONTAINER
}
while [[ "$STATUS" != "healthy" ]]
do
STATUS=$(check)
echo "$STATUS"
sleep 3
done |
Actually had to add a timeout to avoid an endless loop in GitHub Actions. It is still not configurable, so not a completely easy way.
|
For others that stumble on this, |
@daveisfera if you use initialization scripts then connection doesn't up until the init is over, like in https://github.com/pypa/warehouse/pull/9993/files |
I'm not following. What part of that link is the "initialization scripts"? |
@daveisfera this section is the initialization SQL script that is processed before the connection is up.
|
I don't believe that that will solve the problem. The issue that we saw is that occasionally |
Do tests run initialization scripts? If yes, then it should be a bug with |
If you run "pg_isready" inside the same container, it will likely connect
to the unix socket (which is enabled even during initialization). You have
to explicitly connect it to the TCP port instead (or use a separate
container that can't access the unix socket at all).
|
@tianon |
On first start, while creating the initial database and running Lines 326 to 331 in a83005b
The temporary server does not listen on external ports, but would be |
@yosifkit why temporary server won't use a different port for initialization? |
If you do |
I’ve added |
https://hub.docker.com/_/postgres contains at least two instructions that tell to wait for DB to initialize successfully. These are hard to automate, because there are no instructions how to wait for it programmatically.
It would be nice is the instructions could at least confirm some of the best way to do this in
docker-compose
https://stackoverflow.com/questions/35069027/docker-wait-for-postgresql-to-be-running
The text was updated successfully, but these errors were encountered: