pg.ddx.io  pgsql-pkg-debian@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Berg <cb@df7cb.de>
To: avdd <i@avdd.co>
Cc: pgsql-pkg-debian@postgresql.org
Subject: Re: history from concurrent psql sessions
Date: Sat, 13 Sep 2014 19:13:27 +0200
Message-ID: <20140913171327.GB965@msg.df7cb.de> (raw)
In-Reply-To: <5414140A.2070306@avdd.co>
References: <5414140A.2070306@avdd.co>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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/

Attachments:

  signature.asc (application/pgp-signature, 818B) download

Message-ID: <20140913171327.GB965@msg.df7cb.de>
Permalink:  ../20140913171327.GB965@msg.df7cb.de/
Also on:    postgresql.org/message-id/20140913171327.GB965@msg.df7cb.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-pkg-debian@postgresql.org
  Cc: cb@df7cb.de, i@avdd.co
  Subject: Re: history from concurrent psql sessions
  In-Reply-To: <20140913171327.GB965@msg.df7cb.de>
  References: <5414140A.2070306@avdd.co> <20140913171327.GB965@msg.df7cb.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox