Subject: psql casts aspersions on server reliability

From: Robert Haas <[email-masked]>
Date: Wed, 28 Sep 2016 08:22:11 -0400

psql tends to do things like this:

rhaas=# select * from pg_stat_activity;
FATAL:  terminating connection due to administrator command
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

Basically everything psql has to say about this is a lie:

1. It says the server closed the connection unexpectedly, but it just
finished processing a FATAL message from the server.  So how
unexpected is it that the connection would thereafter be closed?

2.  It says the server probably terminated abnormally, but PostgreSQL
is rarely so unreliable as to just give up the ghost and die.  The
ErrorResponse it just processed has an errcode of
ERRCODE_ADMIN_SHUTDOWN, so probably what happened is somebody either
shut down the server or killed the session.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

-- 
Sent via pgsql-hackers mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

---

From: Tom Lane <[email-masked]>
Date: Wed, 28 Sep 2016 09:14:41 -0400

> Basically everything psql has to say about this is a lie:

I cannot get terribly excited about this.  What you seem to be proposing
is that psql try to intuit the reason for connection closure from the
last error message it got, but that seems likely to lead to worse lies
than printing a boilerplate message.

I could go along with just dropping the last sentence ("This probably...")
if the last error we got was FATAL level.  I don't find "unexpectedly"
to be problematic here: from the point of view of psql, and probably
of its user, the shutdown *was* unexpected.

			regards, tom lane

---

From: Robert Haas <[email-masked]>
Date: Wed, 28 Sep 2016 10:22:53 -0400

> of its user, the shutdown *was* unexpected.

I don't care very much whether we try to intuit the reason for
connection closure or not; it could be done, but I don't feel that it
has to be done.  My bigger point is that currently psql speculates
that the reason for *every* connection closure is abnormal server
termination, which is actually a very rare event.

It may have been common when that message was added.
1a17447be1186fdd36391c58a2a0209f613d89c4 changed the wording this
message in 2001, and the original message seems to date to
011ee13131f6fa2f6dbafd3827b70d051cb28f64 in 1996.  And my guess is at
that time the server probably did just roll over and die with some
regularity.  But today it usually doesn't.  It's neither helpful nor
good PR for libpq to guess that the most likely cause of a server
disconnection is server unreliability.

I have seen actual instances of customers getting upset by this
message even though the server had been shut down quite cleanly.  The
message got into a logfile and induced minor panic.  Fortunately, I
have not seen this happen lately.

---

From: David Steele <[email-masked]>
Date: Wed, 28 Sep 2016 11:13:36 -0400

> have not seen this happen lately.

+1 for making this error message less frightening.  I have also had to
explain it away on occasion.

-- 
-David
[email-masked]

---

From: Petr Jelinek <[email-masked]>
Date: Wed, 28 Sep 2016 20:23:24 +0200

> explain it away on occasion.

+1 I've seen this being misleading way too often.

-- 
  Petr Jelinek                  http://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services