Re: history from concurrent psql sessions

From: Christoph Berg <cb(at)df7cb(dot)de>
To: avdd <i(at)avdd(dot)co>
Cc: pgsql-pkg-debian(at)postgresql(dot)org
Subject: Re: history from concurrent psql sessions
Date: 2014-09-13 17:13:27
Message-ID: 20140913171327.GB965@msg.df7cb.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-pkg-debian

Hi,

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

Re: avdd 2014-09-13 <5414140A(dot)2070306(at)avdd(dot)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(at)df7cb(dot)de | http://www.df7cb.de/

Browse pgsql-pkg-debian by date

  From Date Subject
Next Message apt.postgresql.org repository 2014-09-22 15:43:18 skytools updated to version 2.1.13-4.pgdg+2
Previous Message apt.postgresql.org repository 2014-09-07 20:43:07 pgxnclient updated to version 1.2.1-3.pgdg+1