Skip to content

Commit 38f4328

Browse files
committed
Fix pg_isready to handle -d option properly.
Previously, -d option for pg_isready was broken. When the name of the database was specified by -d option, pg_isready failed with an error. When the conninfo specified by -d option contained the setting of the host name but not Numeric IP address (i.e., hostaddr), pg_isready displayed wrong connection message. -d option could not handle a valid URI prefix at all. This commit fixes these bugs of pg_isready. Backpatch to 9.3, where pg_isready was introduced. Per report from Josh Berkus and Robert Haas. Original patch by Fabrízio de Royes Mello, heavily modified by me.
1 parent 04eee1f commit 38f4328

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/bin/scripts/pg_isready.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ main(int argc, char **argv)
3131
const char *connect_timeout = DEFAULT_CONNECT_TIMEOUT;
3232

3333
const char *pghost_str = NULL;
34+
const char *pghostaddr_str = NULL;
3435
const char *pgport_str = NULL;
3536

3637
#define PARAMS_ARRAY_SIZE 7
@@ -130,7 +131,10 @@ main(int argc, char **argv)
130131
/*
131132
* Get the host and port so we can display them in our output
132133
*/
133-
if (pgdbname)
134+
if (pgdbname &&
135+
(strncmp(pgdbname, "postgresql://", 13) == 0 ||
136+
strncmp(pgdbname, "postgres://", 11) == 0 ||
137+
strchr(pgdbname, '=') != NULL))
134138
{
135139
opts = PQconninfoParse(pgdbname, &errmsg);
136140
if (opts == NULL)
@@ -149,8 +153,7 @@ main(int argc, char **argv)
149153

150154
for (opt = opts, def = defs; def->keyword; def++)
151155
{
152-
if (strcmp(def->keyword, "hostaddr") == 0 ||
153-
strcmp(def->keyword, "host") == 0)
156+
if (strcmp(def->keyword, "host") == 0)
154157
{
155158
if (opt && opt->val)
156159
pghost_str = opt->val;
@@ -161,6 +164,13 @@ main(int argc, char **argv)
161164
else
162165
pghost_str = DEFAULT_PGSOCKET_DIR;
163166
}
167+
else if (strcmp(def->keyword, "hostaddr") == 0)
168+
{
169+
if (opt && opt->val)
170+
pghostaddr_str = opt->val;
171+
else if (def->val)
172+
pghostaddr_str = def->val;
173+
}
164174
else if (strcmp(def->keyword, "port") == 0)
165175
{
166176
if (opt && opt->val)
@@ -179,7 +189,9 @@ main(int argc, char **argv)
179189

180190
if (!quiet)
181191
{
182-
printf("%s:%s - ", pghost_str, pgport_str);
192+
printf("%s:%s - ",
193+
pghostaddr_str != NULL ? pghostaddr_str : pghost_str,
194+
pgport_str);
183195

184196
switch (rv)
185197
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy