diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index dacdfef..23d5a3c 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -646,9 +646,11 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
 							return PQPING_NO_ATTEMPT;
 						}
 
-						/* If postmaster is listening on "*", use localhost */
-						if (strcmp(host_str, "*") == 0)
-							strcpy(host_str, "localhost");
+						/* If postmaster is listening on "*", "0.0.0.0" or "::", use 127.0.0.1 */
+						if (strcmp(host_str, "*") == 0 ||
+							strcmp(host_str, "0.0.0.0") == 0 ||
+							strcmp(host_str, "::") == 0)
+							strcpy(host_str, "127.0.0.1");
 
 						/*
 						 * We need to set connect_timeout otherwise on Windows
