You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
I tried this on windows and linux and with and without the chmod line. The crucial part in the psql command is the -h localhost option. All other options can be removed and the error still occurs, but if the -h is removed everything works fine.
Does a workaround exist for this?
Reacted by usmanovbf, Dmitry Erokhin, Yukio Mizuta and Gleb Haranin
A recent change to the docker_entrypoint.sh script restricts postgres to only accept connections over a unix domain socket during internal initialization: #440
I would also appreciate a suggested workaround and would suggest the documentation be updated to clearly state the limitations of /docker-entrypoint-initdb.d/ scripts executing during internal init.
Reacted by Ivan, Joseph Ashwin Kottapurath, ELORCHI, Public Daniel and Alexander Farber
Edit: I see that the crucial problem here is that you can't modify this third party script. Perhaps you could send a PR to have it fixed? 🤔
For what it's worth, I ran into a similar problem where I wasn't able to connect to the postgres instance whilst using a connection string that set the host part to localhost.
Based on the docs I dropped the explicit host part:
a Unix-domain socket connection is chosen if the host part is either empty or starts with a slash
Activity
ionicom commentedon Aug 6, 2018
A recent change to the
docker_entrypoint.shscript restricts postgres to only accept connections over a unix domain socket during internal initialization: #440I too ran into this limitation when trying to run db migrations (via flyway) during this init context: https://stackoverflow.com/questions/51699847/flyway-unable-to-connect-to-postgres-container-within-docker-entrypoint-initdb-d
I would also appreciate a suggested workaround and would suggest the documentation be updated to clearly state the limitations of
/docker-entrypoint-initdb.d/scripts executing during internal init.tianon commentedon Aug 6, 2018
This was also discussed a little over in #441.
I think the best workaround (short of using the unix socket instead) is suggested in #440 (comment):
simonseyock commentedon Aug 15, 2018
Thanks for mentioning that. If desired I can create a PR to add this workaround to the documentation.
tianon commentedon Aug 20, 2018
I'm a bit wary of actively documenting the workaround since I think that would provide users with a false sense of the level to which it's supported.
For example, if we could find a way to appropriately provide the arguments to the image (https://github.com/docker-library/docs/tree/57a71eed9a741dd9a64b9a439d2664b896bff87d/postgres#database-configuration) on to
pg_ctlwhen we start this temporary daemon, that would make the workaround have a subtle bug (removing those arguments during restart, essentially).AlanFoster commentedon Aug 29, 2018
Edit: I see that the crucial problem here is that you can't modify this third party script. Perhaps you could send a PR to have it fixed? 🤔
For what it's worth, I ran into a similar problem where I wasn't able to connect to the postgres instance whilst using a connection string that set the host part to localhost.
Based on the docs I dropped the explicit host part:
Therefore:
The
psqlCLI supports this format, so this should work for you:Or using your existing format, just don't specify the host part and it should work:
tianon commentedon Sep 4, 2018
Thanks for the detailed examples, @AlanFoster 👍
I've opened docker-library/docs#1298 to add a blurb to the documentation about this.
afarber commentedon Dec 2, 2024
The following workaround without restarting postgres also works for me in a postgres:17-alpine3.20 based Dockerfile:
RUN sed -i "s/listen_addresses=''/listen_addresses='localhost'/" /usr/local/bin/docker-entrypoint.sh