Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit011ee13

Browse files
committed
|
|We're all too familiar with psql's "no response from backend" message.|Users can't tell what this means, and psql continues prompting for|commands after it even though the backend is dead and no commands can|succeed. It eventually dies on a signal when the dead socket fills|up. I extended the message to offer a better explanation and made|psql exit when it finds the backend is dead.||I also added a short message and newline when the user does a ctl-D so|it doesn't mess up the terminal display.||Submitted by: Bryan Henderson <bryanh@giraffe.netgate.net>
1 parent6b9ecd8 commit011ee13

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

‎src/bin/psql/psql.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.17 1996/08/10 05:02:53 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.18 1996/08/14 04:56:48 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -988,6 +988,10 @@ MainLoop(PsqlSettings *settings, FILE *source)
988988
boolquerySent=0;
989989
boolinteractive;
990990
READ_ROUTINEGetNextLine;
991+
boolconnected=1;
992+
/* We are connected to the backend (last time we looked) */
993+
booleof=0;
994+
/* We've reached the end of our command input. */
991995

992996
interactive= ((source==stdin)&& !settings->notty);
993997
#definePROMPT "=> "
@@ -1012,9 +1016,13 @@ MainLoop(PsqlSettings *settings, FILE *source)
10121016
query[0]='\0';
10131017

10141018
/* main loop for getting queries and executing them */
1015-
while ((line=GetNextLine(settings->prompt,source))!=NULL)
1016-
{
1017-
exitStatus=0;
1019+
while (connected&& !eof) {
1020+
line=GetNextLine(settings->prompt,source);
1021+
if (line==NULL) {/* No more input. Time to quit */
1022+
printf("EOF\n");/* Goes on prompt line */
1023+
eof=1;
1024+
}else {
1025+
exitStatus=0;
10181026
line=rightTrim(line);/* remove whitespaces on the right, incl. \n's */
10191027

10201028
if (line[0]=='\0') {
@@ -1099,11 +1107,16 @@ MainLoop(PsqlSettings *settings, FILE *source)
10991107

11001108
exitStatus=SendQuery(settings,query);
11011109
querySent=1;
1110+
if (PQstatus(settings->db)==CONNECTION_BAD) {
1111+
connected=0;
1112+
fprintf(stderr,"We have lost the connection to the backend, so "
1113+
"further processing is impossible. Terminating.\n");
1114+
}
11021115
}
1103-
1104-
free(line);/* free storage malloc'd by GetNextLine */
1105-
}/* while */
1106-
returnexitStatus;
1116+
free(line);/* free storage malloc'd by GetNextLine */
1117+
}
1118+
}/* while */
1119+
returnexitStatus;
11071120
}
11081121

11091122
int

‎src/interfaces/libpq/fe-exec.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.15 1996/08/13 01:34:27 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.16 1996/08/14 04:56:55 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -387,17 +387,26 @@ PQexec(PGconn* conn, const char* query)
387387

388388
/* check to see if the query string is too long */
389389
if (strlen(query)>MAX_MESSAGE_LEN) {
390-
sprintf(conn->errorMessage,"PQexec() -- query is too long. Maximum length is %d\n",MAX_MESSAGE_LEN-2 );
390+
sprintf(conn->errorMessage,"PQexec() -- query is too long. "
391+
"Maximum length is %d\n",MAX_MESSAGE_LEN-2 );
391392
returnNULL;
392393
}
393394

395+
/* Don't try to send if we know there's no live connection. */
396+
if (conn->status!=CONNECTION_OK) {
397+
sprintf(conn->errorMessage,"PQexec() -- There is no connection "
398+
"to the backend.\n");
399+
returnNULL;
400+
}
401+
394402
/* the frontend-backend protocol uses 'Q' to designate queries */
395403
sprintf(buffer,"Q%s",query);
396404

397405
/* send the query to the backend; */
398406
if (pqPuts(buffer,pfout,pfdebug)==1) {
399407
(void)sprintf(conn->errorMessage,
400-
"PQexec() -- while sending query: %s\n-- fprintf to Pfout failed: errno=%d\n%s\n",
408+
"PQexec() -- while sending query: %s\n"
409+
"-- fprintf to Pfout failed: errno=%d\n%s\n",
401410
query,errno,strerror(errno));
402411
returnNULL;
403412
}
@@ -414,7 +423,12 @@ PQexec(PGconn* conn, const char* query)
414423
if (id==EOF) {
415424
/* hmm, no response from the backend-end, that's bad */
416425
(void)sprintf(conn->errorMessage,
417-
"PQexec() -- No response from backend\n");
426+
"PQexec() -- Request was sent to backend, but backend "
427+
"closed the channel before "
428+
"responding. This probably means the backend "
429+
"terminated abnormally before or while processing "
430+
"the request.\n");
431+
conn->status=CONNECTION_BAD;/* No more connection to backend */
418432
return (PGresult*)NULL;
419433
}
420434

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp