Re: history from concurrent psql sessions - Mailing list pgsql-pkg-debian

From Christoph Berg
Subject Re: history from concurrent psql sessions
Date
Msg-id 20140913171327.GB965@msg.df7cb.de
Whole thread Raw
List pgsql-pkg-debian
Hi,

[apparently your message didn't made it to the list, hence fullquoting]

Re: avdd 2014-09-13 <5414140A.2070306@avdd.co>
> Dear friendly postgresql packagers
>
> re this bug:
>
> https://bugs.launchpad.net/ubuntu/+source/postgresql-9.1/+bug/985959
>
> namely, with concurrent psql sessions, the later sessions will overwrite the
> history of earlier concurrent sessions.
>
> I finally bothered to dig into this.
>
> The function saveHistory() in src/bin/psql/input.c tells us:
>
> * On newer versions of libreadline, truncate the history file as
> * needed and then append what we've added. This avoids overwriting
> * history from other concurrent sessions (although there are still
> * race conditions when two sessions exit at about the same time). If
> * we don't have those functions, fall back to write_history().
>
> and
>
> /* ... and overwrite file. Tough luck for concurrent sessions. */
>
> Looks like a smoking gun!
>
> Debian builds are against libedit, so only the fallback code is compiled in
> saveHistory().
>
> But pg_wrapper sees if a real readline is installed and exports a LD_PRELOAD
> to point to it.  So even though readline is used, the applicable code branch
> has been compiled out.
>
> I can't think of any workaround short of compiling against real readline
> myself, or just not using concurrent sessions.
>
> a.

libedit has history_truncate_file, but not append_history, that's only
half of the support needed:

#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY)

There's plenty of linker tricks one could think of, like providing a
fake append_history() that calls either readline's append_history(),
or falls back to libedit's write_history(), but the proper approach
seems to fix libedit to provide a working append_history(). Then we
could still LD_PRELOAD libreadline, but the code wouldn't get #if'ed
away (and even with libedit, the support would be better).

I'll see if I can arrange that in Debian (and I guess it'll then
trickle over to Ubuntu some day as well).

Christoph
--
cb@df7cb.de | http://www.df7cb.de/

Attachment

pgsql-pkg-debian by date:

Previous
From: apt.postgresql.org repository
Date:
Subject: pgxnclient updated to version 1.2.1-3.pgdg+1
Next
From: apt.postgresql.org repository
Date:
Subject: skytools updated to version 2.1.13-4.pgdg+2