Thread: bogus psql "could not save history file[...]" message in 9.3.6

bogus psql "could not save history file[...]" message in 9.3.6

From
"David G. Johnston"
Date:
Installed 9.3.6 from apt.postgresql.org onto a reasonably clean Ubuntu
14.04 (trusty)

$ sudo apt-get install [...] # ok
$ ls -la /var/lib/postgresql # 9.3 is the only result; equivalent to (ls
-la ~)
$ sudo su - postgres # ok
$ psql # ok
> select 1; # ok
> \q # 'could not save history to file "/var/lib/postgresql/.psql_history":
No such file or directory' !!!
$ ls -la /var/lib/postgresql # 9.3 and .psql_history are both present
$ cat /var/lib/postgresql/.psql_history # select 1; <newline> \q <eof>
$ psql # ok
> select 2; # ok
> \q # ok this time; no message
$ cat [...] # confirmed everything present
$ rm /var/lib/postgresql/.psql_history # gone
$ psql
> select 3;
> \q # same error again !!!
$ [confirm select 3 is present in .psql_history]

Seems like a file existence check and warning is in the wrong
place...everything works correctly except there is a bogus warning.

Or change the message to simply be "creating new .psql_history file in
/var/lib/postgresql"

Obviously its odd that /var/lib is where the history file is being placed
but the package sets that as HOME for the newly created postgres user...I'm
doubting this problem is limited to just that situation though.

David J.

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Tom Lane
Date:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> Installed 9.3.6 from apt.postgresql.org onto a reasonably clean Ubuntu
> 14.04 (trusty)

> $ sudo apt-get install [...] # ok
> $ ls -la /var/lib/postgresql # 9.3 is the only result; equivalent to (ls
> -la ~)
> $ sudo su - postgres # ok
> $ psql # ok
>> select 1; # ok
>> \q # 'could not save history to file "/var/lib/postgresql/.psql_history":
> No such file or directory' !!!

Sigh ... let me guess ... libedit?  How old?  What was the last
combination that worked on this platform?

The only patch recently applied in this area is b0fd5c552, which I really
don't think would have any impact on exit-time saving behavior.  What
seems substantially more likely is that your command history library
changed.

            regards, tom lane

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
"David G. Johnston"
Date:
On Fri, Mar 13, 2015 at 5:36 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > Installed 9.3.6 from apt.postgresql.org onto a reasonably clean Ubuntu
> > 14.04 (trusty)
>
> > $ sudo apt-get install [...] # ok
> > $ ls -la /var/lib/postgresql # 9.3 is the only result; equivalent to (l=
s
> > -la ~)
> > $ sudo su - postgres # ok
> > $ psql # ok
> >> select 1; # ok
> >> \q # 'could not save history to file
> "/var/lib/postgresql/.psql_history":
> > No such file or directory' !!!
>
> Sigh ... let me guess ... libedit?  How old?  What was the last
> combination that worked on this platform?
>
> The only patch recently applied in this area is b0fd5c552, which I really
> don't think would have any impact on exit-time saving behavior.  What
> seems substantially more likely is that your command history library
> changed.
>
>                         regards, tom lane
>

=E2=80=8BI can research a bit: I'm using a 14.04 Vagrant box
(box-cutter/ubuntu1404-desktop )
with some pre-installed (notably Libre (Open?) Office) on the box
=E2=80=8Bbefore
I added tmux, git, and Sublime Text 3 myself
=E2=80=8Band then
install
=E2=80=8Bed=E2=80=8B
PostgreSQL.

=E2=80=8BCan you give me a command to run to check what it is you are sayin=
g.  My
Linux-fu is not that strong yet...=E2=80=8B

=E2=80=8BThere isn't any actual problem writing the history out, even the f=
irst
time, there is just the spurious warning.

This is my first time using Ubuntu 14.04 for any purpose.

I'm not inclined to spend too much time figuring out how the system came to
be whacked, if it is, but if you've got a few quick things I can check I'd
be glad to do so.

David J.=E2=80=8B

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Tom Lane
Date:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> ​Can you give me a command to run to check what it is you are saying.  My
> Linux-fu is not that strong yet...​

Running ldd on the psql executable would be a good first step.

            regards, tom lane

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
"David G. Johnston"
Date:
On Fri, Mar 13, 2015 at 6:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > =E2=80=8BCan you give me a command to run to check what it is you are s=
aying.  My
> > Linux-fu is not that strong yet...=E2=80=8B
>
> Running ldd on the psql executable would be a good first step.
>

=E2=80=8Blibedit.so.2 =3D> /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f=
8b3af22000)

Not seeing libreadline

A plain psql when using this package performs the call via a wrapper -
/usr/share/postgresql-common/pg_wrapper.

I did the ldd against /usr/lib/postgresql/9.3/bin/psql

David J.

=E2=80=8B

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Tom Lane
Date:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Mar 13, 2015 at 6:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Running ldd on the psql executable would be a good first step.

> ​libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f8b3af22000)

