Skip to content

Commit 207f6ed

Browse files
committed
Print the error message before attempting to reset the connection after a
backend crash.
1 parent 352cd1f commit 207f6ed

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/bin/psql/common.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.27 2000/11/27 02:20:36 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.28 2000/12/15 17:54:43 petere Exp $
77
*/
88
#include "postgres.h"
99
#include "common.h"
@@ -315,32 +315,6 @@ PSQLexec(const char *query)
315315
if (PQresultStatus(res) != PGRES_COPY_OUT)
316316
cancelConn = NULL;
317317

318-
if (PQstatus(pset.db) == CONNECTION_BAD)
319-
{
320-
if (!pset.cur_cmd_interactive)
321-
{
322-
psql_error("connection to server was lost\n");
323-
exit(EXIT_BADCONN);
324-
}
325-
fputs("The connection to the server was lost. Attempting reset: ", stderr);
326-
PQreset(pset.db);
327-
if (PQstatus(pset.db) == CONNECTION_BAD)
328-
{
329-
fputs("Failed.\n", stderr);
330-
PQfinish(pset.db);
331-
PQclear(res);
332-
pset.db = NULL;
333-
SetVariable(pset.vars, "DBNAME", NULL);
334-
SetVariable(pset.vars, "HOST", NULL);
335-
SetVariable(pset.vars, "PORT", NULL);
336-
SetVariable(pset.vars, "USER", NULL);
337-
SetVariable(pset.vars, "ENCODING", NULL);
338-
return NULL;
339-
}
340-
else
341-
fputs("Succeeded.\n", stderr);
342-
}
343-
344318
if (res && (PQresultStatus(res) == PGRES_COMMAND_OK ||
345319
PQresultStatus(res) == PGRES_TUPLES_OK ||
346320
PQresultStatus(res) == PGRES_COPY_IN ||
@@ -351,6 +325,31 @@ PSQLexec(const char *query)
351325
{
352326
psql_error("%s", PQerrorMessage(pset.db));
353327
PQclear(res);
328+
329+
if (PQstatus(pset.db) == CONNECTION_BAD)
330+
{
331+
if (!pset.cur_cmd_interactive)
332+
{
333+
psql_error("connection to server was lost\n");
334+
exit(EXIT_BADCONN);
335+
}
336+
fputs("The connection to the server was lost. Attempting reset: ", stderr);
337+
PQreset(pset.db);
338+
if (PQstatus(pset.db) == CONNECTION_BAD)
339+
{
340+
fputs("Failed.\n", stderr);
341+
PQfinish(pset.db);
342+
pset.db = NULL;
343+
SetVariable(pset.vars, "DBNAME", NULL);
344+
SetVariable(pset.vars, "HOST", NULL);
345+
SetVariable(pset.vars, "PORT", NULL);
346+
SetVariable(pset.vars, "USER", NULL);
347+
SetVariable(pset.vars, "ENCODING", NULL);
348+
}
349+
else
350+
fputs("Succeeded.\n", stderr);
351+
}
352+
354353
return NULL;
355354
}
356355
}

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