diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-01-11 14:12:31 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-01-11 14:12:31 -0500 |
commit | c1d589571c497a952d7fbe40d9828655859d746f (patch) | |
tree | 4cb59beae2e500fba40bf1115fca2a3864cd034d | |
parent | 52a10224e3cc1d706ba9800695f97cb163b747d5 (diff) | |
download | postgresql-c1d589571c497a952d7fbe40d9828655859d746f.tar.gz postgresql-c1d589571c497a952d7fbe40d9828655859d746f.zip |
Try next host after a "cannot connect now" failure.
If a server returns ERRCODE_CANNOT_CONNECT_NOW, try the next host,
if multiple host names have been provided. This allows dealing
gracefully with standby servers that might not be in hot standby mode
yet.
In the wake of the preceding commit, it might be plausible to retry
many more error cases than we do now, but I (tgl) am hesitant to
move too aggressively on that --- it's not clear it'd be desirable
for cases such as bad-password, for example. But this case seems
safe enough.
Hubert Zhang, reviewed by Takayuki Tsunakawa
Discussion: https://postgr.es/m/BN6PR05MB3492948E4FD76C156E747E8BC9160@BN6PR05MB3492.namprd05.prod.outlook.com
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index a4a8b3ad7a5..2b78ed8ec3e 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -3315,6 +3315,20 @@ keep_going: /* We will come back to here until there is /* OK, we read the message; mark data consumed */ conn->inStart = conn->inCursor; + /* + * If error is "cannot connect now", try the next host if + * any (but we don't want to consider additional addresses + * for this host, nor is there much point in changing SSL + * or GSS mode). This is helpful when dealing with + * standby servers that might not be in hot-standby state. + */ + if (strcmp(conn->last_sqlstate, + ERRCODE_CANNOT_CONNECT_NOW) == 0) + { + conn->try_next_host = true; + goto keep_going; + } + /* Check to see if we should mention pgpassfile */ pgpassfileWarning(conn); |