Re: BUG #14031: Failed to Write to History File

Lists: pgsql-bugs
From: cjthmp(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14031: Failed to Write to History File
Date: 2016-03-18 03:50:10
Message-ID: 20160318035010.5149.8101@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14031
Logged by: cj
Email address: cjthmp(at)gmail(dot)com
PostgreSQL version: 9.5.1
Operating system: Mac
Description:

I re-installed PostgreSQL 9.5 on my Mac, and now every time I run a query I
get a "Failed to write to history file". Error. What history file is it
talking about? How can I fix this?

I've seen this question before, but not an answer. Thanks.


From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: cjthmp(at)gmail(dot)com
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14031: Failed to Write to History File
Date: 2016-03-18 20:57:48
Message-ID: CAKFQuwYPydK1s3th1XwQGm97CSEk1o6AXgoTo8Q9UxVOrBKNMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Thu, Mar 17, 2016 at 8:50 PM, <cjthmp(at)gmail(dot)com> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 14031
> Logged by: cj
> Email address: cjthmp(at)gmail(dot)com
> PostgreSQL version: 9.5.1
> Operating system: Mac
> Description:
>
> I re-installed PostgreSQL 9.5 on my Mac, and now every time I run a query I
> get a "Failed to write to history file". Error. What history file is it
> talking about? How can I fix this?
>
> I've seen this question before, but not an answer. Thanks.
>

​Not much help but the history file comes either from "readline" or
"libedit" - those are the two potential O/S provided libraries that psql
uses to make using its command line interface much friendlier.

David J.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: cjthmp(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14031: Failed to Write to History File
Date: 2016-03-19 13:59:01
Message-ID: 3290.1458395941@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 503 토토 베이 페치 실패

cjthmp(at)gmail(dot)com writes:
> I re-installed PostgreSQL 9.5 on my Mac, and now every time I run a query I
> get a "Failed to write to history file". Error. What history file is it
> talking about? How can I fix this?

Um ... how old is that Mac?

I would assume that you are running into a side effect of this commit:

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Branch: master Release: REL9_5_BR [df9ebf1ee] 2015-03-14 13:43:00 -0400
Branch: REL9_4_STABLE Release: REL9_4_2 [f50b5c7d0] 2015-03-14 13:43:08 -0400
Branch: REL9_3_STABLE Release: REL9_3_7 [2cb76fa6f] 2015-03-14 13:43:13 -0400
Branch: REL9_2_STABLE Release: REL9_2_11 [309ff2ad0] 2015-03-14 13:43:17 -0400
Branch: REL9_1_STABLE Release: REL9_1_16 [043fe5c5a] 2015-03-14 13:43:21 -0400
Branch: REL9_0_STABLE Release: REL9_0_20 [396ef6fd8] 2015-03-14 13:43:26 -0400

Remove workaround for ancient incompatibility between readline and libedit.

GNU readline defines the return value of write_history() as "zero if OK,
else an errno code". libedit's version of that function used to have a
different definition (to wit, "-1 if error, else the number of lines
written to the file"). We tried to work around that by checking whether
errno had become nonzero, but this method has never been kosher according
to the published API of either library. It's reportedly completely broken
in recent Ubuntu releases: psql bleats about "No such file or directory"
when saving ~/.psql_history, even though the write worked fine.

However, libedit has been following the readline definition since somewhere
around 2006, so it seems all right to finally break compatibility with
ancient libedit releases and trust that the return value is what readline
specifies. (I'm not sure when the various Linux distributions incorporated
this fix, but I did find that OS X has been shipping fixed versions since
10.5/Leopard.)

If anyone is still using such an ancient libedit, they will find that psql
complains it can't write ~/.psql_history at exit, even when the file was
written correctly. This is no worse than the behavior we're fixing for
current releases.

Back-patch to all supported branches.

If you're actually running on a pre-Leopard Mac, my recommendation would
be to install GNU readline and link psql to that instead of the
system-provided libedit. The number of other libedit bugs this avoids
is large :-(

If it isn't pre-Leopard, my guess is still that you're somehow using an
ancient copy of libedit. You could investigate by running "otool -L
/path/to/psql" to see which libedit or libreadline version it's linked
to, and then see how old that is.

regards, tom lane