aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-protocol3.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-11-27 01:30:34 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2010-11-27 01:30:34 -0500
commitdb96e1ccfcb8f3514eef931bea9435974ec7ad28 (patch)
treea036fbf566b7032289193f1e856fb5fa2a6564ba /src/interfaces/libpq/fe-protocol3.c
parentbe3b666eb810089fd9a1d42e3888be52ab9ddb63 (diff)
downloadpostgresql-db96e1ccfcb8f3514eef931bea9435974ec7ad28.tar.gz
postgresql-db96e1ccfcb8f3514eef931bea9435974ec7ad28.zip
Rewrite PQping to be more like what we agreed to last week.
Basically, we want to distinguish all cases where the connection was not made from those where it was. A convenient proxy for this is to see if we got a message with a SQLSTATE code back from the postmaster. This presumes that the postmaster will always send us a SQLSTATE in a failure message, which is true for 7.4 and later postmasters in every case except fork failure. (We could possibly complicate the postmaster code to do something about that, but it seems not worth the trouble, especially since pg_ctl's response for that case should be to keep waiting anyway.) If we did get a SQLSTATE from the postmaster, there are basically only two cases, as per last week's discussion: ERRCODE_CANNOT_CONNECT_NOW and everything else. Any other error code implies that the postmaster is in principle willing to accept connections, it just didn't like or couldn't handle this particular request. We want to make a special case for ERRCODE_CANNOT_CONNECT_NOW so that "pg_ctl start -w" knows it should keep waiting. In passing, pick names for the enum constants that are a tad less likely to present collision hazards in future.
Diffstat (limited to 'src/interfaces/libpq/fe-protocol3.c')
-rw-r--r--src/interfaces/libpq/fe-protocol3.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index b8e4bee31b1..cf9407de7ae 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -758,15 +758,19 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
/*
* Now build the "overall" error message for PQresultErrorMessage.
+ *
+ * Also, save the SQLSTATE in conn->last_sqlstate.
*/
resetPQExpBuffer(&workBuf);
val = PQresultErrorField(res, PG_DIAG_SEVERITY);
if (val)
appendPQExpBuffer(&workBuf, "%s: ", val);
- if (conn->verbosity == PQERRORS_VERBOSE)
+ val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
+ if (val)
{
- val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
- if (val)
+ if (strlen(val) < sizeof(conn->last_sqlstate))
+ strcpy(conn->last_sqlstate, val);
+ if (conn->verbosity == PQERRORS_VERBOSE)
appendPQExpBuffer(&workBuf, "%s: ", val);
}
val = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);