Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XSqtI-00069H-Uz for pgsql-pkg-debian@arkaria.postgresql.org; Sat, 13 Sep 2014 17:13:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XSqtI-0005sd-ER for pgsql-pkg-debian@arkaria.postgresql.org; Sat, 13 Sep 2014 17:13:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XSqtG-0005sO-IH for pgsql-pkg-debian@postgresql.org; Sat, 13 Sep 2014 17:13:38 +0000 Received: from feynman.df7cb.de ([2001:6f8:10ee::1]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XSqt8-00012h-76 for pgsql-pkg-debian@postgresql.org; Sat, 13 Sep 2014 17:13:36 +0000 Received: from msg.df7cb.de (aftr-37-24-157-72.unity-media.net [37.24.157.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by feynman.df7cb.de (Postfix) with ESMTPSA id D4983696DB; Sat, 13 Sep 2014 19:13:27 +0200 (CEST) Date: Sat, 13 Sep 2014 19:13:27 +0200 From: Christoph Berg To: avdd Cc: pgsql-pkg-debian@postgresql.org Subject: Re: history from concurrent psql sessions Message-ID: <20140913171327.GB965@msg.df7cb.de> Mail-Followup-To: Christoph Berg , avdd , pgsql-pkg-debian@postgresql.org References: <5414140A.2070306@avdd.co> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="BOKacYhQ+x31HxR3" Content-Disposition: inline In-Reply-To: <5414140A.2070306@avdd.co> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -4.4 (----) X-Mailing-List: pgsql-pkg-debian List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Precedence: bulk Sender: pgsql-pkg-debian-owner@postgresql.org --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 >=20 > re this bug: >=20 > https://bugs.launchpad.net/ubuntu/+source/postgresql-9.1/+bug/985959 >=20 > namely, with concurrent psql sessions, the later sessions will overwrite = the > history of earlier concurrent sessions. >=20 > I finally bothered to dig into this. >=20 > The function saveHistory() in src/bin/psql/input.c tells us: >=20 > * 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(). >=20 > and >=20 > /* ... and overwrite file. Tough luck for concurrent sessions. */ >=20 > Looks like a smoking gun! >=20 > Debian builds are against libedit, so only the fallback code is compiled = in > saveHistory(). >=20 > But pg_wrapper sees if a real readline is installed and exports a LD_PREL= OAD > to point to it. So even though readline is used, the applicable code bra= nch > has been compiled out. >=20 > I can't think of any workaround short of compiling against real readline > myself, or just not using concurrent sessions. >=20 > 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 --=20 cb@df7cb.de | http://www.df7cb.de/ --BOKacYhQ+x31HxR3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJUFHswAAoJEExaa6sS0qeuRewP/jwlcE3TPB1Ec//xqec/f4mI YnYGv5UZjVsVVaSGxMTY6bvvOrypsr/nmsOcl/GEE5yjHYAy2EUlfEeZXEtGp6nP 1/VxV2wi5zjLPT9hUDZUsI05cUXXm96qcpGkbTeAdSU1jIMur2qEeuuSYzUftlRY Sa+VR3AVqXvr2zAxKcmwT+bChYrt81HXnRH44iJdGzEJPbJd/z46SATVSwt7u9/r SBCfvYO3xItvLEr69TVyGg47sj9G8Z9LHq0pJKBNq0cZPRfF+xGyvdXqMmh6bwAS RjOuKcoRVOc7Jwtb1e8PtNp+VwpTC9bUTDZmoiI4CjbjXNx2J1uxC2iC1xzGN08f +D1I1dPpAgb65G/KFnvcRqYWSAx+YmHaadSjVZYPJ2HJqKfBpiHyrJ3Tb93xWCDN Yafza8otO+p4hEgTekvO2fkQ9Gawsb8l2+ihoMc6990OAfAqo18LzWjs72TWLyLQ a5+CSD10U5nGO49iOAPfDg/pWNUr4yqGKCt551jOL/0n/sjDE9fw041GagotFGUe BInu10yD5/XO1UAM+FELdZiWRwJTJAsadTssiK0PJmkgcNQPqlh33pha1lts062I zAT2DS+1DzkVgpx6wa0HnKPukZ7PKVVHlUApfrYYEXqthOVB3DPNoEnKxL/Dy+HO n9OCNuarjF8tgu6D6+Xx =jcqO -----END PGP SIGNATURE----- --BOKacYhQ+x31HxR3--