Righto.  So now, what version of libedit have you got?  (On Red Hat
"rpm -q libedit" would be the thing to do, but I have no idea about
Ubuntu's package manager.)

            regards, tom lane

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Jeff Frost
Date:
> On Mar 13, 2015, at 6:42 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>=20
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
>> On Fri, Mar 13, 2015 at 6:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> Running ldd on the psql executable would be a good first step.
>=20
>> =E2=80=8Blibedit.so.2 =3D> /usr/lib/x86_64-linux-gnu/libedit.so.2 =
(0x00007f8b3af22000)
>=20
> Righto.  So now, what version of libedit have you got?  (On Red Hat
> "rpm -q libedit" would be the thing to do, but I have no idea about
> Ubuntu's package manager.)
>=20
>             regards, tom lane

This is from an empty 14.04 vagrant where I installed postgresql-9.3 =
from the apt.postgresql.org <http://apt.postgresql.org/> repo:

agrant@vagrant-ubuntu-trusty-64:/etc/apt/sources.list.d$ dpkg -S =
/usr/lib/x86_64-linux-gnu/libedit.so.2
libedit2:amd64: /usr/lib/x86_64-linux-gnu/libedit.so.2

vagrant@vagrant-ubuntu-trusty-64:/etc/apt/sources.list.d$ dpkg --list =
libedit2
Desired=3DUnknown/Install/Remove/Purge/Hold
| =
Status=3DNot/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-=
pend
|/ Err?=3D(none)/Reinst-required (Status,Err: uppercase=3Dbad)
||/ Name                                     Version                   =
Architecture              Description
=
+++-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
ii  libedit2:amd64                           3.1-20130712-2            =
amd64                     BSD editline and history libraries

And it does the same thing:

vagrant@vagrant-ubuntu-trusty-64:/etc/apt/sources.list.d$ sudo su - =
postgres
postgres@vagrant-ubuntu-trusty-64:~$ psql
psql (9.3.6)
Type "help" for help.

postgres=3D# select 1;
 ?column?
----------
        1
(1 row)

postgres=3D# \q
could not save history to file "/var/lib/postgresql/.psql_history": No =
such file or directory

postgres@vagrant-ubuntu-trusty-64:~$ ls -l =
/var/lib/postgresql/.psql_history
-rw------- 1 postgres postgres 10 Mar 14 01:53 =
/var/lib/postgresql/.psql_history
postgres@vagrant-ubuntu-trusty-64:~$

postgres@vagrant-ubuntu-trusty-64:~$ cat .psql_history
select 1;

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
"David G. Johnston"
Date:
On Fri, Mar 13, 2015 at 6:42 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Fri, Mar 13, 2015 at 6:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Running ldd on the psql executable would be a good first step.
>
> > =E2=80=8Blibedit.so.2 =3D> /usr/lib/x86_64-linux-gnu/libedit.so.2
> (0x00007f8b3af22000)
>
> Righto.  So now, what version of libedit have you got?  (On Red Hat
> "rpm -q libedit" would be the thing to do, but I have no idea about
> Ubuntu's package manager.)
>

=E2=80=8Bapt-cache showpkg libedit2

# 3.1-20130712-2
(us.archive.ubuntu.com_ubunut_dists_trusty_main_binary-amd64_Packages)

"Reverse Depends=E2=80=8B"

=E2=80=8Bincludes:

postgresql-client.9.3,libedit2 2.11-20080614 (same thing for 8.4 to 9.4)

David J.

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Tom Lane
Date:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
>> \q # 'could not save history to file "/var/lib/postgresql/.psql_history":
> No such file or directory' !!!

BTW, I poked around in the libedit sources and noted that it will call
wctomb() during write_history(), assuming it's configured to support wide
characters.  Working hypothesis is that wctomb() is trying to read some
locale configuration file and not finding it, which it's probably okay
with, but our is-errno-set check is unhappy later.  This behavior might
well vary depending on what locale environment you have set.

strace'ing psql while it exits might be informative.

            regards, tom lane

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Jeff Frost
Date:
> On Mar 13, 2015, at 9:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>=20
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
>>> \q # 'could not save history to file =
"/var/lib/postgresql/.psql_history":
>> No such file or directory' !!!
>=20
> BTW, I poked around in the libedit sources and noted that it will call
> wctomb() during write_history(), assuming it's configured to support =
wide
> characters.  Working hypothesis is that wctomb() is trying to read =
some
> locale configuration file and not finding it, which it's probably okay
> with, but our is-errno-set check is unhappy later.  This behavior =
might
> well vary depending on what locale environment you have set.
>=20
> strace'ing psql while it exits might be informative.

Here you go:

Process 3951 attached
read(0, "\4", 1)                        =3D 1
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, =
{B38400 opost isig -icanon -echo ...}) =3D 0
ioctl(0, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400 =
opost isig icanon echo ...}) =3D 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, =
{B38400 opost isig icanon echo ...}) =3D 0
rt_sigaction(SIGINT, {0x7f5798b08730, [], SA_RESTORER|SA_RESTART, =
0x7f5797c3dff0}, {0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D=
 0
rt_sigaction(SIGTERM, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGHUP, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGALRM, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGTSTP, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGTTOU, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGTTIN, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0ab0, [], SA_RESTORER, 0x7f5797c3dff0}, 8) =3D 0
rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x7f5797c3dff0}, =
{0x7f57986b0090, [], SA_RESTORER|SA_RESTART, 0x7f5797c3dff0}, 8) =3D 0
write(1, "\\q\n", 3)                    =3D 3
sendto(3, "X\0\0\0\4", 5, MSG_NOSIGNAL, NULL, 0) =3D 5
close(3)                                =3D 0
rt_sigaction(SIGPIPE, {SIG_DFL, [], SA_RESTORER|SA_RESTART, =
0x7f5797c3dff0}, {SIG_DFL, [], 0}, 8) =3D 0
rename("/var/lib/postgresql/.psql_history", =
"/var/lib/postgresql/.psql_history-") =3D -1 ENOENT (No such file or =
directory)
open("/var/lib/postgresql/.psql_history", O_WRONLY|O_CREAT|O_TRUNC, =
0600) =3D 3
write(3, "select 1;\n", 10)             =3D 10
close(3)                                =3D 0
unlink("/var/lib/postgresql/.psql_history-") =3D -1 ENOENT (No such file =
or directory)
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) =3D =
-1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) =3D =
-1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 =
ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 =
ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 =
ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) =3D -1 ENOENT =
(No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", =
O_RDONLY) =3D -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", =
O_RDONLY) =3D -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) =3D=
 -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", =
O_RDONLY) =3D -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) =
=3D -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) =3D =
-1 ENOENT (No such file or directory)
write(2, "could not save history to file \""..., 94) =3D 94
exit_group(0)                           =3D ?
+++ exited with 0 +++=

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Tom Lane
Date:
Jeff Frost <jeff@pgexperts.com> writes:
>> On Mar 13, 2015, at 9:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> strace'ing psql while it exits might be informative.

> Here you go:

> ...
> rename("/var/lib/postgresql/.psql_history", "/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or
directory)
> open("/var/lib/postgresql/.psql_history", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 3
> write(3, "select 1;\n", 10)             = 10
> close(3)                                = 0
> unlink("/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or directory)

... WTF?  That rename() and that unlink() are certainly not coming from
Postgres, and I do not see anything like that in the libedit sources
either.  (I'm looking at the libedit-20141030-3.1 version that Fedora
is currently shipping.)  That must be coming from some Ubuntu-specific
patch?

> open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)

I'm guessing here, but I suspect these calls are coming from strerror()
looking for a translated version of "No such file or directory" --- ie,
at this point the damage is already done and we are trying to report
that we think we've failed.

Short answer seems to be that Ubuntu stuck in a patch that thinks nothing
of clobbering errno during a write_history() call.

            regards, tom lane

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Alvaro Herrera
Date:
Tom Lane wrote:
> Jeff Frost <jeff@pgexperts.com> writes:
> >> On Mar 13, 2015, at 9:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> strace'ing psql while it exits might be informative.
>
> > Here you go:
>
> > ...
> > rename("/var/lib/postgresql/.psql_history", "/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or
directory)
> > open("/var/lib/postgresql/.psql_history", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 3
> > write(3, "select 1;\n", 10)             = 10
> > close(3)                                = 0
> > unlink("/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or directory)
>
> ... WTF?  That rename() and that unlink() are certainly not coming from
> Postgres, and I do not see anything like that in the libedit sources
> either.  (I'm looking at the libedit-20141030-3.1 version that Fedora
> is currently shipping.)  That must be coming from some Ubuntu-specific
> patch?

You can use
  apt-get source libedit2
to obtain a copy of the tarball plus all the patches that were applied
to build the package.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Re: bogus psql "could not save history file[...]" message in 9.3.6

From
Mark Kirkwood
Date:
On 14/03/15 15:46, Alvaro Herrera wrote:
> Tom Lane wrote:
>> Jeff Frost <jeff@pgexperts.com> writes:
>>>> On Mar 13, 2015, at 9:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> strace'ing psql while it exits might be informative.
>>
>>> Here you go:
>>
>>> ...
>>> rename("/var/lib/postgresql/.psql_history", "/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or
directory)
>>> open("/var/lib/postgresql/.psql_history", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 3
>>> write(3, "select 1;\n", 10)             = 10
>>> close(3)                                = 0
>>> unlink("/var/lib/postgresql/.psql_history-") = -1 ENOENT (No such file or directory)
>>
>> ... WTF?  That rename() and that unlink() are certainly not coming from
>> Postgres, and I do not see anything like that in the libedit sources
>> either.  (I'm looking at the libedit-20141030-3.1 version that Fedora
>> is currently shipping.)  That must be coming from some Ubuntu-specific
>> patch?
>
> You can use
>    apt-get source libedit2
> to obtain a copy of the tarball plus all the patches that were applied
> to build the package.
>

Also might be worth checking the ownership of postgres home directory
(/var/lib/postgresql) - I'd hazard a guess that it is owned by root and
postgres cannot write the history file.

Cheers

Mark